区域设置正在切换/未正确加载(有时)
我对我们网站的语言/区域设置有一个非常恼人的问题。我一直在这里四处寻找,但没有发现任何类似的东西。
因此,我们支持几种不同的语言,并使用 .po 和 .mo 文件设置所有内容,在大多数情况下都可以正常工作。有时,当您加载某些内容或刷新页面时,它会切换语言。它也没有真正的模式,有时连续 6 个“en”,然后是“sv”,有时每隔一个“sv”和“en”。
例如。如果您想编辑用户,您会看到一个弹出窗口,首先包含authorize.php,我们在其中检查语言并使用此函数进行相应设置:
function _set_locale ($lang){
switch($lang) {
case 'sv': $locale = "sv_SE"; break;
case 'en': $locale = "en_SG"; break;
case 'nl': $locale = "nl_NL"; break;
case 'dk': $locale = "da_DK"; break;
case 'vi': $locale = "vi_VN"; break;
case 'zh': $locale = "zh_CN"; break;
default: $locale = "en_SG"; break;
}
putenv("LANGUAGE=$locale");
setlocale(LC_ALL, "$locale.UTF-8");
bindtextdomain("messages", "./locale/");
textdomain("messages");
我正在使用瑞典语运行一个帐户,'sv ' 设置并刷新编辑用户弹出窗口 10 次并调试此功能,$lang 为“sv”,我记录了 setlocale(LC_ALL, 0),每次都返回“sv_SE.UTF-8”,但页面以英文显示5-6次。
看起来它只是从当前语言切换到原始语言英语,所以我认为它没有被翻译。看起来我们没有设置错误/默认语言,它只是忽略/没有时间?设置语言。
该语言不会保存在 cookie 中,有些帐户只有 1 种语言(不是英语),但仍然会收到此信息。
在上面的例子中。当我们从authorize.php返回时,我们在实际的“编辑用户”页面中不使用任何语言变量。所以它应该无法在那里改变它。 (我还调试并检查了从auth返回时的语言,每次都是瑞典语)。
我不希望任何人能够通过我提供的信息解决这个问题我只是感兴趣如果有人经历过这个或者知道为什么它有时会“切换”请让我知道我是否可以附加一些更多的代码来解决这个问题。
谢谢!
I have a very annoying problem with the language/locale for our site. I've been looking around here but haven't found anything similar.
So we support a few different languages and have everything set up with .po and .mo files which works fine most of the time. Sometimes it switches language when you load something or refresh a page. There's not really a pattern to it either, sometimes 6 'en' in a row and then 'sv' and sometimes every second 'sv' and 'en'.
Ex. If you want to edit a user you get a popup which starts by including authorize.php where we check the language and set it accordingly with this function:
function _set_locale ($lang){
switch($lang) {
case 'sv': $locale = "sv_SE"; break;
case 'en': $locale = "en_SG"; break;
case 'nl': $locale = "nl_NL"; break;
case 'dk': $locale = "da_DK"; break;
case 'vi': $locale = "vi_VN"; break;
case 'zh': $locale = "zh_CN"; break;
default: $locale = "en_SG"; break;
}
putenv("LANGUAGE=$locale");
setlocale(LC_ALL, "$locale.UTF-8");
bindtextdomain("messages", "./locale/");
textdomain("messages");
I was running an account with Swedish, 'sv' set and refreshed the edit user popup 10 times and debugged this function, $lang was 'sv' and I logged setlocale(LC_ALL, 0) which returned 'sv_SE.UTF-8' every time but the page was displayed in English 5-6 times.
It seems like it's only switching from the current language to English which is the original language, so I figure that it's not getting translated. It doesn't look like we're setting the wrong/default language, it just ignores/don't have time? to set the language.
The language is not saved in cookies and some accounts just have 1 language (which is not English) and still gets this.
In the above ex. when we return from authorize.php we don't use any language variable in the actual 'edit user' page. So it shouldn't be able to change it there. (I also debugged and checked the language when returning from auth. and it was Swedish every time).
I don't expect anyone to be able to solve this by the info I've given I'm just interested if someone has experienced this or have any idea why it sometimes 'switches' please let me know if I can attach some more code to sort this out.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个类似的间歇性问题 PHP gettext 和 vagrant 运行 ubuntu ,它在第三个请求时显示了正确的文本。
尝试以下方法之一,我认为这取决于您如何让 PHP 与 Apache 一起运行,
我认为这源于我对传递给 setLocale() 的值进行了修改
I had a similar intermittent problem PHP gettext and vagrant running ubuntu, it was showing the right text on the 3rd request.
Try one of the following, I think it will depend how you have PHP running with Apache
I think it stemmed from me playing around with the value passed to setLocale()