title: Gettext will always use system default locale
body: <p>I need to localise a Windows-only PHP web application and I'm evaluating the <a href="http://php.net/gettext" rel="noreferrer">gettext extension</a> but I'm having the hardest time trying to make it work in my Windows 7 development box. I've used trial and error together with <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="noreferrer">Process Monitor</a> to overcome the poor and inaccurate documentation and I've managed to make <code>_()</code> display strings from the *.po catalogue that corresponds to the computer's default locale (Modern Spanish in my case). <strong>All my attempts to set a different locale are silently ignored.</strong></p>
  
  <p>I've written a test script with lots of redundant stuff:</p>
  
  <pre><code>&lt;dl&gt;&lt;?php
  
  define('DIR_LOCALE', __DIR__ . DIRECTORY_SEPARATOR . 'locale');
  bindtextdomain('general', DIR_LOCALE);
  bind_textdomain_codeset('general', 'UTF-8');
  textdomain('general');
  
  if(!defined('LC_MESSAGES')){
      define('LC_MESSAGES', 5);
  }
  
  $pruebas = array(
      'enu',
      'es_ES',
      'en_GB',
      'english-uk',
      'Spanish_Spain.1252',
      'esn',
      'spanish',
      'spanish-modern',
  );
  foreach($pruebas as $locale){
      putenv("LC_ALL=$locale");
      setlocale(LC_ALL, $locale);
  
      putenv("LC_MESSAGES=$locale");
      setlocale(LC_MESSAGES, $locale);
  
      putenv("LANGUAGE=$locale");
      putenv("LANG=$locale");
  ?&gt;
      &lt;dt&gt;&lt;?=htmlspecialchars($locale)?&gt;&lt;/dt&gt;
      &lt;dd&gt;&lt;?=_('codigo_idioma')?&gt;&lt;/dd&gt;
  &lt;?php } ?&gt;
  &lt;/dl&gt;
  </code></pre>
  
  <p>In my case, <code>&lt;?=_('codigo_idioma')?&gt;</code> always prints <code>es_ES@modern</code>.</p>
  
  <p>I have PHP/5.4.5 but I'm expecting to get it working in any reasonably up-to-date server our customers own.</p>
  
  <p>I've read lots of vague references about the need to install locales even on Windows but no exact details. <strong>What can the problem be?</strong></p>
  
  <p><sup><em>(I'm aware that the common advice is to dump gettext and use any other library.)</em></sup></p>
  
  <hr>
  
  <p><strong>Further testing:</strong></p>
  
  <p>My code run flawlessly as-is in another two computers: 32-bit Windows Vista and 32-bit Windows 7 32-bit. It fails in my computer (64-bit Windows 7) and another one (32-bit Windows Server 2003)</p>
  
  <ul>
  <li>Apache version seems irrelevant (it also happens with the command-line interpreter).</li>
  <li>PHP version seems irrelevant (also tried latest 32-bit PHP/5.5.5 in my PC).</li>
  <li>My <code>[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls]</code> registry tree is identical to the other Seven box.</li>
  </ul>
  
  <p><strong>Edit:</strong> While testing on the command-line, I've discovered that setting the <code>LANG</code> environment variable before running the PHP script finally changes the language:</p>
  
  <pre><code>C:\&gt;set LANG=en_GB
  C:\&gt;php C:\test\gettext.php
  </code></pre>
  
  <p>This definitively proves that my computer has the correct assets but also makes me wonder why PHP claims that <code>putenv()</code> works and then ignores it:</p>
  
  <pre><code>var_dump( getenv('LANG'), putenv('LANG=en_GB'), getenv('LANG') );
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>bool(false)
  bool(true)
  string(5) "en_GB"
  </code></pre>
  
  <p>Even this doesn't have any effect:</p>
  
  <pre><code>$_ENV['LANG'] = 'en_GB';
  $_SERVER['LANG'] = 'en_GB';
  </code></pre>