b24
b24

Reputation: 2473

yii2 framework message language

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.

Upvotes: 11

Views: 6847

Answers (3)

Vinh Huynh Tu
Vinh Huynh Tu

Reputation: 1

'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'
        ],
    ],
],

Upvotes: -2

b24
b24

Reputation: 2473

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.

Upvotes: 5

Degger
Degger

Reputation: 4323

This code works for me.

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

Yii::t('yii','Update')

Upvotes: 0

Related Questions