title: Complete C++ i18n gettext() "hello world" example
body: <p>I am looking for a complete i18n <code>gettext()</code> hello world example. I have started a script based upon <a href="http://oriya.sarovar.org/docs/gettext_single.html" rel="noreferrer">A tutorial on Native Language Support using GNU gettext</a> by G. Mohanty. I am using Linux and G++.</p>
  
  <p>Code:</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;
  #include &lt;cstdlib&gt;
  int main (){
      char* cwd = getenv("PWD");
      std::cout &lt;&lt; "getenv(PWD): " &lt;&lt; (cwd?cwd:"NULL") &lt;&lt; std::endl;
      char* l = getenv("LANG");
      std::cout &lt;&lt; "getenv(LANG): " &lt;&lt; (l?l:"NULL") &lt;&lt; std::endl;
      char* s = setlocale(LC_ALL, "");
      std::cout &lt;&lt; "setlocale(): " &lt;&lt; (s?s:"NULL") &lt;&lt; std::endl;
      std::cout &lt;&lt; "bindtextdomain(): " &lt;&lt; bindtextdomain("hellogt", cwd) &lt;&lt; std::endl;
      std::cout &lt;&lt; "textdomain(): " &lt;&lt; textdomain( "hellogt") &lt;&lt; std::endl;
      std::cout &lt;&lt; gettext("hello, world!") &lt;&lt; std::endl;
  }
  EOF
  g++ -ohellogt hellogt.cxx
  xgettext -d hellogt -o hellogt.pot hellogt.cxx
  msginit --no-translator -l es_MX -o hellogt_spanish.po -i hellogt.pot
  sed --in-place hellogt_spanish.po --expression='/#: /,$ s/""/"hola mundo"/'
  sed --in-place hellogt_spanish.po --expression='s/PACKAGE VERSION/hellogt 1.0/'
  mkdir -p ./es_MX/LC_MESSAGES
  msgfmt -c -v -o ./es_MX/LC_MESSAGES/hellogt.mo hellogt_spanish.po
  export LANG=es_MX
  ls -l $PWD/es_MX/LC_MESSAGES/hellogt.mo
  ./hellogt
  strace -e trace=open ./hellogt
  </code></pre>
  
  <p>The program compiles, the text is extracted, Spanish file is created, modified and binary created but hellogt still displays English. The trace shows no evidence of looking in the current working directory for es_MX nor any references to LC_MESSAGES directory.</p>