This chapter explains how to write a multilingual app. Localization, also known as Internationalization (I18N), takes care that a software application can be adapted and rendered in different languages without changes in the source code. This is particularly important in a web application where users speak different languages.
Yii provides powerful tools to handle this task, choosing from the file or database approach (according to the application's complexity). We will cover the following topics:
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';
18.188.66.13