示例#1
0
 public function run()
 {
     $currentLang = Yii::$app->composition['langShortCode'];
     // Get current link
     $current = Yii::$app->menu->current;
     $rule = Yii::$app->menu->currentUrlRule;
     $items = [];
     // Loop through all languages
     foreach (Lang::find()->asArray()->all() as $lang) {
         // Find item of current link with the lang
         $item = Yii::$app->menu->find()->where(['nav_id' => $current->navId])->lang($lang['short_code'])->with('hidden')->one();
         if ($item) {
             $link = $item->link;
             if ($item->type == 2 && !empty($rule)) {
                 $routeParams = [$rule['route']];
                 foreach ($rule['params'] as $key => $value) {
                     $routeParams[$key] = $value;
                 }
                 $compositionObject = Yii::createObject(Composition::className());
                 $compositionObject['langShortCode'] = $lang['short_code'];
                 $link = Yii::$app->urlManager->createMenuItemUrl($routeParams, $item->id, $compositionObject);
             }
             $items[] = ['href' => $link, 'isCurrent' => $currentLang == $lang['short_code'], 'language' => $lang];
         } else {
             $items[] = ['href' => Yii::$app->urlManager->prependBaseUrl($lang['short_code']), 'isCurrent' => $currentLang == $lang['short_code'], 'language' => $lang];
         }
     }
     return $this->render('index', ['items' => $items, 'currentLanguage' => Lang::find()->where(['short_code' => $currentLang])->asArray()->one()]);
 }
示例#2
0
 public function run()
 {
     $langData = Lang::find()->asArray()->all();
     $navId = Yii::$app->links->findOneByArguments(['url' => Yii::$app->links->activeUrl, 'lang' => Yii::$app->composition->getKey('langShortCode')])['id'];
     $html = '<ul>';
     foreach ($langData as $lang) {
         $html .= '<li style="display:inline;margin-right:5px"><a href="' . $lang['short_code'] . '/' . Yii::$app->links->findOneByArguments(['id' => $navId, 'lang_id' => $lang['id']])['url'] . '">' . $lang['short_code'] . '</a></li>';
     }
     $html .= '</ul>';
     return $html;
 }
示例#3
0
文件: WLang.php 项目: egorlost/mysite
 public function run()
 {
     return $this->render('view', ['current' => Lang::getCurrent(), 'langs' => Lang::find()->where('id != :current_id', [':current_id' => Lang::getCurrent()->id])->all()]);
 }
示例#4
0
 public function actionDataLanguages()
 {
     return Lang::find()->asArray()->all();
 }
示例#5
0
 /**
  * @todo should be static model methods inside Lang Model
  */
 private function getLangIdByShortCode($shortCode)
 {
     return \admin\models\Lang::find()->where(['short_code' => $shortCode])->one()->id;
 }
示例#6
0
 /**
  * @todo do not return the specofic type content, but return an array contain more infos also about is multi linguage and foreach in view file! 
  * @param unknown_type $element
  * @param string       $configContext list,create,update
  */
 public function createElements($element, $configContext)
 {
     if ($element['i18n'] && $configContext !== self::TYPE_LIST) {
         $return = [];
         foreach (\admin\models\Lang::find()->all() as $l => $v) {
             $ngModel = $this->i18nNgModelString($configContext, $element['name'], $v->short_code);
             $id = 'id-' . md5($ngModel . $v->short_code);
             // anzahl cols durch anzahl sprachen
             $return[] = ['id' => $id, 'name' => $element['name'], 'label' => $element['alias'] . ' ' . $v->name, 'ngModel' => $ngModel, 'html' => $this->renderElementPlugins($configContext, $element['plugins'], $id, $element['name'], $ngModel, $element['alias'] . ' ' . $v->name, $element['gridCols'])];
         }
         return $return;
     }
     if ($element['i18n'] && $configContext == self::TYPE_LIST) {
         $element['name'] = $element['name'] . '.de';
         // @todo get default language!
     }
     $ngModel = $this->ngModelString($configContext, $element['name']);
     $id = 'id-' . md5($ngModel);
     return [['id' => $id, 'name' => $element['name'], 'ngModel' => $ngModel, 'label' => $element['alias'], 'html' => $this->renderElementPlugins($configContext, $element['plugins'], $id, $element['name'], $ngModel, $element['alias'], $element['gridCols'])]];
 }