Yii 和 PHP Gettext [英] Yii and PHP Gettext
问题描述
我想让我的 yii 应用程序多语言.为此,我想使用 gettext(因为它比 yii 消息简单得多).
I want to make my yii app multilanguage. To do this I want to use gettext (because its much simpler than yii messages).
为此,我使用了这个 yii 扩展,我配置了 PO 文件,我制作了翻译等
To this I used this yii extension, I configured the PO files, I made the translations, etc.
最大的问题:什么都没发生.什么都没有翻译.
The big problem: nothing happened. Nothing was translated.
推荐答案
要使用没有任何扩展名的 gettext,请按照以下步骤操作.在 config/main.php
中像这样设置你的目标语言:
To use gettext without any extension follow those steps. In config/main.php
set yout target language like this:
'language' = 'ru',
设置messages
组件使用CGettextMessageSource
:
'messages' => array(
'class' => 'CGettextMessageSource',
),
在protected/messages/ru
文件夹中创建messages.po
文件(注意:文件夹名称与语言代码相同).如果使用 poedit,messages.po
文件必须有适当的标题.示例:
Create messages.po
file in protected/messages/ru
folder (note: folder name is same as language code). If poedit is used messages.po
file must have appropriate headers. Example:
msgid ""
msgstr ""
"Project-Id-Version: FOO BAR 1.0
"
"Report-Msgid-Bugs-To:
"
"POT-Creation-Date: 2011-11-11 11:11+0300
"
"PO-Revision-Date:
"
"Language: ru
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
"
"X-Poedit-SourceCharset: utf-8
"
"X-Poedit-Basepath: .
"
"X-Poedit-KeywordsList: _ngettext:1,2;t:1c,2
"
"X-Poedit-SearchPath-0: ../..
"
注意t:1c,2
.这意味着,函数 Yii::app()
的第一个参数将用作上下文(参见 msgctx) 和第二个作为要翻译的实际字符串.没有这个,你的 i18n 将无法工作!
Note t:1c,2
. This means, that first parameter from function Yii::app()
will be used as context (see msgctx) and second as actual string to translate. Without this your i18n will not work!
现在只需在 poedit 中打开 messages.po
→ Update
→ 做翻译 → Save
.messages.mo
文件将被 Yii 创建和使用.
Now just open messages.po
in poedit → Update
→ do translations → Save
.
And messages.mo
file will be created and used by Yii.
对于您的语言复数字符串,请参阅 gettext 帮助.
For you language plurals string see gettext help.
这篇关于Yii 和 PHP Gettext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!