I18N

In a view:


echo Yii::t('skate','Good Morning');

In config\web.php:




    'bootstrap' => ['log'],

    'language' => 'pt',

    'sourceLanguage' => 'en_us',

    'components' => [

        ...

        'i18n' => [

            'translations' => [

                '*' => [

                    'class' => 'yii\i18n\PhpMessageSource',

                ],

            ],

        ],

        ...



In vendor/yiisoft/yii2/messages/pt/skate.php:




<?php

return [

    'Good Morning' => 'Bom Dia',

];



Can anyone please help me why the string is not getting translated?

Got it!

Translation files are not stored in vendor/yiisoft/yii2/messages/lang_id.

Translation files are stored in a messages/lang_id directory (that you must create) under your application main directory.

In this case skate.php was copied to appmain/messages/pt and works fine now.

You still need to include the following in your config\web.php file (which it’s not there by default):




        'i18n' => [

            'translations' => [

                '*' => [

                    'class' => 'yii\i18n\PhpMessageSource',

                ],

            ],

        ],



I wish documentation were a little more explicit about this, but well…

Anyway, if someone is also struggling with this, this is the solution.