public function getLangUrl() { if ($this->_lang_url === null) { $this->_lang_url = $this->getUrl(); $url_list = explode('/', $this->_lang_url); $lang_url = isset($url_list[1]) ? $url_list[1] : null; Language::setCurrent($lang_url); if ($lang_url !== null && $lang_url === Language::getCurrent()->url && strpos($this->_lang_url, Language::getCurrent()->url) === 1) { $this->_lang_url = substr($this->_lang_url, strlen(Language::getCurrent()->url) + 1); } } return $this->_lang_url; }
static function getLangByUrl($url = null) { if ($url === null) { return null; } else { $language = Language::find()->where('url = :url', [':url' => $url])->one(); if ($language === null) { return null; } else { return $language; } } }
public function createUrl($params) { if (isset($params['lang_id'])) { $lang = Language::findOne($params['lang_id']); if ($lang === null) { $lang = Language::getDefaultLang(); } unset($params['lang_id']); } else { $lang = Language::getCurrent(); } $url = parent::createUrl($params); if ($url == '/') { return '/' . $lang->url; } else { return '/' . $lang->url . $url; } }
public function run() { return $this->render('switcher', ['current' => \cyberz\language\models\Language::getCurrent(), 'langs' => \cyberz\language\models\Language::find()->where('id != :current_id', [':current_id' => \cyberz\language\models\Language::getCurrent()->id])->all()]); }