配置
<?php
return [
'language' => 'zh-CN',
'components' => [
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/i18n',
// https://www.yiichina.com/doc/guide/2.0/tutorial-i18n#message-translation
// 消息翻译服务用于将一条文本信息从一种语言(通常是 源语言 ) 翻译成另一种语言(通常是 目标语言)。
// 源语言 sourceLanguage
// 目标语言 language
'sourceLanguage' => 'en-US',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
],
],
],
],
],
];
翻译信息
common\i18n\zh-CN\app.php
<?php
return [
'welcome' => '欢迎'
];
使用
echo \Yii::t('app', 'welcome');