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]; } } }
private function _getExistedLanguage($langCode, $onlyActive = true) { if ($onlyActive === true) { $langList = TsTranslationComponent::getActiveLanguages('asDefault'); } else { $langList = TsTranslationComponent::getAvailableLanguages('asDefault'); } if (isset($langList[$langCode])) { return $langCode; } else { return array_search('1', $langList); } }