I have done all described in the cookbook/26 but dropdown language list is not work.
1.components/MyController.php
<?php
class MyController extends CController
{
function init()
{
parent::init();
$app = Yii::app();
if (isset($_POST['_lang']))
{
$app->language = $_POST['_lang'];
$app->session['_lang'] = $app->language;
}
else if (isset($app->session['_lang']))
{
$app->language = $app->session['_lang'];
}
}
}
?>
2.components/LangBox.php
<?php
class LangBox extends CWidget
{
public function run()
{
$currentLang = Yii::app()->language;
$this->render('langBox', array('currentLang' => $currentLang));
}
}
3.components/views/langBox.php
<?php echo CHtml::form() ?>
<div id="langdrop">
<?php echo CHtml::dropDownList('_lang', $currentLang, array(
'en' => 'English', 'ru' => 'Русский'), array('submit' => '')) ?>
</div>
</form>
4.config/main.php
‘sourceLanguage’ => ‘en’,
‘language’ => ‘ru’,
- messages/ru/main.php
<?php
return array('Home' => 'Главная',);
I can change language when I set in the config/main.php ‘language’ => ‘en’,
, but dropdown selector is not work. Where is my mistake?
Can anybody help me, please.