how to use multilanguage in yii2? [duplicate]

試著忘記壹切 提交于 2019-12-24 16:37:08

问题


How to create multilanguage app in yii2?
Is there any preinstall message in yii2?

config:

'language' => 'es',
'components' => [
    'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                //'basePath' => '@app/messages',
                'sourceLanguage' => 'ru-RU',

                'fileMap' => [
                    'app' => 'app.php',
                    'app/error' => 'error.php',
                ],
            ],
        ],
    ],

view :

echo \Yii::t('app', 'I am a message!');
$username = 'Alexander';
echo \Yii::t('app', 'Hello, {username}!', [
    'username' => $username,
]);

回答1:


Try this:

Edit config.php in frontend or backend

'language' => 'ru',
'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages',
                'fileMap' => [
                    'app' => 'app.php',
                ],
            ],
        ],
    ],

create app.php in frontend/messages/ru/app.php or backend/messages/ru/app.php

View:

echo \Yii::t('app', 'I am a message!');


来源:https://stackoverflow.com/questions/32882444/how-to-use-multilanguage-in-yii2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!