- add language code table to your ‘about’ table.
id, description, language_id (fk)
- populate with proper data
1 - this is a description - english
2 - ceci est une description - french
3 - bla bla bla - other language
- in the app, you need to do a couple of things.
check for the language to be displayed and then fetch the description in the proper language.
To setup i18n, you need to do the following. I will show you what i did in my current project.
in main.php, set default language.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
// Application name
'name'=>'PMMetriX',
'sourceLanguage'=>'en_us',
in userIdentity, i set a session variable to the default language selected by the user
// set language code as per user preferrence - i.e. en_us, fr_ca,, etc.
$languageCode = Language::model()->findByPk($user->language_id);
$app->user->setState('languageId', $languageCode->code);
i extended Controller so that everytime an action is requested, it populates Yii::app->user->languageId
public function init()
{
if (isset(Yii::app()->user->languageId))
return Yii::app()->language = Yii::app()->user->languageId;
}
i then created a widget to display some text in the preferred language
class SearchInstText extends CWidget
{
public function run()
{
$systemMessage = SystemMessage::model()->findByPk(11);
if (isset(yii::app()->language))
if (yii::app()->language === 'en_us')
$textVar = 'text';
else
$textVar = 'text_fr_ca';
$this->render('searchInstTextView', array('systemMessage'=>$systemMessage[$textVar]));
}
}
and the view:
<?php
echo $systemMessage;
?>
for the labels, hints and other little things, this is handled through Yii:t.