YII2:在代码中使用i18n

1.添加配置
'i18n' => [
                'translations' => [
                        'gs*' => [
                        'class' => 'yii\i18n\PhpMessageSource',
                        'basePath' => '@app/message',
                        'sourceLanguage' => 'en-US',
                                'fileMap' => [
                                'app' => 'app.php',
                                ],
                        ],
                ],
        ],
'language' => 'zh-CN',
2.添加翻译文件
return [
        'test'=>'测试'
];
3.使用
Yii::t('gs', 'test');