Php 如何在Yi2 advanced中使用Yii::t()配置gettext?
我安装了Yi2 advanced template并使用PhpMessageSource配置Yii::t(),但我需要使用GettextMessageSource配置它。我将以下代码添加到common/config/main-local.php中:Php 如何在Yi2 advanced中使用Yii::t()配置gettext?,php,yii,gettext,multilingual,yii2,Php,Yii,Gettext,Multilingual,Yii2,我安装了Yi2 advanced template并使用PhpMessageSource配置Yii::t(),但我需要使用GettextMessageSource配置它。我将以下代码添加到common/config/main-local.php中: 'i18n' => [ 'translations' => [ 'app*' => [ 'class' => 'yii\i18n\
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\GettextMessageSource',
'basePath' => '@app/messages',
'sourceLanguage' => 'en-US',
],
],
],
放在前端/messages/ru-ru-app.po文件示例文本:
msgid "TEST"
msgstr "Текст"
加载项视图文件:
Yii::t('app', 'TEST');
但它不起作用,我需要在哪里存储.po文件,或者我做错了什么
'basePath' => '@app/messages',
改为
'basePath'=>'@common/messages',
或'basePath'=>'@root/common/messages
并将您的消息替换为common/messages。我还遇到了GettextMessageSource问题。检查您的po文件是否有行msgctxt 应该是这样的:
msgctxt "app"
msgid "Settings"
msgstr "Ustawienia"
还可以将参数传递给它Yii::t()
Yii::t("app", "some text: {someVariable}",["someVariable"=>$whatEverYouWant]))