i18n/gettext:Web应用程序中的setlocale配置 [英] i18n/gettext : setlocale configuration in web applications
问题描述
所以我开始搞弄gettext
,但是我仍然对某些事情感到困惑,如果有人可以帮助我并为我填补空白,那将是很棒的.
So I started messing around with gettext
but I'm still puzzled about certain things, would be great if anyone could help me out and fill in the gaps for me.
-
通常,大多数实现只是基于语言参数调用
setlocale
.在某些情况下,我可能需要使用putenv
,对于Windows安装程序中的特殊情况?
Usually most of the implementations just invoke
setlocale
based on a language parameter. Is there any case in which I need to useputenv
, perhaps for edge cases on Windows setups?
我的php框架的默认语言是英语UTF-8-因此我将LC_ALL
设置为en_US.utf-8
,因为en_US
是ISO-8859-1/Latin1,显然不是支持UTF-8吗?
The default language for my php framework is English, UTF-8 - so I'd set LC_ALL
to en_US.utf-8
, since en_US
is ISO-8859-1/Latin1 and obviously that's not as supportive as UTF-8?
调用setlocale(LC_ALL, 'en_US.utf-8')
后,我应该了解一些陷阱吗?由于它更改了所有这些内容,所以:LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, and LC_MESSAGES
-我是否需要更新任何脚本,例如生成时间或类似时间的脚本?
Are there any gotchas I should know about after invoking setlocale(LC_ALL, 'en_US.utf-8')
? Since it changes all of these: LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME, and LC_MESSAGES
- will I have to update any scripts for example, that generate time or something like that?
例如,假设一台新配置的服务器未配置es_ES.utf-8
语言环境,我知道如何生成语言环境,但是如果它不可用,那我应该在阵列中提供备份吗?如果有人可以提供一个实际的例子,那就太好了,
Let's say for example a freshly configured server did not have es_ES.utf-8
locale configured, I know how to generate the locale but if it wasn't available then should I provide backups in an array? Would be great if someone could provide a practical example, like:
setlocale( LC_ALL, array('es_ES.UTF-8', 'es_ES', 'es') )
是否存在提供此类示例的网站,或者人们通常会提出优先顺序吗?
Is there some sort of website that offers examples such as this, or do people usually come up with the priority ordering themselves?
我读到某处locale
或i18n
文件夹的通常结构如下所示.
I read somewhere that the usual structure of the locale
or i18n
folder is something like below.
结构真的重要吗?似乎发生的一切都是当您执行bindtextdomain('messages', 'locale')
时,它递归地在该目录中搜索messages.mo
,我可能没有注意到,但可能是考虑了目录.
Does the structure really matter? It seems like all that's happening is when you do bindtextdomain('messages', 'locale')
it recursively searches that directory for messages.mo
, I might not be noticing but it might be taking the directories into account.
我对结构应该有多严格?
How strict should I be with the structure?
locale
en_US
LC_MESSAGES
messages.po
es_ES
LC_MESSAGES
messages.po
6. 我是否应该尝试测试系统是否真正支持语言环境?因为例如,如果服务器没有语言环境,而我尝试使用setlocale
进行设置,则不会出错,也不会出现任何错误,它只会默默地通过它.
6. Should I even bother with trying to test whether the system actually supports the locale or not? Because for example, if a server didn't have a locale and I attempted to set it with setlocale
it wouldn't error out or anything, it would just silently let it go by.
推荐答案
不是您问题的合格答案,我并不是说使用gettext是不好的-我从来没有足够的配合它对此有很深的见解-但由于它的复杂性以及在具有不同区域设置的不同平台上的大量不可预测性,我决定不让gettext呆在那里.我在此处发表了一个问题,周围不是很多,Zend_translate包似乎值得一看.我自己还没有解决这个问题.
This is not a qualified answer to your question, and I'm not saying using gettext is bad - I never worked enough with it to have a really deep opinion on it - but I decided to leave gettext alone because of its complexity and massive unpredictability on different platforms with different locales. I posted a question looking for alternatives here and while there is not really much around, the Zend_translate package seems to be worth a look. I haven't got around to it myself yet.
如果您使用gettext,请务必查看 PHP手册关于Gettext的用户贡献的注释
If you work with gettext, be sure to check out the PHP Manual User Contributed Notes on Gettext.
这篇关于i18n/gettext:Web应用程序中的setlocale配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!