title: PHP/Gettext Problems
body: <p>I remember running some tests a some months ago with gettext and the following code worked perfectly:</p>
  <pre><code>putenv('LANG=l33t');
  putenv('LANGUAGE=l33t');
  putenv('LC_MESSAGES=l33t');
  
  if (defined('LC_MESSAGES')) // available if PHP was compiled with libintl
  {
      setlocale(LC_MESSAGES, 'l33t');
  }
  
  else
  {
      setlocale(LC_ALL, 'l33t');
  }
  
  bindtextdomain('default', './locale'); // ./locale/l33t/LC_MESSAGES/default.mo
  bind_textdomain_codeset('default', 'UTF-8');
  textdomain('default');
  
  echo _('Hello World!'); // h3110 w0r1d!
  </code></pre>
  <p>This worked perfectly (under Windows XP and CentOS if I remember correctly), which was good because I could use <em>arbitrary</em> &quot;locales&quot;, without having to bother if they were installed on the system or not. However, this doesn't seem to work anymore, I wonder why...</p>
  <hr />
  <h3>Red Hat + PHP 5.2.11:</h3>
  <p>I'm able to switch back and forth from various locales and the translations show up correclty as long as the <code>setlocale()</code> call doesn't return false (if the locale is available/installed on the system).</p>
  <p>This is not perfect (would be great if I could just point gettext to any arbitrary translation directory without having to test for the existence of the locale), but it's acceptable. I'll run some more tests later on.</p>
  <h3>Windows 7 + PHP 5.3.1 (XAMPP):</h3>
  <p><code>setlocale()</code> always returns false (even when using <code>LC_ALL</code> instead of <code>LC_MESSAGES</code>), unless I use some valid Windows locale such as <code>eng</code>, <code>deu</code> or <code>ptg</code> - in this case the locale seems to be correctly set but the translations still don't show up. I can't test right now because I've hundreds of tabs open but I think the very first call to that script yields the correct translation (restarting Apache won't do the trick).</p>
  <p>I'm not sure if this is related to the <a href="http://bugs.php.net/bug.php?id=49349" rel="noreferrer">PHP Bug #49349</a>. I'll test this is a couple of hours.</p>
  <hr />
  <p>Is there any way to use the gettext extension (not pure PHP implementations like <a href="https://launchpad.net/php-gettext/" rel="noreferrer">php-gettext</a> or the <a href="http://framework.zend.com/manual/en/zend.translate.adapter.html" rel="noreferrer">Zend Translate Adapter</a>) reliably across different operating systems (possibly with <em>custom</em> locales like <code>l33t</code>)?</p>
  <p>Also, is it absolutely necessary to use <code>setlocale(LC_ALL, ...)</code>? I would preffer leaving the <code>TIME</code>, <code>NUMERIC</code> and <code>MONETARY</code> (specially) locale settings untouched (defaulting to the <code>POSIX</code> locale).</p>
  <hr />
  <p>I had an idea... Would it be possible to call <code>setlocale()</code> with a very common locale (like <code>C</code>, <code>POSIX</code> or <code>en_US</code>) and specify the language via the domain? Something like this:</p>
  <pre><code>/lang/C/LC_MESSAGES/domain.pt.mo
  /lang/C/LC_MESSAGES/domain.de.mo
  /lang/C/LC_MESSAGES/domain.en.mo
  /lang/C/LC_MESSAGES/domain2.pt.mo
  /lang/C/LC_MESSAGES/domain2.de.mo
  /lang/C/LC_MESSAGES/domain2.en.mo
  </code></pre>
  <p>Would this work on *nix and Windows plataforms without problems?</p>