Php 为什么Yii忽略了我的.po文件?

Php 为什么Yii忽略了我的.po文件?,php,yii,gettext,po,Php,Yii,Gettext,Po,因为Yii不能创建没有特殊扩展名的PO文件,所以我只是用创建了一个.PO文件。我想在main.php中使用和配置所有内容 class Yii extends YiiBase { public static function _($message, $category, $params = array()) { return parent::t($category, $message, $params); } } 但是Yii只是忽略了我在main.php中

因为Yii不能创建没有特殊扩展名的PO文件,所以我只是用创建了一个.PO文件。我想在
main.php
中使用和配置所有内容

class Yii extends YiiBase
{
    public static function _($message, $category, $params = array())
    {
        return parent::t($category, $message, $params);
    }
}
但是Yii只是忽略了我在
main.php
中的设置和我的.po文件本身

main.php

'language' => 'de_DE',
[...]    
'components' => array(
    'messages' => array(
        'class' => 'CGettextMessageSource',
        'useMoFile' => false,
        'catalog' => 'messages',
        'basePath' => 'protected/messages'
    ),
),
我的采购订单文件

protected => messages => de_DE => messages.mo, messages.po
msgid ""
msgstr ""
"Project-Id-Version: myTest\n"
"POT-Creation-Date: 2014-04-28 17:18+0100\n"
"PO-Revision-Date: 2014-04-29 09:16+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.4\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: t\n"
"X-Poedit-SearchPath-0: /..."
"trunk/fe/htdocs/protected\n"

#: /htdocs/protected/views/site/index.php:9
msgid "_TEST_"
msgstr "Congratulations! You have successfully created your Yii application."
我的.po文件的内容

protected => messages => de_DE => messages.mo, messages.po
msgid ""
msgstr ""
"Project-Id-Version: myTest\n"
"POT-Creation-Date: 2014-04-28 17:18+0100\n"
"PO-Revision-Date: 2014-04-29 09:16+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.4\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: t\n"
"X-Poedit-SearchPath-0: /..."
"trunk/fe/htdocs/protected\n"

#: /htdocs/protected/views/site/index.php:9
msgid "_TEST_"
msgstr "Congratulations! You have successfully created your Yii application."
由于严格的标准,我无法扩展
t
-函数,因此我在
yii.php
中编写了一个包装器,并将其复制到
protected
中,并将其包含在
main.php

class Yii extends YiiBase
{
    public static function _($message, $category, $params = array())
    {
        return parent::t($category, $message, $params);
    }
}
这是我的index.php,其中有一个字符串需要转换:

<?php echo Yii::_('_TEST_', 'messages');?>

您的po文件中缺少上下文“msgctxt”

[...]
msgctxt "messages"
msgid "_TEST_"
msgstr "Congratulations! You have successfully created your Yii application."

msgctxt "messages"
msgid "_TEST2_"
msgstr "Another translated text."
[...]

您的po文件中缺少上下文“msgctxt”

[...]
msgctxt "messages"
msgid "_TEST_"
msgstr "Congratulations! You have successfully created your Yii application."

msgctxt "messages"
msgid "_TEST2_"
msgstr "Another translated text."
[...]

首先,Yii没有忽略我的.po文件

问题: 易只是被窃听了

如果要使用.po文件进行翻译,它将使用类:


首先,Yii没有忽略我的.po文件

问题: 易只是被窃听了

如果要使用.po文件进行翻译,它将使用类:

正如“克里斯”所说的,你错过了。通过在.po文件中设置适当的头,告诉poedit从
Yii:t()
category
参数生成
msgctxt

"X-Poedit-KeywordsList: t:1c,2\n"
这意味着,第一个参数将在gettext中用作
上下文
,第二个参数将用作消息字符串

另请看我的。

As@chris---说你错过了。通过在.po文件中设置适当的头,告诉poedit从
Yii:t()
category
参数生成
msgctxt

"X-Poedit-KeywordsList: t:1c,2\n"
这意味着,第一个参数将在gettext中用作
上下文
,第二个参数将用作消息字符串


另请参见我的。

是的,没错。但Yii不会生成那些
msgctxt
条目。嗯,Yii不会生成任何po文件。但它会生成PHP数组文件,扩展名不会生成
msgctxt
条目。此外,它只适用于一个
目录
。似乎整个PO
CGettextMessageSource
都被窃听了。是的,没错。但Yii不会生成那些
msgctxt
条目。嗯,Yii不会生成任何po文件。但它会生成PHP数组文件,扩展名不会生成
msgctxt
条目。此外,它只适用于一个
目录
。整个PO
CGettextMessageSource
似乎都被窃听了。