Question

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.

  1. Usually most of the implementations just invoke setlocale based on a language parameter. Is there any case in which I need to use putenv, perhaps for edge cases on Windows setups?

  2. 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?

  3. 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?

  4. 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?

  5. I read somewhere that the usual structure of the locale or i18n 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 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.  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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top