Setting the default language
A Yii application uses two kinds of languages: source language and target language.
Source language specifies the language employed to write the source code; the default setting is en-US
, and it is advisable not to change this value since English is the most used and known language in software development. On the other hand, there is a target language used to display content to end users, and we are going to work specifically on this aspect.
This language can be set in the configuration file using the language
property:
return [ // set target language to be Italian 'language' => 'it-IT', .... .... ];
Alternatively, you can use the following code:
// change target language to Italian \Yii::$app->language = 'it-IT';
Now, let's see how to handle app localization in practice.