如何在yii2中创建多语言应用程序?
是否在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',
],
],
],
],
观点:
echo \Yii::t('app', 'I am a message!');
$username = 'Alexander';
echo \Yii::t('app', 'Hello, {username}!', [
'username' => $username,
]);
答案 0 :(得分:0)
试试这个:
在前端或后端编辑config.php
'language' => 'ru',
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
'fileMap' => [
'app' => 'app.php',
],
],
],
],
在app.php
或frontend/messages/ru/app.php
backend/messages/ru/app.php
查看:
echo \Yii::t('app', 'I am a message!');