Getting Started

Add a new language

5 views April 3, 2015 March 11, 2019 admin 0

To add a new language to the application, you basically need two things:

  1. Translate English strings to the new language.
  2. Add the new language to the list of languages supported by the application.

1. Translate strings

To translate strings you must do the following:

  1. Locate the @app/messages folder and create a new folder which name include the ISO language code (in lowercase) and the ISO country code (in uppercase), separated by a hyphen. For example, Brazilian Portuguese, ‘pt-BR’.
  2. Then copy the file app.php from the ‘es-ES’ folder and paste it into your new folder. Let’s say in ‘pt-BR’.
  3. Then translate strings from English to the new language (To continue our example, replace strings in Spanish to Portuguese).
  4. Save the file and the application will be translated to the new language.

2. Add new language to the application

To add your new language:

  1. Open the file @app/helpers/language.php
  2. Add the line "pt-BR" => Yii :: t ('app', 'Portuguese'), to suportedLanguage() method.
  3. Save the file

Following the example, the method should end like:

public static function supportedLanguages()
{
    return array(
        "en-US" => Yii::t('app', 'English'),
        "es-ES" => Yii::t('app', 'Spanish'),
        "pt-BR" => Yii::t('app', 'Portuguese'),
    );
}

From now on, when you enter the application, you can change the language to portuguese from your User Profile.

Note: Keep in mind that the text you type in the source code must be in English.

Additional Step

As added the ‘Portuguese’ string to the application, it is recommended to translate this string in both Spanish and Portuguese:

  1. Open the file @app/messages/es-ES/app.php and add ‘Portuguese’ => ‘Portugués’,.
  2. Open the file @app/messages/pt-BR/app.php and add ‘Portuguese’ => ‘Português’,.

Was this helpful?