Intoduction ¶
//Somewhere in controller:
$model = Page::model()->findPk(1);
echo $model->text; // Outputs Привет!
Yii::app()->language = 'en';
echo $model->text; // Outputs Hello!
Setup ¶
- Download extension.
- Copy STranslateableBehavior folder to extensions directory.
- Copy TranslateCommand.php to commands directory.
Usage ¶
1: Edit models, that you want to be able to translate. Enable STranslateableBehavior:
public function behaviors()
{
return array( 'translate'=>'application.extensions.STranslateableBehavior.STranslateableBehavior' );
}
2: Add translate method and define attributes to translate:
public function translate()
{
// List of model attributes to translate
return array('content', 'url'); //Example
}
Save model!
3: Edit config/main.php and add list of supported languages to app params array:
...
'params'=>array(
'languages'=>array('ru', 'en'),
),
...
4: Create migration from command line run:
./yiic translate
Check migration php code!
Apply migration!
./yiic migrate
After migration you should see in your tables columns suffixed with language name.
Compatibility ¶
Tested only on Yii v1.1.8r3324 with MySQL on PHP 5.3
Links ¶
PS. Testers needed!
History ¶
2011-29-07 - Initial release. Note - this is first release and this extension is a try to find a new way of model translation in Yii projects.
Improved version available
Thanks for creating this extension! After using the extension in a couple of projects, we created and released an improved version, available here: http://www.yiiframework.com/extension/i18n-columns/
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.