//Somewhere in controller: $model = Page::model()->findPk(1); echo $model->text; // Outputs Привет! Yii::app()->language = 'en'; echo $model->text; // Outputs Hello!
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.
Tested only on Yii v1.1.8r3324 with MySQL on PHP 5.3
PS. Testers needed!
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.
Be the first person to leave a comment
Please login to leave your comment.