Yii和PHP Gettext [英] Yii and PHP Gettext

查看:85
本文介绍了Yii和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\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-11-11 11:11+0300\n"
"PO-Revision-Date: \n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"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;\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-KeywordsList: _ngettext:1,2;t:1c,2\n"
"X-Poedit-SearchPath-0: ../..\n"

注意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.poUpdate→做翻译→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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆