2

我的项目中有本地化工作。工作意味着我的项目被翻译成locale/sk文件夹中的任何语言,sk因为斯洛伐克语是我的默认系统语言。

设置为任何其他语言都不起作用。我试过$lang = 'cs', 'cz', 'en', 'en_UK','en_UK.utf8'和其他的。尽管如此,仅获取'sk'文件夹中的翻译,并且该setlocale()函数仍然返回 false。我试图更改浏览器中的默认语言 - 没有效果。

这是我的代码:

putenv("LANG=$lang"); 
setlocale(LC_ALL, $lang); 
bindtextdomain("messages", realpath("../localem")); 
textdomain("messages");
...
_("Welcome!")

我也试过这些:

putenv("LANGUAGE=$lang"); 
putenv('LC_ALL=$lang');

欢迎任何建议。

编辑:

$loc = array('nor');
if (setlocale(LC_ALL, $loc)==false) print ' false'; else print setlocale(LC_ALL, $loc);

'nor'打印Norwegian (Bokmĺl)_Norway.1252,'rus'俄语,但'svk'打印 false 等等'cze'

在列表中提到了所有这些:

http://msdn.microsoft.com/en-us/library/cdax410z%28v=vs.80%29.aspx

4

1 回答 1

1

Windows uses another format for the locale setting, see MSDN: List of Country/Region Strings.

You can send a list of locales to setlocale by sending in an array, such as to get Norwegian month names and time formats:

setlocale(LC_TIME, array('nb_NO.UTF-8', 'no_NO.UTF-8', 'nor'));

Windows might however return strings in another encoding than UTF-8, so you might want to handle this manually (converting from cpXXXX to UTF-8).

于 2012-07-16T12:57:11.227 回答