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.
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?The default language for my php framework is English, UTF-8 - so I'd set
LC_ALL
toen_US.utf-8
, sinceen_US
is ISO-8859-1/Latin1 and obviously that's not as supportive as UTF-8?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?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?
I read somewhere that the usual structure of the
locale
ori18n
folder is something like below.Does the structure really matter? It seems like all that's happening is when you do
bindtextdomain('messages', 'locale')
it recursively searches that directory formessages.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.p开发者_如何学Co
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.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.
If you work with gettext, be sure to check out the PHP Manual User Contributed Notes on Gettext.
精彩评论