@gilbert
To internationalize Yii applications, you can follow these steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
'i18n' => [ 'translations' => [ 'app*' => [ 'class' => 'yiii18nPhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en-US', 'fileMap' => [ 'app' => 'app.php', 'app/error' => 'error.php', ], ], ], ], |
1
|
echo Yii::t('app', 'Hello World!'); |
This will output the translated message for the current language.
1
|
'language' => 'en-US', |
You can also change the language dynamically by setting the 'language' parameter of the Yii::$app object:
1
|
Yii::$app->language = 'fr-FR'; |
That's it! Your Yii application is now internationalized and ready to support multiple languages.