title: Why does locale es_MX work but not es?
body: <p><a href="http://en.wikipedia.org/wiki/Msgfmt#Programming" rel="nofollow noreferrer">Wikipedia entry for GNU gettext</a> shows an example where the locale is just the lanuage, "fr". Whereas the <a href="https://stackoverflow.com/questions/1003360/complete-c-i18n-gettext-hello-world-example/1033337#1033337">i18n gettext() “hello world” example</a> has the locale value with both the language and country, "<code>es_MX</code>". I have modified the "<code>es_MX</code>" example to use just the lanuage, "es", but it produces the English text rather the expected Spanish.</p>
  
  <pre><code>cat &gt;hellogt.cxx &lt;&lt;EOF
  // hellogt.cxx
  #include &lt;libintl.h&gt;
  #include &lt;locale.h&gt;
  #include &lt;iostream&gt;
  int main (){
      setlocale(LC_ALL, "");
      bindtextdomain("hellogt", ".");
      textdomain( "hellogt");
      std::cout &lt;&lt; gettext("hello, world!") &lt;&lt; std::endl;
  }
  EOF
  g++ -o hellogt hellogt.cxx
  xgettext --package-name hellogt --package-version 1.2 --default-domain hellogt --output hellogt.pot hellogt.cxx
  msginit --no-translator --locale es --output-file hellogt_spanish.po --input hellogt.pot
  sed --in-place hellogt_spanish.po --expression='/"hello, world!"/,/#: / s/""/"hola mundo"/'
  mkdir --parents ./es.utf8/LC_MESSAGES
  msgfmt --check --verbose --output-file ./es.utf8/LC_MESSAGES/hellogt.mo hellogt_spanish.po
  LANG=es.utf8 ./hellogt
  </code></pre>
  
  <p>According to <a href="http://www.linux.com/archive/feature/53781" rel="nofollow noreferrer">Controlling your locale with environment variables</a>:</p>
  
  <blockquote>
    <p>environment variable, LANGUAGE, which
    is used only by GNU gettext ... If
    defined, LANGUAGE takes precedence
    over LC_ALL, LC_MESSAGES, and LANG.</p>
  </blockquote>
  
  <pre><code>LANGUAGE=es.utf8 ./hellogt
  </code></pre>
  
  <p>produces the expected Spanish text rather than English.</p>
  
  <p>But this does not explain why "LANG=es" does not work.</p>