This extension allows you to pass the application language via an url and then use it for all further generated urls (within the application itself). It can use the user preffered language as a default initial language.
protected/extensions/urlManager/See the following code example:
'components'=>array( .... 'urlManager'=>array( 'class'=>'application.extensions.urlManager.LangUrlManager', 'languages'=>array('ru','uk'), 'langParam'=>'language', ), ... )
Your can share the change language link follow this example:
echo CHtml::link('<span class="ru">по-русски</span>',array(Yii::app()->defaultController.'/',Yii::app()->urlManager->langParam=>'ru'),array( 'class'=>((Yii::app()->language=='ru') ? 'action':''), )); <?php echo CHtml::link('<span class="ua">украiнською</span>',array(Yii::app()->defaultController.'/',Yii::app()->urlManager->langParam=>'uk'),array( 'class'=>((Yii::app()->language=='uk') ? 'action':''), ));
Total 9 comments
Fixed, please download the above version from download page
Had the same problem with parameter 'urlFormat'=>'path', enabled. First disable this and check if your raw urls are correct.
When I test the link is change from 'en' to 'fr' but :
Yii::t('blog','my message');//not translate into french.
Do you have any idea why? Thank you in advance for your response.
Following is the code of my test: <?php echo CHtml::link('English', array(Yii::app()->defaultController.'/',Yii::app()->urlManager->langParam=>'en') ,array('class'=>((Yii::app()->language=='en') ? 'action':''), )); echo ' . '; echo CHtml::link('French', array(Yii::app()->defaultController.'/',Yii::app()->urlManager->langParam=>'fr') ,array('class'=>((Yii::app()->language=='fr') ? 'action':''), )); ?>
Yii::t('blog','my message');
In my message language file in folder protected/message/fr/blog.php return array ( 0 => '', 'My message' => 'Mon message', );
When I click on French, output display as follows:
lang = "fr" is selected
My message
'My message' is not translated to 'Mon message'
defined:
languages=>array('en_us'=>'English', 'zh_cn'=>'中文')and, you can list all languages in header on your site, look like:
foreach(Yii::app()->urlManager->languages as $lang=>$title) { echo '<li>' . CHtml::link($title, array('', 'lang'=>$lang)) . '</li>'; }And for what purpose you would like so I added it to the code? I personally have not discerned in this practical use. Although, maybe I'm wrong
i think languages parameter use following will beter:
'urlManager' => array( 'class'=>'application.extensions.urlManager.LangUrlManager', 'languages' => array( 'en_us' => 'English', // first item is primary language(source language) 'zh_cn' => '中文', ), ),
I think that will add several new features: 1) setting the default language of the preferred language transmitted by browser 2) improve the parsing of language
I think that will add several new features: 1) setting the default language of the preferred language transmitted by browser 2) improve the parsing of language
thanks for you extension share~
this extension is better than "langhandler" http://www.yiiframework.com/extension/langhandler/
and, i share my default routes:
'<lang:(zh_cn|en_us)>/<_m:(srbac)>/<_c>/<_a>*' => '<_m>/<_c>/<_a>', '<lang:(zh_cn|en_us)>/<_c>/<_a>*' => '<_c>/<_a>', '<lang:(zh_cn|en_us)>/<_c>' => '<_c>', '<lang:(zh_cn|en_us)>' => '',
Leave a comment
Please login to leave your comment.