11

As you know in Yii2 the core messages are available in 26 languages. I want to change yii core message language to display validation message in my language.

I added this line to my config file:

'language' => 'fa_IR',

and also added this lines:

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

but core message shown in English. I only want to use framework message available with Yii2. For example in this path vendor/yiisoft/yii2/messages/fa_IR/yii.php

What is the best solution for this work.

b24
  • 2,425
  • 6
  • 30
  • 51

3 Answers3

5

Ohhhh it's my mistake. Language code is fa-IR but I set it fa_IR. I think all language code seperate by _ like 'sourceLanguage' => 'en_US', but it's different. Sorry all.

b24
  • 2,425
  • 6
  • 30
  • 51
0

This code works for me.

Make sure you use translate method in your view files, like:

Yii::t('yii','Update')
user1852788
  • 4,278
  • 26
  • 25
-2
'i18n' => [
    'translations' => [
        'common' => [
            'class' => 'yii\i18n\PhpMessageSource',
            'basePath' => '@common/messages',
        ],
        'static' => [
            'class' => 'yii\mongodb\i18n\MongoDbMessageSource',
            'collection' => 'translation_static'
        ],
        'data' => [
            'class' => 'yii\mongodb\i18n\MongoDbMessageSource',
            'collection' => 'translation_data'
        ],
        'product' => [
            'class' => 'yii\mongodb\i18n\MongoDbMessageSource',
            'collection' => 'translation_product'
        ],
        'user' => [
            'class' => 'yii\mongodb\i18n\MongoDbMessageSource',
            'collection' => 'translation_user'
        ],
    ],
],
George
  • 6,886
  • 3
  • 44
  • 56