This extension will set up your applications target language according to visitors browser setting, accepted languages list and country code passed in url.
After a long time langhandler has been updated to version 1.1 (version of langhandler, not Yii). There is an optional boolean parameter $strict available now. It defaults to false and can be set to true like any other component attribute:
'ELangHandler' => array ( 'class' => 'application.extensions.langhandler.ELangHandler', 'languages' => array('pl','en','de'), 'strict' => true, ),
If $strict is left to default false it will not try to compare browser's preferred language exactly like reported, instead it will try to extract language code only. When it is set to true langhandler functionality will not be changed compared to initial release.
Notice that when language is reported with area code it will always be converted to canonical form with underscore separating codes. So if area matters for you (you may want to set locale based on area not only language) set $strict to true and insert codes pairs (ll_AA format) in languages array.
This update changes defaults compared to initial release, so if you are using ll_AA codes now remember to set $strict to true or your application may (and probably will) misbehave after updating to langhandler 1.1.
'ELangHandler' => array ( 'class' => 'application.extensions.langhandler.ELangHandler', 'languages' => array('pl','en','de'), ),
COMMENT: languages array should contain languages codes which will be accepted by application. sourceLanguage code doesn't have to be inserted, however it may be useful in some situations (will be explained later).
'urlManager'=>array( 'class'=>'application.extensions.langhandler.ELangCUrlManager', 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( '<lang:(pl|en|de)>/<_c>/<_a>/' => '<_c>/<_a>', ), ),
COMMENT: urlFormat and showScriptName aren't required but recommended. Route rule and class override are a required minimum.
After component has been configured like in examples above, application will support 3 target languages Polish (pl), English (en), German (de) and source language (yii defaults to en_us). Once language has been chosen langhandler will make sure that its code is passed in url in every request. If language is not specified in url, langhandler will try to recognize browser preffered language and use it, if its code is present in languages array in configuration file. If browser prefered language is not supported by your app, first language from configuration array will be used.
source language (en) supported languages (de,pl)
When adding or removing supported languages remember to alter route rules as well.
If you want to change language simply add lang variable with language code to url.
echo CHtml::link('this link will open current page in german',array('','lang'=>'de'))
For more information about translating core messages, views and other files check Yii documentation