Пример #1
0
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     if (isset($_POST['Articles'])) {
         $model->attributes = $_POST['Articles'];
         if ($model->save()) {
             /*
             * Save attributes at once
             * Also can save one by one. Example: TsTranslation::save($model, 'fullText');
             * Third parameter of TsTranslation::save() is language 
             *      - as default uses TsTranslation::getDtLanguage() returned value:
             *      - $this->widget('tstranslation.widgets.TsLanguageWidget', array(
                        'dynamicTranslate' => true,
                    ));
             */
             TsTranslation::save($model, array('title', 'introText', 'fullText'));
         }
     }
     /**
     * Get attributes translations at once
     * Also can get translation one by one. Example: TsTranslation::dt($model, 'fullText');
     * Third parameter of TsTranslation::dt() is language 
     *      - as default uses TsTranslation::getDtLanguage() returned value:
     *      - $this->widget('tstranslation.widgets.TsLanguageWidget', array(
                'dynamicTranslate' => true,
            ));
     */
     $model->attributes = TsTranslation::dt($model, array('title', 'introText', 'fullText'));
     $this->render('update', array('model' => $model));
 }
Пример #2
0
 protected function beforeAction($action)
 {
     if (!TsTranslation::model()->isAccessEnabled()) {
         if (Yii::app()->request->isAjaxRequest) {
             echo '{"ok":0, "message":"You have no permission to do this action!"}';
             Yii::app()->end();
         } else {
             throw new CHttpException(403, 'You have no permission to do this action!');
         }
     }
     return parent::beforeAction($action);
 }
Пример #3
0
 public function run()
 {
     if ($this->dynamicTranslate) {
         if (!TsTranslation::model()->isAccessEnabled()) {
             throw new CHttpException(403, 'You have no permission to use dynamic content save method!');
         }
         $languageArray = TsTranslationComponent::getAvailableLanguages(false);
         if (!$this->showIsOne && count($languageArray) <= 1) {
             return;
         }
         $assetsUrl = $this->registerClientScript();
         $templateArray = explode('{items}', $this->template);
         $params = $_GET;
         $items = '';
         $currentLang = '';
         $dtLang = TsTranslation::model()->getDtLanguage();
         foreach ($languageArray as $lang) {
             if ($lang->code2 == $dtLang) {
                 $currentLang = '<span class="ts-current-dt-lang btn" data-toggle="' . $this->type . '" href="#">' . strtr($this->itemTemplate, array('{flag}' => '<img src="' . $assetsUrl . '/images/flags/' . $lang->code2 . '.gif">', '{name}' => $lang->name, '{nativeName}' => $lang->nativeName, '{code}' => $lang->code2)) . '</span>';
             } else {
                 $item = strtr($this->itemTemplate, array('{flag}' => '<img src="' . $assetsUrl . '/images/flags/' . $lang->code2 . '.gif">', '{name}' => $lang->name, '{nativeName}' => $lang->nativeName, '{code}' => $lang->code2));
                 $params['_dtLang'] = $lang->code2;
                 $items .= '<li><a data-language="' . $lang->code2 . '" href="' . Yii::app()->createUrl(Yii::app()->controller->route, $params) . '">' . $item . '</a></li>';
             }
         }
         echo $templateArray[0] . '<div id="' . $this->_id . '" class="' . $this->type . ' ts-dt-language-widget">' . $currentLang . '<ul class="' . $this->type . '-menu ts-lang-changer-list">' . $items . '</ul></div>' . $templateArray[1];
     } else {
         $languageArray = TsTranslationComponent::getActiveLanguages(false);
         if (!$this->showIsOne && count($languageArray) <= 1) {
             return;
         }
         $assetsUrl = $this->registerClientScript();
         $urlManager = Yii::app()->getComponent('urlManager');
         $templateArray = explode('{items}', $this->template);
         $params = $_GET;
         $items = '';
         $currentLang = '<span class="ts-current-dt-lang btn" data-toggle="' . $this->type . '" href="#"><img src="' . $assetsUrl . '/images/flags/' . Yii::app()->language . '.gif"> ' . Yii::app()->language . ' (This language not active, please select other language)</span>';
         foreach ($languageArray as $lang) {
             $item = strtr($this->itemTemplate, array('{flag}' => '<img src="' . $assetsUrl . '/images/flags/' . $lang->code2 . '.gif">', '{name}' => $lang->name, '{nativeName}' => $lang->nativeName, '{code}' => $lang->code2));
             if ($lang->code2 == Yii::app()->language) {
                 $currentLang = '<span class="ts-current-lang btn" data-toggle="' . $this->type . '" href="#">' . strtr($this->itemTemplate, array('{flag}' => '<img src="' . $assetsUrl . '/images/flags/' . $lang->code2 . '.gif">', '{name}' => $lang->name, '{nativeName}' => $lang->nativeName, '{code}' => $lang->code2)) . '</span>';
                 $items .= '<li><a data-language="' . $lang->code2 . '" href="#" class="ts-current-lang-link" onclick="javascript:return false;">' . $item . '</a></li>';
             } else {
                 $params['_lang'] = $lang->code2;
                 $items .= '<li><a data-language="' . $lang->code2 . '" href="' . Yii::app()->createUrl(Yii::app()->controller->route, $params) . '">' . $item . '</a></li>';
             }
         }
         if ($this->type === 'inline') {
             $currentLang = '';
         }
         if ($urlManager->showLangInUrl) {
             echo $templateArray[0] . '<div id="' . $this->_id . '" class="' . $this->type . ' ts-language-widget">' . $currentLang . '<ul class="' . $this->type . '-menu ts-lang-changer-list">' . $items . '</ul></div>' . $templateArray[1];
         } else {
             echo $templateArray[0] . '<div id="' . $this->_id . '" class="' . $this->type . ' ts-language-widget"><form id="tsLangChangerForm" method="POST"><input type="hidden" name="_newLang" id="tsNewLang" value="">' . $currentLang . '<ul class="' . $this->type . '-menu ts-lang-changer-list">' . $items . '</ul></form></div>' . $templateArray[1];
         }
     }
 }
Пример #4
0
 public static function getTsTranslation()
 {
     if (self::$_instance === null) {
         if (Yii::app()->hasComponent('tstranslation')) {
             self::$_instance = Yii::app()->getComponent('tstranslation');
         }
     }
     return self::$_instance;
 }
 public function run()
 {
     if (!TsTranslation::model()->isAccessEnabled()) {
         echo 'Error 403. You have no permission to use this widget!';
     } else {
         $this->registerClientScript();
         $languageModel = new ExtLanguages();
         $languageModel->unsetAttributes();
         $allLanguages = AllLanguages::model()->findAll();
         $allLanguagesList = CHtml::listData($allLanguages, 'id', 'name');
         $sourceTableName = SourceMessages::model()->tableName();
         $sql = 'SELECT `category` FROM ' . $sourceTableName . ' GROUP BY `category`';
         $categoryArray = Yii::app()->db->createCommand($sql)->queryColumn();
         $this->render('_translation_list', array('id' => $this->_id, 'model' => $languageModel, 'type' => $this->type, 'allLanguagesList' => $allLanguagesList, 'listOptions' => $this->listOptions, 'htmlOptions' => $this->htmlOptions, 'categoryArray' => $categoryArray, 'showDynamicContent' => $this->showDynamicContent));
     }
 }