我正在处理这个问题很长一段时间,这不是我的第一个问题,但我仍然无法让本地化正常工作。我使用 WAMP 服务器和 php gettext。我为演示我的问题而制作的一个简单代码:
/* dirs */
$directory = realpath('../locale');
$domain = 'messages';
/* trying to find out correct setting - last one is winner */
$locale ="ro";
$locale ="ro_utf8";
$locale ="ro_RO";
$locale ="ro_RO.UTF-8";
$locale ="Romanian_Romania.1250";
putenv("LANG=".$locale);
print setlocale( LC_ALL, $locale);
setlocale( LC_ALL, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
/* STRING TO BE TRANSLATED */
echo _('string');
在../locale目录中有很多这样的文件夹 - $language_name/LC_MESSAGES/。这些包含相应的 .po 和 . mo 文件的翻译如下:
msgid "string"
msgstr "string SK"
在sk_SK文件夹或这个
msgid "string"
msgstr "string RO"
在ro, ro_RO, ro_RO.UTF8, ro_RO.UTF-8, romanian, Romanian_Romania, Romanian_Romania.1250文件夹中。
什么文件看起来像:
Romanian_Romania.1250 字符串 SK
所以你可以清楚地看到 -我将 locale() 设置为 romanian,但我的文本是使用目录中的翻译翻译的sk_SK。我究竟做错了什么?
是否有一些函数可以用来获取有关我的服务器期望找到的 $locale 字符串和目录名称的信息?