pb1*_*149 6 php windows translation gettext poedit
我试图使用PHP gettext扩展来翻译一些字符串.所有函数似乎都返回正确的值,但只调用gettext()/ _()返回原始字符串.PO/MO文件似乎正确,我相信我已正确设置目录.我在Windows上运行带有PHP 5.3.10的WAMP服务器(也尝试运行5.3.4和5.3.8,因为我有安装).
首先,请看/new2/www/index.php:
$locale = 'esn'; # returns Spanish_Spain.1252 in var dump
putenv("LC_ALL={$locale}"); // Returns TRUE
setlocale(LC_ALL, $locale); // Returns 'Spanish_Spain.1252'
$domain = 'messages';
bindtextdomain($domain, './locale'); // Returns C:\wamp\www\new2\www\locale
bind_textdomain_codeset($domain, 'UTF-8'); // Returns UTF-8
textdomain($domain); // Returns'messages'
print gettext("In the dashboard"); // Prints the original text, not the translation.
exit;
Run Code Online (Sandbox Code Playgroud)
我创建了以下文件结构:
www/new2/www/locale/Spanish_Spain.1252/LC_MESSAGES/messages.mo
Run Code Online (Sandbox Code Playgroud)
我也曾尝试更换Spanish_Spain.1252有:es_ES,esn,esp,Spanish,和Spanish_Spain.
用于生成MO的PO文件是这样的(仅给出相关条目):
#: C:\wamp\www\new2/www/index.php:76
msgid "In the dashboard"
msgstr "TRANSLATED es_ES DASHBOARD"
Run Code Online (Sandbox Code Playgroud)
这是使用PoEdit生成的.添加任何新的.MO文件后,我重新启动了Apache.另请注意,我之前使用Zend_Translate和Gettext,它正在正确翻译.我希望依赖本机gettext扩展,部分原因是我试图创建一个自己的轻量级框架.
任何帮助,将不胜感激.
编辑:修改后的目录结构.注意 - 将能够在24小时内尝试最近的答案.
看这里。它在 Windows 和 Linux 上都适用于我。数组中的最后一个值适用于 Windows。可以在此处找到语言名称列表。我的目录在
./locales/en/LC_MESSAGES/domain.mo
/cs/LC_MESSAGES/domain.mo
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6331 次 |
| 最近记录: |