How to override necessary messages from main messages in yii2

In yii2, I want to override some translations of the main messages, for example: in @ yii / messages / vi / yii.php, has key => the translated message:

'Update' => 'Sửa'

but in my application I want to change this as:

'Update' => 'Cập nhật'

I created a file: @ app / messages / vi / yii.php, has only one message that needs to be redefined:

return [
    'Update' => 'Cập nhật'
];

in my main.php configuration, I added this to the components:

'i18n' => [
      'translations' => [
            'yii' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages'
           ],
      ],
],

It works, but only for messages with overriding, others from the kernel do not work.

+4
source share
2 answers

I think you need to copy yii.php from the kernel to @common/messages/<your language>/yii.phpand edit it. It should work stably.

+1

-

'i18n'=>[

                    'yii'=>[
                        'class' => 'yii\i18n\PhpMessageSource',
                        'basePath' => "@vendor/yiisoft/yii2/messages",
                        'sourceLanguage' => 'en_US', // put your language here
                        'fileMap' => [
                            'yii'=>'yii.php',
                        ]
                    ]
                ]
            ],
0

Source: https://habr.com/ru/post/1652155/


All Articles