Home | History | Annotate | Line # | Download | only in doc
      1  1.1  christos <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      2  1.1  christos <html>
      3  1.1  christos <head>
      4  1.1  christos   <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      5  1.1  christos   <title>GNU gettext FAQ</title>
      6  1.1  christos </head>
      7  1.1  christos <body>
      8  1.1  christos <h1 style="text-align: center;">Frequently Asked Questions<br>
      9  1.1  christos for GNU gettext
     10  1.1  christos </h1>
     11  1.1  christos <h1 style="text-align: center;">Questions</h1>
     12  1.1  christos <h3>General</h3>
     13  1.1  christos <ul>
     14  1.1  christos   <li><a href="#general_mailinglist">Where is the mailing list?</a></li>
     15  1.1  christos   <li><a href="#general_source">Where is the newest gettext source?</a></li>
     16  1.1  christos   <li><a href="#general_announce">I want to be notified of new gettext
     17  1.1  christos releases.</a></li>
     18  1.1  christos </ul>
     19  1.1  christos <h3>Problems building GNU gettext</h3>
     20  1.1  christos <ul>
     21  1.1  christos   <li><a href="#building_solaris_libasprintf">On Solaris, I get a build
     22  1.1  christos error text relocations remain in the <span
     23  1.1  christos  style="font-family: monospace;">libasprintf</span> subdirectory</a></li>
     24  1.1  christos   <li><a href="#building_rpath_check">During make check, some tests
     25  1.1  christos named <span style="font-family: monospace;">rpath-<span
     26  1.1  christos  style="font-style: italic;">Nxyz</span></span>
     27  1.1  christos fail: ld: fatal error ... -lrpathz</a></li>
     28  1.1  christos   <li><a href="#building_install">make install fails</a></li>
     29  1.1  christos </ul>
     30  1.1  christos <h3>Problems integrating GNU gettext</h3>
     31  1.1  christos <ul>
     32  1.1  christos   <li><a href="#integrating_howto">How do I make use of <span
     33  1.1  christos  style="font-family: monospace;">gettext()</span> in my package?</a></li>
     34  1.1  christos   <li><a href="#integrating_undefined">I get a linker error undefined
     35  1.1  christos reference to libintl_gettext</a></li>
     36  1.1  christos   <li><a href="#integrating_abuse_gettextize">gettextize adds multiple
     37  1.1  christos references to the same directories/files
     38  1.1  christos to <span style="font-family: monospace;">Makefile.am</span> and </a><span
     39  1.1  christos  style="font-family: monospace;"><a href="#integrating_abuse_gettextize">configure.ac</a><br>
     40  1.1  christos     </span></li>
     41  1.1  christos   <li><a href="#integrating_noop">My program compiles and links fine,
     42  1.1  christos but doesn't output translated
     43  1.1  christos strings.</a><br>
     44  1.1  christos   </li>
     45  1.1  christos </ul>
     46  1.1  christos <h3>GNU gettext on Windows</h3>
     47  1.1  christos <ul>
     48  1.1  christos   <li><a href="#windows_woe32">What does Woe32 mean?</a></li>
     49  1.1  christos   <li><a href="#windows_howto">How do I compile, link and run a program
     50  1.1  christos that uses the gettext()
     51  1.1  christos function?</a><br>
     52  1.1  christos   </li>
     53  1.1  christos   <li><a href="#windows_setenv">Setting the <span
     54  1.1  christos  style="font-family: monospace;">LANG</span>
     55  1.1  christos environment variable doesn't have any effect</a></li>
     56  1.1  christos </ul>
     57  1.1  christos <h3>Other</h3>
     58  1.1  christos <ul>
     59  1.1  christos   <li><a href="#newline">What does this mean: `msgid' and `msgstr'
     60  1.1  christos entries do not both
     61  1.1  christos end with '\n'</a></li>
     62  1.1  christos   <li><a href="#translit">German umlauts are displayed like ge"andert
     63  1.1  christos instead of
     64  1.1  christos gendert</a></li>
     65  1.1  christos   <li><a href="#localename">The <span style="font-family: monospace;">LANGUAGE</span>
     66  1.1  christos environment variable is ignored after I set <span
     67  1.1  christos  style="font-family: monospace;">LANG=en</span></a></li>
     68  1.1  christos   <li><a href="#nonascii_strings">I use accented characters in my
     69  1.1  christos source code. How do I tell the
     70  1.1  christos C/C++ compiler in which encoding it is (like <span
     71  1.1  christos  style="font-family: monospace;">xgettext</span>'s <span
     72  1.1  christos  style="font-family: monospace;">--from-code</span> option)?</a></li>
     73  1.1  christos </ul>
     74  1.1  christos <h1 style="text-align: center;">Answers</h1>
     75  1.1  christos <h3>General</h3>
     76  1.1  christos <h4><a name="general_mailinglist"></a>Where is the mailing list?</h4>
     77  1.1  christos Three mailing lists are available: <br>
     78  1.1  christos <ul>
     79  1.1  christos   <li><span style="font-family: monospace;">bug-gnu-gettext (a] gnu.org</span><br>
     80  1.1  christos This mailing list is for discussion of features and bugs of the GNU
     81  1.1  christos gettext <span style="font-style: italic;">software</span>, including
     82  1.1  christos libintl, the gettext-tools, and its autoconf macros.</li>
     83  1.1  christos   <li><span style="font-family: monospace;">translation-i18n (a] lists.sourceforge.net</span><br>
     84  1.1  christos This mailing list is for methodology questions around
     85  1.1  christos internationalization, and for discussions of translator tools,
     86  1.1  christos including but not limited to GNU gettext.</li>
     87  1.1  christos   <li><span style="font-family: monospace;">translation (a] iro.umontreal.ca</span><br>
     88  1.1  christos This is the email address of the <a
     89  1.1  christos  href="http://www.iro.umontreal.ca/contrib/po/HTML/">Free Translation
     90  1.1  christos Project</a>, that is the project which manages the translated message
     91  1.1  christos catalogs for many free software packages. Note that KDE and GNOME
     92  1.1  christos packages are not part of this project; they have their own translation
     93  1.1  christos projects: <a href="http://i18n.kde.org/">i18n.kde.org</a> and <a
     94  1.1  christos  href="http://developer.gnome.org/projects/gtp/">gtp</a>.<br>
     95  1.1  christos   </li>
     96  1.1  christos </ul>
     97  1.1  christos The <span style="font-family: monospace;">bug-gnu-gettext</span> list
     98  1.1  christos is archived as part of the <a
     99  1.1  christos  href="http://mail.gnu.org/archive/html/bug-gnu-utils/"><span
    100  1.1  christos  style="font-family: monospace;">bug-gnu-utils</span></a> archives. <span
    101  1.1  christos  style="font-family: monospace;">bug-gnu-gettext</span> cannot be
    102  1.1  christos subscribed on its own; to receive its contents by mail, subscribe to <span
    103  1.1  christos  style="font-family: monospace;">bug-gnu-utils</span>.<br>
    104  1.1  christos <h4><a name="general_source"></a>Where is the newest gettext source?</h4>
    105  1.1  christos The newest gettext release is available on <span
    106  1.1  christos  style="font-family: monospace;">ftp.gnu.org</span> and its mirrors, in
    107  1.1  christos <a href="http://ftp.gnu.org/gnu/gettext/">http://ftp.gnu.org/gnu/gettext/</a>.<br>
    108  1.1  christos <br>
    109  1.1  christos Prereleases are announced on the <a
    110  1.1  christos  href="http://mail.gnu.org/pipermail/autotools-announce"><span
    111  1.1  christos  style="font-family: monospace;">autotools-announce</span> mailing list</a>.
    112  1.1  christos Note that prereleases are meant for testing and not meant for use in
    113  1.1  christos production environments. Please don't use the gettextize program of a
    114  1.1  christos prerelease on projects which you share with other programmers via CVS.<br>
    115  1.1  christos <br>
    116  1.1  christos If you want to live on the bleeding edge, you can also use the
    117  1.1  christos development sources. Instructions for retrieving the gettext CVS are
    118  1.1  christos found <a href="http://savannah.gnu.org/projects/gettext">here</a>.
    119  1.1  christos Note that building from CVS requires special tools (autoconf, automake,
    120  1.1  christos m4, groff, bison, etc.) and requires that you pay attention to the <span
    121  1.1  christos  style="font-family: monospace;">README-alpha</span> and <span
    122  1.1  christos  style="font-family: monospace;">autogen.sh</span> files in the CVS.<br>
    123  1.1  christos <h4><a name="general_announce"></a>I want to be notified of new gettext
    124  1.1  christos releases.</h4>
    125  1.1  christos If you are interested in stable gettext releases, you can follow the <a
    126  1.1  christos  href="http://mail.gnu.org/pipermail/info-gnu"><span
    127  1.1  christos  style="font-family: monospace;">info-gnu</span> mailing list</a>. It
    128  1.1  christos is also available as a newsgroup <a
    129  1.1  christos  href="nntp://news.gmane.org/gmane.org.fsf.announce"><span
    130  1.1  christos  style="font-family: monospace;">gmane.org.fsf.announce</span></a>
    131  1.1  christos through <a href="http://www.gmane.org/"><span
    132  1.1  christos  style="font-family: monospace;">gmane.org</span></a>.<br>
    133  1.1  christos <br>
    134  1.1  christos You can also periodically check the download location.<br>
    135  1.1  christos <br>
    136  1.1  christos If you are interested in testing prereleases as well, you can subscribe
    137  1.1  christos to the <a href="http://mail.gnu.org/pipermail/autotools-announce"><span
    138  1.1  christos  style="font-family: monospace;">autotools-announce</span> mailing
    139  1.1  christos list</a>.<br>
    140  1.1  christos <h3>Problems building GNU gettext</h3>
    141  1.1  christos <h4><a name="building_solaris_libasprintf"></a>On Solaris, I get a
    142  1.1  christos build error text relocations remain in the <span
    143  1.1  christos  style="font-family: monospace;">libasprintf</span> subdirectory</h4>
    144  1.1  christos libtool (or more precisely, the version of libtool that was available
    145  1.1  christos at the time the gettext release waas made) doesn't support linking C++
    146  1.1  christos libraries with some versions of GCC. As a workaround, you can configure
    147  1.1  christos gettext with the option <span style="font-family: monospace;">--disable-libasprintf</span>.<br>
    148  1.1  christos <h4><a name="building_rpath_check"></a>During make check, some tests
    149  1.1  christos named <span style="font-family: monospace;">rpath-<span
    150  1.1  christos  style="font-style: italic;">Nxyz</span></span>
    151  1.1  christos fail: ld: fatal error ... -lrpathz</h4>
    152  1.1  christos If only a few among the many rpath tests fail, you can probably ignore
    153  1.1  christos the problem. The rpath tests are sensitive to incomplete shared library
    154  1.1  christos support in the system, and to bugs in libtool that creates the shared
    155  1.1  christos libraries. Some known failures are listed in <span
    156  1.1  christos  style="font-family: monospace;">autoconf-lib-link/tests/rpath.README</span>.<br>
    157  1.1  christos <br>
    158  1.1  christos To ignore the problem, just proceed with<br>
    159  1.1  christos <br>
    160  1.1  christos <div style="margin-left: 40px;"><code>cd gettext-tools</code><br>
    161  1.1  christos <code>make check</code><br>
    162  1.1  christos <code>cd ..</code><br>
    163  1.1  christos </div>
    164  1.1  christos <br>
    165  1.1  christos <h4><a name="building_install"></a>make install fails</h4>
    166  1.1  christos <span style="font-family: monospace;">make install DESTDIR=<span
    167  1.1  christos  style="font-style: italic;">/some/tempdir</span></span> can fail with
    168  1.1  christos an error message relating to <span style="font-family: monospace;">libgettextlib</span>
    169  1.1  christos or <span style="font-family: monospace;">libgettextsrc</span>, or can
    170  1.1  christos silently fail to install <span style="font-family: monospace;">libgettextsrc</span>.
    171  1.1  christos On some platforms, this is due to limitations of libtool regarding <span
    172  1.1  christos  style="font-family: monospace;">DESTDIR</span>. On other platforms, it
    173  1.1  christos is due to the way the system handles shared libraries, and libtool
    174  1.1  christos cannot work around it. Fortunately, on Linux and other glibc based
    175  1.1  christos systems, <span style="font-family: monospace;">DESTDIR</span> is
    176  1.1  christos supported if no different version of gettext is already installed (i.e.
    177  1.1  christos it works if you uninstall the older gettext before building and
    178  1.1  christos installing the newer one, or if you do a plain <span
    179  1.1  christos  style="font-family: monospace;">make install</span> before <span
    180  1.1  christos  style="font-family: monospace;">make install DESTDIR=<span
    181  1.1  christos  style="font-style: italic;">/some/tempdir</span></span>). On other
    182  1.1  christos systems, when&nbsp; <span style="font-family: monospace;">DESTDIR</span>
    183  1.1  christos does not work, you can still do <span style="font-family: monospace;">make
    184  1.1  christos install</span> and copy the installed files to <span
    185  1.1  christos  style="font-family: monospace;"><span style="font-style: italic;">/some/tempdir</span></span>
    186  1.1  christos afterwards.<br>
    187  1.1  christos <br>
    188  1.1  christos If <span style="font-family: monospace;">make install</span> without <span
    189  1.1  christos  style="font-family: monospace;">DESTDIR</span> fails, it's a bug which
    190  1.1  christos you are welcome to report to the usual bug report address.
    191  1.1  christos <h3>Problems integrating GNU gettext</h3>
    192  1.1  christos <h4><a name="integrating_howto"></a>How do I make use of <span
    193  1.1  christos  style="font-family: monospace;">gettext()</span> in my package?</h4>
    194  1.1  christos It's not as difficult as it sounds. Here's the recipe for C or C++
    195  1.1  christos based packages.<br>
    196  1.1  christos <ul>
    197  1.1  christos   <li>Add an invocation of <span style="font-family: monospace;">AM_GNU_GETTEXT([external])</span>
    198  1.1  christos to the package's <span style="font-family: monospace;">configure.{ac,in}</span>
    199  1.1  christos file.</li>
    200  1.1  christos   <li>Invoke <span style="font-family: monospace;">gettextize --copy</span>.
    201  1.1  christos It will do most of the autoconf/automake related work for you.</li>
    202  1.1  christos   <li>Add the <span style="font-family: monospace;">gettext.h</span>
    203  1.1  christos file to the package's source directory, and include it in all source
    204  1.1  christos files that contain translatable strings or do output via <span
    205  1.1  christos  style="font-family: monospace;">printf</span> or <span
    206  1.1  christos  style="font-family: monospace;">fprintf</span>.</li>
    207  1.1  christos   <li>In the source file defining the main() function of the program,
    208  1.1  christos add these lines to the header<br>
    209  1.1  christos     <div style="margin-left: 40px;"><code><span
    210  1.1  christos  style="font-family: monospace;">#include &lt;locale.h&gt;</span><br
    211  1.1  christos  style="font-family: monospace;">
    212  1.1  christos     <span style="font-family: monospace;">#include "gettext.h"</span></code><br>
    213  1.1  christos     </div>
    214  1.1  christos and these lines near the beginning of the main() function:<br>
    215  1.1  christos     <div style="margin-left: 40px;"><code><span
    216  1.1  christos  style="font-family: monospace;">setlocale (LC_ALL, "");</span><br
    217  1.1  christos  style="font-family: monospace;">
    218  1.1  christos     <span style="font-family: monospace;">bindtextdomain (PACKAGE,
    219  1.1  christos LOCALEDIR);</span><br style="font-family: monospace;">
    220  1.1  christos     <span style="font-family: monospace;">textdomain (PACKAGE);</span></code><br>
    221  1.1  christos     </div>
    222  1.1  christos   </li>
    223  1.1  christos   <li>Mark all strings that should be translated with _(), like this: <span
    224  1.1  christos  style="font-family: monospace;">_("No errors found.")</span>. While
    225  1.1  christos doing this, try to turn the strings into good English, one entire
    226  1.1  christos sentence per string, not more than one paragraph per string, and use
    227  1.1  christos format strings instead of string concatenation. This is needed so that
    228  1.1  christos the translators can provide accurate translations.</li>
    229  1.1  christos   <li>In every source file containing translatable strings, add these lines
    230  1.1  christos to the header:<br>
    231  1.1  christos     <div style="margin-left: 40px;"><code><span
    232  1.1  christos  style="font-family: monospace;">#include "gettext.h"</span><br
    233  1.1  christos  style="font-family: monospace;">
    234  1.1  christos     <span style="font-family: monospace;">#define _(string) gettext (string)</span></code><br>
    235  1.1  christos     </div>
    236  1.1  christos   </li>
    237  1.1  christos   <li>In the freshly created <span style="font-family: monospace;">po/</span>
    238  1.1  christos directory, set up the <span style="font-family: monospace;">POTFILES.in</span>
    239  1.1  christos file, and do a <span style="font-family: monospace;">make update-po</span>.
    240  1.1  christos Then distribute the generated <span style="font-family: monospace;">.pot</span>
    241  1.1  christos file to your nearest translation project.</li>
    242  1.1  christos   <li>Shortly before a release, integrate the translators' <span
    243  1.1  christos  style="font-family: monospace;">.po</span> files into the <span
    244  1.1  christos  style="font-family: monospace;">po/</span> directory and do <span
    245  1.1  christos  style="font-family: monospace;">make update-po</span> again.<br>
    246  1.1  christos   </li>
    247  1.1  christos </ul>
    248  1.1  christos You find detailed descriptions of how this all works in the GNU gettext
    249  1.1  christos manual, chapters The Maintainer's View and Preparing Program
    250  1.1  christos Sources.
    251  1.1  christos <h4><a name="integrating_undefined"></a>I get a linker error undefined
    252  1.1  christos reference to libintl_gettext</h4>
    253  1.1  christos This error means that the program uses the <span
    254  1.1  christos  style="font-family: monospace;">gettext()</span> function after having
    255  1.1  christos included the <span style="font-family: monospace;">&lt;libintl.h&gt;</span>
    256  1.1  christos file from GNU gettext (which remaps it to <span
    257  1.1  christos  style="font-family: monospace;">libintl_gettext()</span>), however at
    258  1.1  christos link time a function of this name could not be linked in. (It is
    259  1.1  christos expected to come from the <span style="font-family: monospace;">libintl</span>
    260  1.1  christos library, installed by GNU gettext.)<br>
    261  1.1  christos <br>
    262  1.1  christos There are many possible reasons for this error, but in any case you
    263  1.1  christos should consider the <span style="font-family: monospace;">-I</span>, <span
    264  1.1  christos  style="font-family: monospace;">-L</span> and <span
    265  1.1  christos  style="font-family: monospace;">-l</span> options passed to the
    266  1.1  christos compiler. In packages using <span style="font-family: monospace;">autoconf</span>
    267  1.1  christos generated configure scripts, <span style="font-family: monospace;">-I</span>
    268  1.1  christos options come from the <span style="font-family: monospace;">CFLAGS</span>
    269  1.1  christos and <span style="font-family: monospace;">CPPFLAGS</span> variables
    270  1.1  christos (in Makefiles also <span style="font-family: monospace;">DEFS</span>
    271  1.1  christos and <span style="font-family: monospace;">INCLUDES</span>), <span
    272  1.1  christos  style="font-family: monospace;">-L</span> options come from the <span
    273  1.1  christos  style="font-family: monospace;">LDFLAGS</span> variable, and <span
    274  1.1  christos  style="font-family: monospace;">-l</span> options come from the <span
    275  1.1  christos  style="font-family: monospace;">LIBS</span> variable. The first thing
    276  1.1  christos you should check are the values of these variables in your environment
    277  1.1  christos and in the&nbsp; package's <span style="font-family: monospace;">config.status</span>
    278  1.1  christos autoconfiguration result.<br>
    279  1.1  christos <br>
    280  1.1  christos To find the cause of the error, a little analysis is needed. Does the
    281  1.1  christos program's final link command contains the option -lintl?<br>
    282  1.1  christos <ul>
    283  1.1  christos   <li>If yes:<br>
    284  1.1  christos Find out where the <span style="font-family: monospace;">libintl</span>
    285  1.1  christos comes from. To do this, you have to check for <span
    286  1.1  christos  style="font-family: monospace;">libintl.a</span> and <span
    287  1.1  christos  style="font-family: monospace;">libintl.so*</span> (<span
    288  1.1  christos  style="font-family: monospace;">libintl.dylib</span> on MacOS X) in
    289  1.1  christos each directory given as a -L option, as well as in the compiler's
    290  1.1  christos implicit search directories. (You get these implicit search directories
    291  1.1  christos for gcc by using <span style="font-family: monospace;">gcc -v</span>
    292  1.1  christos instead of <span style="font-family: monospace;">gcc</span> in the
    293  1.1  christos final link command line; compilers other than GCC usually look in <span
    294  1.1  christos  style="font-family: monospace;">/usr/lib</span> and <span
    295  1.1  christos  style="font-family: monospace;">/lib</span>.) A shell command like<br>
    296  1.1  christos     <div style="margin-left: 40px;"><code>$ for d in /usr/local/lib
    297  1.1  christos /usr/lib /lib; do ls -l $d/libintl.*; done</code><br>
    298  1.1  christos     </div>
    299  1.1  christos will show where the <span style="font-family: monospace;">libintl</span>
    300  1.1  christos comes from. By looking at the dates and whether each library defines <span
    301  1.1  christos  style="font-family: monospace;">libintl_gettext</span> (via <span
    302  1.1  christos  style="font-family: monospace;">nm <span style="font-style: italic;">path</span>/libintl.so
    303  1.1  christos | grep libintl_gettext</span>) you can now distinguish three possible
    304  1.1  christos causes of the error:<br>
    305  1.1  christos     <ul>
    306  1.1  christos       <li>Some older libintl is used instead of the newer one. The fix
    307  1.1  christos is to remove the old library or to reorganize your -L options.</li>
    308  1.1  christos       <li>The used libintl is the new one, and it doesn't contain
    309  1.1  christos libintl_gettext. This would be a bug in gettext. If this is the case,
    310  1.1  christos please report it to the usual bug report address.</li>
    311  1.1  christos       <li>The used libintl is a static library (libintl.a), there are
    312  1.1  christos no uses of gettext in .o files before the -lintl but there are some
    313  1.1  christos after the -lintl. In this case the fix is to move the -lintl to the
    314  1.1  christos end or near the end of the link command line. The only libintl
    315  1.1  christos dependency that needs to be mentioned after -lintl is -liconv.</li>
    316  1.1  christos     </ul>
    317  1.1  christos   </li>
    318  1.1  christos   <li>If no:<br>
    319  1.1  christos In this case it's likely a bug in the package you are building: The
    320  1.1  christos package's Makefiles should make sure that -lintl is used where needed.<br>
    321  1.1  christos Test whether libintl was found by configure. You can check this by doing<br>
    322  1.1  christos     <div style="margin-left: 40px;"><code>$ grep
    323  1.1  christos '\(INTLLIBS\|LIBINTL\)' config.status</code><br>
    324  1.1  christos     </div>
    325  1.1  christos and looking whether the value of this autoconf variable is non-empty.<br>
    326  1.1  christos     <ul>
    327  1.1  christos       <li>If yes: It should be the responsibility of the Makefile to
    328  1.1  christos use the value of this variable in the link command line. Does the
    329  1.1  christos Makefile.in rule for linking the program use <span
    330  1.1  christos  style="font-family: monospace;">@INTLLIBS@</span> or <span
    331  1.1  christos  style="font-family: monospace;">@LIBINTL@</span>?<br>
    332  1.1  christos         <ul>
    333  1.1  christos           <li>If no: It's a Makefile.am/in bug.</li>
    334  1.1  christos           <li>If yes: Something strange is going on. You need to dig
    335  1.1  christos deeper.</li>
    336  1.1  christos         </ul>
    337  1.1  christos Note that <span style="font-family: monospace;">@INTLLIBS@</span> is
    338  1.1  christos for <span style="font-family: monospace;">gettext.m4</span> versions
    339  1.1  christos &lt;= 0.10.40 and <span style="font-family: monospace;">@LIBINTL@</span>
    340  1.1  christos is for <span style="font-family: monospace;">gettext.m4</span>
    341  1.1  christos versions &gt;= 0.11, depending on which <span
    342  1.1  christos  style="font-family: monospace;">gettext.m4</span> was used to build
    343  1.1  christos the package's <span style="font-family: monospace;">configure</span> -
    344  1.1  christos regardless of which gettext you have now installed.</li>
    345  1.1  christos       <li>If no: So libintl was not found.<br>
    346  1.1  christos Take a look at the package's <span style="font-family: monospace;">configure.in/ac</span>.
    347  1.1  christos Does it invoke AM_GNU_GETTEXT?<br>
    348  1.1  christos       <ul>
    349  1.1  christos         <li>If no: The gettext maintainers take no responsibilities for
    350  1.1  christos lookalikes named CY_GNU_GETTEXT, AM_GLIB_GNU_GETTEXT, AM_GNOME_GETTEXT
    351  1.1  christos and similar, or for homebrewn autoconf checks. Complain to the package
    352  1.1  christos maintainer.</li>
    353  1.1  christos         <li>If yes: It looks like the <span
    354  1.1  christos  style="font-family: monospace;">-I</span> and <span
    355  1.1  christos  style="font-family: monospace;">-L</span> options were inconsistent.
    356  1.1  christos You should have a <span style="font-family: monospace;">-I<span
    357  1.1  christos  style="font-style: italic;">somedir</span>/include</span> in the <span
    358  1.1  christos  style="font-family: monospace;">CFLAGS</span> or <span
    359  1.1  christos  style="font-family: monospace;">CPPFLAGS</span> if and only if you
    360  1.1  christos also have a <span style="font-family: monospace;">-L<span
    361  1.1  christos  style="font-style: italic;">somedir</span>/lib</span> in the <span
    362  1.1  christos  style="font-family: monospace;">LDFLAGS</span>. And <span
    363  1.1  christos  style="font-family: monospace;"><span style="font-style: italic;">somedir</span>/include</span>
    364  1.1  christos should contain a <span style="font-family: monospace;">libintl.h</span>
    365  1.1  christos if and only if <span style="font-family: monospace;"><span
    366  1.1  christos  style="font-style: italic;">somedir</span>/lib</span> contains <span
    367  1.1  christos  style="font-family: monospace;">libintl.{a,so}</span>.<br>
    368  1.1  christos This case can also happen if you have configured a GCC &lt; 3.2 with
    369  1.1  christos the same <span style="font-family: monospace;">--prefix</span> option
    370  1.1  christos as you used for GNU libiconv or GNU gettext. This is fatal, because
    371  1.1  christos these versions of GCC implicitly use <span
    372  1.1  christos  style="font-family: monospace;">-L<span style="font-style: italic;">prefix</span>/lib</span>
    373  1.1  christos but <span style="font-weight: bold; font-style: italic;">not</span><br
    374  1.1  christos  style="font-weight: bold; font-style: italic;">
    375  1.1  christos           <span style="font-family: monospace;">-I<span
    376  1.1  christos  style="font-style: italic;">prefix</span>/include</span>. The
    377  1.1  christos workaround is to use a different <span style="font-family: monospace;">--prefix</span>
    378  1.1  christos for GCC.<br>
    379  1.1  christos         </li>
    380  1.1  christos       </ul>
    381  1.1  christos      </li>
    382  1.1  christos     </ul>
    383  1.1  christos   </li>
    384  1.1  christos </ul>
    385  1.1  christos <h4><a name="integrating_abuse_gettextize"></a>gettextize adds multiple
    386  1.1  christos references to the same directories/files
    387  1.1  christos to <span style="font-family: monospace;">Makefile.am</span> and <span
    388  1.1  christos  style="font-family: monospace;">configure.ac</span></h4>
    389  1.1  christos If <span style="font-family: monospace;">gettextize</span> is used on
    390  1.1  christos a package, then the <span style="font-family: monospace;">po/</span>, <span
    391  1.1  christos  style="font-family: monospace;">intl/</span>, <span
    392  1.1  christos  style="font-family: monospace;">m4/</span> directories of the package
    393  1.1  christos are removed, and then <span style="font-family: monospace;">gettextize</span>
    394  1.1  christos is invoked on the package again, it will re-add the <span
    395  1.1  christos  style="font-family: monospace;">po/</span>, <span
    396  1.1  christos  style="font-family: monospace;">intl/</span>, <span
    397  1.1  christos  style="font-family: monospace;">m4/</span> directories and change <span
    398  1.1  christos  style="font-family: monospace;">Makefile.am</span>, <span
    399  1.1  christos  style="font-family: monospace;">configure.ac</span> and <span
    400  1.1  christos  style="font-family: monospace;">ChangeLog</span> accordingly. This is
    401  1.1  christos normal. The second use of <span style="font-family: monospace;">gettextize</span>
    402  1.1  christos here is an abuse of the program. <span style="font-family: monospace;">gettextize</span>
    403  1.1  christos is a wizard intended to transform a <span style="font-style: italic;">working
    404  1.1  christos source package</span> into a <span style="font-style: italic;">working
    405  1.1  christos source package</span> that uses the newest version of gettext. If you
    406  1.1  christos start out from a nonfunctional source package (it is nonfunctional
    407  1.1  christos since you have omitted some directories), you cannot expect that <span
    408  1.1  christos  style="font-family: monospace;">gettextize</span> corrects it.<br>
    409  1.1  christos <br>
    410  1.1  christos Often this question arises in packages that use CVS. See the section
    411  1.1  christos CVS Issues / Integrating with CVS of the GNU gettext documentation.
    412  1.1  christos This section mentions a program <span style="font-family: monospace;">autopoint</span>
    413  1.1  christos which is designed to reconstruct those files and directories created by
    414  1.1  christos <span style="font-family: monospace;">gettextize</span> that can be
    415  1.1  christos omitted from a CVS repository.<br>
    416  1.1  christos <h4><a name="integrating_noop"></a>My program compiles and links fine,
    417  1.1  christos but doesn't output translated
    418  1.1  christos strings.</h4>
    419  1.1  christos There are several possible reasons. Here is a checklist that allows you
    420  1.1  christos to determine the cause.<br>
    421  1.1  christos <ol>
    422  1.1  christos   <li>Check that the environment variables LC_ALL, LC_MESSAGES,
    423  1.1  christos LC_CTYPE, LANG, LANGUAGE together specify a valid locale and language.<br>
    424  1.1  christos To check this, run the commands<br>
    425  1.1  christos     <div style="margin-left: 40px;"><code>$ gettext --version</code><br>
    426  1.1  christos     <code>$ gettext --help</code><br>
    427  1.1  christos     </div>
    428  1.1  christos You should see at least some output in your desired language. If not,
    429  1.1  christos either<br>
    430  1.1  christos     <ul>
    431  1.1  christos       <li>You have chosen a too exotic language. <span
    432  1.1  christos  style="font-family: monospace;">gettext</span> is localized to 33
    433  1.1  christos languages. Choose a less exotic language, such as Galician or
    434  1.1  christos Ukrainian. Or<br>
    435  1.1  christos       </li>
    436  1.1  christos       <li>There is a problem with your environment variables. Possibly
    437  1.1  christos LC_ALL points to a locale that is not installed, or LC_MESSAGES and
    438  1.1  christos LC_CTYPE are inconsistent.</li>
    439  1.1  christos     </ul>
    440  1.1  christos   </li>
    441  1.1  christos   <li>Check that your program contains a <span
    442  1.1  christos  style="font-family: monospace;">setlocale</span> call.<br>
    443  1.1  christos To check this, run your program under ltrace. For example,<br>
    444  1.1  christos     <div style="margin-left: 40px;"><code>$ ltrace ./myprog</code><br>
    445  1.1  christos     <code>...</code><br>
    446  1.1  christos     <code>setlocale(6,
    447  1.1  christos "")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    448  1.1  christos = "de_DE.UTF-8"</code><br>
    449  1.1  christos     </div>
    450  1.1  christos If you have no ltrace, you can also do this check by running your
    451  1.1  christos program under the debugger. For example,<br>
    452  1.1  christos     <div style="margin-left: 40px;"><code>$ gdb ./myprog</code><br>
    453  1.1  christos     <code>(gdb) break main</code><br>
    454  1.1  christos     <code>(gdb) run</code><br>
    455  1.1  christos     <code>Breakpoint 1, main ()</code><br>
    456  1.1  christos     <code>(gdb) break setlocale</code><br>
    457  1.1  christos     <code>(gdb) continue</code><br>
    458  1.1  christos     <code>Breakpoint 2, setlocale ()</code><br>
    459  1.1  christos     <code>;; OK, the breakpoint has been hit, setlocale() is being
    460  1.1  christos called.</code><br>
    461  1.1  christos     </div>
    462  1.1  christos Either way, check that the return value of <span
    463  1.1  christos  style="font-family: monospace;">setlocale()</span> is non-NULL. A NULL
    464  1.1  christos return value indicates a failure.&nbsp;</li>
    465  1.1  christos   <li>Check that your program contains a <span
    466  1.1  christos  style="font-family: monospace;">textdomain</span> call, a <span
    467  1.1  christos  style="font-family: monospace;">bindtextdomain</span> call referring
    468  1.1  christos to the same message domain, and then really calls the <span
    469  1.1  christos  style="font-family: monospace;">gettext</span>, <span
    470  1.1  christos  style="font-family: monospace;">dgettext</span> or <span
    471  1.1  christos  style="font-family: monospace;">dcgettext</span> function.<br>
    472  1.1  christos To check this, run the program under ltrace. For example,<br>
    473  1.1  christos     <div style="margin-left: 40px;"><code>$ ltrace ./myprog</code><br>
    474  1.1  christos     <code>...</code><br>
    475  1.1  christos     <code>textdomain("hello-c")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    476  1.1  christos = "hello-c"</code><br>
    477  1.1  christos     <code>bindtextdomain("hello-c", "/opt/share"...) = "/opt/share"...</code><br>
    478  1.1  christos     <code>dcgettext(0, 0x08048691, 5, 0x0804a200, 0x08048689) =
    479  1.1  christos 0x4001721f</code><br>
    480  1.1  christos     </div>
    481  1.1  christos If you have no ltrace, you can also do this check by running your
    482  1.1  christos program under the debugger. For example,<br>
    483  1.1  christos     <div style="margin-left: 40px;"><code>$ gdb ./myprog</code><br>
    484  1.1  christos     <code>(gdb) break main</code><br>
    485  1.1  christos     <code>(gdb) run</code><br>
    486  1.1  christos     <code>Breakpoint 1, main ()</code><br>
    487  1.1  christos     <code>(gdb) break textdomain</code><br>
    488  1.1  christos     <code>(gdb) break bindtextdomain</code><br>
    489  1.1  christos     <code>(gdb) break gettext</code><br>
    490  1.1  christos     <code>(gdb) break dgettext</code><br>
    491  1.1  christos     <code>(gdb) break dcgettext</code><br>
    492  1.1  christos     <code>(gdb) continue</code><br>
    493  1.1  christos     <code>Breakpoint 2, textdomain ()</code><br>
    494  1.1  christos     <code>(gdb) continue</code><br>
    495  1.1  christos     <code>Breakpoint 3, bindtextdomain ()</code><br>
    496  1.1  christos     <code>(gdb) continue</code><br>
    497  1.1  christos     <code>Breakpoint 6, dcgettext ()</code><br>
    498  1.1  christos     </div>
    499  1.1  christos Note that here <span style="font-family: monospace;">dcgettext()</span>
    500  1.1  christos is called instead of the <span style="font-family: monospace;">gettext()</span>
    501  1.1  christos function mentioned in the source code; this is due to an optimization
    502  1.1  christos in <span style="font-family: monospace;">&lt;libintl.h&gt;</span>.<br>
    503  1.1  christos When using libintl on a non-glibc system, you have to add a prefix <span
    504  1.1  christos  style="font-family: monospace;">libintl_</span> to all the function
    505  1.1  christos names mentioned here, because that's what the functions are really
    506  1.1  christos named, under the hood.<br>
    507  1.1  christos If <span style="font-family: monospace;">gettext</span>/<span
    508  1.1  christos  style="font-family: monospace;">dgettext</span>/<span
    509  1.1  christos  style="font-family: monospace;">dcgettext</span> is not called at all,
    510  1.1  christos the possible cause might be that some autoconf or Makefile macrology
    511  1.1  christos has turned off internationalization entirely (like the <span
    512  1.1  christos  style="font-family: monospace;">--disable-nls</span> configuration
    513  1.1  christos option usually does).<br>
    514  1.1  christos   </li>
    515  1.1  christos   <li>Check that the <span style="font-family: monospace;">.mo</span>
    516  1.1  christos file that contains the translation is really there where the program
    517  1.1  christos expects it.<br>
    518  1.1  christos To check this, run the program under strace and look at the <span
    519  1.1  christos  style="font-family: monospace;">open()</span> calls. For example,<br>
    520  1.1  christos     <div style="margin-left: 40px;"><code>$ strace ./myprog 2&gt;&amp;1
    521  1.1  christos | grep '^open('</code><br>
    522  1.1  christos     <code>open("/etc/ld.so.preload", O_RDONLY)&nbsp;&nbsp;&nbsp; = -1
    523  1.1  christos ENOENT (No such file or directory)</code><br>
    524  1.1  christos     <code>open("/etc/ld.so.cache",
    525  1.1  christos O_RDONLY)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 5</code><br>
    526  1.1  christos     <code>open("/lib/libc.so.6",
    527  1.1  christos O_RDONLY)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 5</code><br>
    528  1.1  christos     <code>open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE)
    529  1.1  christos = 5</code><br>
    530  1.1  christos     <code>open("/usr/share/locale/locale.alias", O_RDONLY) = 5</code><br>
    531  1.1  christos     <code>open("/opt/share/locale/de/LC_MESSAGES/hello-c.mo", O_RDONLY)
    532  1.1  christos = 5</code><br>
    533  1.1  christos     <code>...</code><br>
    534  1.1  christos     </div>
    535  1.1  christos A nonnegative <span style="font-family: monospace;">open()</span>
    536  1.1  christos return value means that the file has been found.<br>
    537  1.1  christos If you have no strace, you can also guess the <span
    538  1.1  christos  style="font-family: monospace;">.mo</span> file's location: it is<br>
    539  1.1  christos     <div style="margin-left: 40px;"><span
    540  1.1  christos  style="font-family: monospace;"><span style="font-style: italic;">localedir</span>/<span
    541  1.1  christos  style="font-style: italic;">lang</span>/LC_MESSAGES/<span
    542  1.1  christos  style="font-style: italic;">domain</span>.mo</span><br>
    543  1.1  christos     </div>
    544  1.1  christos where <span style="font-style: italic;">domain</span> is the argument
    545  1.1  christos passed to <span style="font-family: monospace;">textdomain()</span>, <span
    546  1.1  christos  style="font-style: italic;">localedir</span> is the second argument
    547  1.1  christos passed to <span style="font-family: monospace;">bindtextdomain()</span>,
    548  1.1  christos and <span style="font-style: italic;">lang</span> is the language (<span
    549  1.1  christos  style="font-style: italic;">LL</span>) or language and territory (<span
    550  1.1  christos  style="font-style: italic;">LL</span>_<span style="font-style: italic;">CC</span>),
    551  1.1  christos depending on the environment variables checked in step 1.</li>
    552  1.1  christos   <li>Check that the .mo file contains a translation for the string
    553  1.1  christos that is being asked for.<br>
    554  1.1  christos To do this, you need to convert the .mo file back to PO file format,
    555  1.1  christos through the command<br>
    556  1.1  christos     <div style="margin-left: 40px;"><code>$ msgunfmt </code><span
    557  1.1  christos  style="font-family: monospace;"><span style="font-style: italic;">localedir</span>/<span
    558  1.1  christos  style="font-style: italic;">lang</span>/LC_MESSAGES/<span
    559  1.1  christos  style="font-style: italic;">domain</span>.mo</span><br>
    560  1.1  christos     <code></code></div>
    561  1.1  christos and look for an <span style="font-family: monospace;">msgid</span>
    562  1.1  christos that matches the given string.<br>
    563  1.1  christos   </li>
    564  1.1  christos </ol>
    565  1.1  christos <h3>GNU gettext on Windows</h3>
    566  1.1  christos <h4><a name="windows_woe32"></a>What does Woe32 mean?</h4>
    567  1.1  christos Woe32 denotes the Windows 32-bit operating systems for x86: Windows
    568  1.1  christos NT/2000/XP and Windows 95/98/ME. Microsoft uses the term Win32 to
    569  1.1  christos denote these; this is a psychological trick in order to make everyone
    570  1.1  christos believe that these OSes are a win for the user. However, for most
    571  1.1  christos users and developers, they are a source of woes, which is why I call
    572  1.1  christos them Woe32.<br>
    573  1.1  christos <h4><a name="windows_howto"></a>How do I compile, link and run a
    574  1.1  christos program that uses the gettext()
    575  1.1  christos function?</h4>
    576  1.1  christos When you use RedHat's cygwin environment, it's as on Unix:<br>
    577  1.1  christos <ul>
    578  1.1  christos   <li>You need to add an <span style="font-family: monospace;">-I</span>
    579  1.1  christos option to the compilation command line, so that the compiler finds the <span
    580  1.1  christos  style="font-family: monospace;">libintl.h</span> include file, and</li>
    581  1.1  christos   <li>You need to add an <span style="font-family: monospace;">-L</span>
    582  1.1  christos option to the link command line, so that the linker finds the <span
    583  1.1  christos  style="font-family: monospace;">libintl</span> library.</li>
    584  1.1  christos </ul>
    585  1.1  christos When you use the Mingw environment (either from within cygwin, with <span
    586  1.1  christos  style="font-family: monospace;">CC="gcc -mno-cygwin"</span>, or from
    587  1.1  christos MSYS, with <span style="font-family: monospace;">CC="gcc"</span>), I
    588  1.1  christos don't know the details.<br>
    589  1.1  christos <br>
    590  1.1  christos When you use the Microsoft Visual C/C++ (MSVC) compiler, you will
    591  1.1  christos likely use the precompiled Woe32 binaries. For running a program that
    592  1.1  christos uses gettext(), one needs the <span style="font-family: monospace;">.bin.woe32.zip</span>
    593  1.1  christos packages of <span style="font-family: monospace;">gettext-runtime</span>
    594  1.1  christos and <span style="font-family: monospace;">libiconv</span>. As a
    595  1.1  christos developer, you'll also need the <span style="font-family: monospace;">xgettext</span>
    596  1.1  christos and <span style="font-family: monospace;">msgfmt</span> programs that
    597  1.1  christos are contained in the <span style="font-family: monospace;">.bin.woe32.zip</span>
    598  1.1  christos package of <span style="font-family: monospace;">gettext-tools</span>.
    599  1.1  christos Then<br>
    600  1.1  christos <ul>
    601  1.1  christos   <li>You need to add an <span style="font-family: monospace;">-MD</span>
    602  1.1  christos option to all compilation and link command lines. MSVC has six
    603  1.1  christos different, mutually incompatible, compilation models (<span
    604  1.1  christos  style="font-family: monospace;">-ML</span>, <span
    605  1.1  christos  style="font-family: monospace;">-MT</span>, <span
    606  1.1  christos  style="font-family: monospace;">-MD</span>, <span
    607  1.1  christos  style="font-family: monospace;">-MLd</span>, <span
    608  1.1  christos  style="font-family: monospace;">-MTd</span>, <span
    609  1.1  christos  style="font-family: monospace;">-MDd</span>); the default is <span
    610  1.1  christos  style="font-family: monospace;">-ML</span>. <span
    611  1.1  christos  style="font-family: monospace;">intl.dll</span> uses the <span
    612  1.1  christos  style="font-family: monospace;">-MD</span> model, therefore the rest
    613  1.1  christos of the program must use <span style="font-family: monospace;">-MD</span>
    614  1.1  christos as well.<br>
    615  1.1  christos   </li>
    616  1.1  christos   <li>You need to add an <span style="font-family: monospace;">-I</span>
    617  1.1  christos option to the compilation command line, so that the compiler finds the <span
    618  1.1  christos  style="font-family: monospace;">libintl.h</span> include file.<br>
    619  1.1  christos   </li>
    620  1.1  christos   <li>You need to add an <span style="font-family: monospace;">-L</span>
    621  1.1  christos option to the link command line, so that the linker finds the <span
    622  1.1  christos  style="font-family: monospace;">intl.lib</span> library.</li>
    623  1.1  christos   <li>You need to copy the <span style="font-family: monospace;">intl.dll</span>
    624  1.1  christos and <span style="font-family: monospace;">iconv.dll</span> to the
    625  1.1  christos directory where your <span style="font-family: monospace;">.exe</span>
    626  1.1  christos files are created, so that they will be found at runtime.<br>
    627  1.1  christos   </li>
    628  1.1  christos </ul>
    629  1.1  christos <h4><a name="windows_setenv"></a>Setting the <span
    630  1.1  christos  style="font-family: monospace;">LANG</span>
    631  1.1  christos environment variable doesn't have any effect</h4>
    632  1.1  christos If neither LC_ALL, LC_MESSAGES nor LANGUAGES is set, it's the LANG
    633  1.1  christos environment variable which determines the language into which gettext()
    634  1.1  christos translates the messages.<br>
    635  1.1  christos <br>
    636  1.1  christos You can test your program by setting the LANG environment variable from
    637  1.1  christos outside the program. In a Windows command interpreter:<br>
    638  1.1  christos <div style="margin-left: 40px;"><code>set LANG=de_DE</code><br>
    639  1.1  christos <code>.\myprog.exe</code><br>
    640  1.1  christos </div>
    641  1.1  christos Or in a Cygwin shell:<br>
    642  1.1  christos <div style="margin-left: 40px;"><code>$ env LANG=de_DE ./myprog.exe</code><br>
    643  1.1  christos </div>
    644  1.1  christos <br>
    645  1.1  christos If this test fails, look at the question My program compiles and links
    646  1.1  christos fine, but doesn't output translated
    647  1.1  christos strings. above.<br>
    648  1.1  christos <br>
    649  1.1  christos If this test succeeds, the problem is related in the way you set the
    650  1.1  christos environment variable. Here is a checklist:<br>
    651  1.1  christos <ul>
    652  1.1  christos   <li>Check that you are using the <span
    653  1.1  christos  style="font-family: monospace;">-MD</span> option in all compilation
    654  1.1  christos and link command lines. Otherwise you might end up calling the <span
    655  1.1  christos  style="font-family: monospace;">putenv()</span> function from
    656  1.1  christos Microsoft's <span style="font-family: monospace;">libc.lib</span>,
    657  1.1  christos whereas <span style="font-family: monospace;">intl.dll</span> is using
    658  1.1  christos the <span style="font-family: monospace;">getenv()</span> function
    659  1.1  christos from Mictosoft's <span style="font-family: monospace;">msvcrt.lib</span>.</li>
    660  1.1  christos   <li>Check that you set the environment variable using <span
    661  1.1  christos  style="font-style: italic;">both</span> <span
    662  1.1  christos  style="font-family: monospace;">SetEnvironmentVariable()</span> and <span
    663  1.1  christos  style="font-family: monospace;">putenv()</span>. A convenient way to
    664  1.1  christos do so, and to deal with the fact that some Unix systems have <span
    665  1.1  christos  style="font-family: monospace;">setenv()</span> and some don't, is the
    666  1.1  christos following function.<br>
    667  1.1  christos     <br>
    668  1.1  christos     <div style="margin-left: 40px;"><code>#include &lt;string.h&gt;</code><br>
    669  1.1  christos     <code>#include &lt;stdlib.h&gt;</code><br>
    670  1.1  christos     <code>#if defined _WIN32</code><br>
    671  1.1  christos     <code># include &lt;windows.h&gt;</code><br>
    672  1.1  christos     <code>#endif</code><br>
    673  1.1  christos     <code></code><br>
    674  1.1  christos     <code>int my_setenv (const char * name, const char * value) {</code><br>
    675  1.1  christos     <code>&nbsp; size_t namelen = strlen(name);</code><br>
    676  1.1  christos     <code>&nbsp; size_t valuelen = (value==NULL ? 0 : strlen(value));</code><br>
    677  1.1  christos     <code>#if defined _WIN32</code><br>
    678  1.1  christos     <code>&nbsp; /* On Woe32, each process has two copies of the
    679  1.1  christos environment variables,</code><br>
    680  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; one managed by the OS and one
    681  1.1  christos managed by the C library. We set</code><br>
    682  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; the value in both locations, so that
    683  1.1  christos other software that looks in</code><br>
    684  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; one place or the other is guaranteed
    685  1.1  christos to see the value. Even if it's</code><br>
    686  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; a bit slow. See also</code><br>
    687  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a
    688  1.1  christos  href="http://article.gmane.org/gmane.comp.gnu.mingw.user/8272">http://article.gmane.org/gmane.comp.gnu.mingw.user/8272</a>&gt;</code><br>
    689  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a
    690  1.1  christos  href="http://article.gmane.org/gmane.comp.gnu.mingw.user/8273">http://article.gmane.org/gmane.comp.gnu.mingw.user/8273</a>&gt;</code><br>
    691  1.1  christos     <code>&nbsp;&nbsp;&nbsp;&nbsp; &lt;<a
    692  1.1  christos  href="http://www.cygwin.com/ml/cygwin/1999-04/msg00478.html">http://www.cygwin.com/ml/cygwin/1999-04/msg00478.html</a>&gt;
    693  1.1  christos */</code><br>
    694  1.1  christos     <code>&nbsp; if (!SetEnvironmentVariableA(name,value))</code><br>
    695  1.1  christos     <code>&nbsp;&nbsp;&nbsp; return -1; </code><br>
    696  1.1  christos     <code>#endif</code><br>
    697  1.1  christos     <code>#if defined(HAVE_PUTENV)</code><br>
    698  1.1  christos     <code>&nbsp; char* buffer = (char*)malloc(namelen+1+valuelen+1);</code><br>
    699  1.1  christos     <code>&nbsp; if (!buffer)</code><br>
    700  1.1  christos     <code>&nbsp;&nbsp;&nbsp; return -1; /* no need to set errno =
    701  1.1  christos ENOMEM */</code><br>
    702  1.1  christos     <code>&nbsp; memcpy(buffer,name,namelen);</code><br>
    703  1.1  christos     <code>&nbsp; if (value != NULL) {</code><br>
    704  1.1  christos     <code>&nbsp;&nbsp;&nbsp; buffer[namelen] = '=';</code><br>
    705  1.1  christos     <code>&nbsp;&nbsp;&nbsp; memcpy(buffer+namelen+1,value,valuelen);</code><br>
    706  1.1  christos     <code>&nbsp;&nbsp;&nbsp; buffer[namelen+1+valuelen] = 0;</code><br>
    707  1.1  christos     <code>&nbsp; } else</code><br>
    708  1.1  christos     <code>&nbsp;&nbsp;&nbsp; buffer[namelen] = 0;</code><br>
    709  1.1  christos     <code>&nbsp; return putenv(buffer);</code><br>
    710  1.1  christos     <code>#elif defined(HAVE_SETENV)</code><br>
    711  1.1  christos     <code>&nbsp; return setenv(name,value,1);</code><br>
    712  1.1  christos     <code>#else</code><br>
    713  1.1  christos     <code>&nbsp; /* Uh oh, neither putenv() nor setenv() ... */</code><br>
    714  1.1  christos     <code>&nbsp; return -1;</code><br>
    715  1.1  christos     <code>#endif</code><br>
    716  1.1  christos     <code>}</code><br>
    717  1.1  christos     <code></code></div>
    718  1.1  christos     <br>
    719  1.1  christos   </li>
    720  1.1  christos </ul>
    721  1.1  christos <h3>Other</h3>
    722  1.1  christos <h4><a name="newline"></a>What does this mean: `msgid' and `msgstr'
    723  1.1  christos entries do not both end
    724  1.1  christos with '\n'</h4>
    725  1.1  christos It means that when the original string ends in a newline, your
    726  1.1  christos translation must also end in a newline. And if the original string does
    727  1.1  christos not end in a newline, then your translation should likewise not have a
    728  1.1  christos newline at the end.<br>
    729  1.1  christos <h4><a name="translit"></a>German umlauts are displayed like
    730  1.1  christos ge"andert instead of gendert</h4>
    731  1.1  christos This symptom occurs when the <span style="font-family: monospace;">LC_CTYPE</span>
    732  1.1  christos facet of the locale is not set; then gettext() doesn't know which
    733  1.1  christos character set to use, and converts all messages to ASCII, as far as
    734  1.1  christos possible.<br>
    735  1.1  christos <br>
    736  1.1  christos If the program is doing<br>
    737  1.1  christos <code><br>
    738  1.1  christos setlocale (LC_MESSAGES, "");<br>
    739  1.1  christos <br>
    740  1.1  christos </code>then change it to<br>
    741  1.1  christos <code><br>
    742  1.1  christos setlocale (LC_CTYPE, "");<br>
    743  1.1  christos setlocale (LC_MESSAGES, "");<br>
    744  1.1  christos </code><br>
    745  1.1  christos or do both of these in a single call:<br>
    746  1.1  christos <code><br>
    747  1.1  christos setlocale (LC_ALL, "");<br>
    748  1.1  christos </code><br>
    749  1.1  christos If the program is already doing<br>
    750  1.1  christos <code><br>
    751  1.1  christos setlocale (LC_ALL, "");<br>
    752  1.1  christos </code><br>
    753  1.1  christos then the symptom can still occur if the user has not set <span
    754  1.1  christos  style="font-family: monospace;">LANG</span>, but instead has set <span
    755  1.1  christos  style="font-family: monospace;">LC_MESSAGES</span> to a valid locale
    756  1.1  christos and has set <span style="font-family: monospace;">LC_CTYPE</span> to
    757  1.1  christos nothing or an invalid locale. The fix for the user is then to set <span
    758  1.1  christos  style="font-family: monospace;">LANG</span> instead of <span
    759  1.1  christos  style="font-family: monospace;">LC_MESSAGES</span>.<br>
    760  1.1  christos <h4><a name="localename"></a>The <span style="font-family: monospace;">LANGUAGE</span>
    761  1.1  christos environment variable is ignored after I set <span
    762  1.1  christos  style="font-family: monospace;">LANG=en</span></h4>
    763  1.1  christos This is because en is a language name, but not a valid locale name.
    764  1.1  christos The <span style="font-family: monospace;">ABOUT-NLS</span>&nbsp; file
    765  1.1  christos says:<br>
    766  1.1  christos <blockquote>
    767  1.1  christos In the <span style="font-family: monospace;">LANGUAGE</span>
    768  1.1  christos environment variable, but not in the <span
    769  1.1  christos  style="font-family: monospace;">LANG</span> environment variable, <span
    770  1.1  christos  style="font-style: italic;">LL</span>_<span style="font-style: italic;">CC</span><span
    771  1.1  christos  style="font-family: monospace;"> </span>combinations can be
    772  1.1  christos abbreviated as&nbsp;<span style="font-style: italic;">LL</span> to
    773  1.1  christos denote the language's main dialect.</blockquote>
    774  1.1  christos Why is <span style="font-family: monospace;">LANG=en</span> not
    775  1.1  christos allowed? Because <span style="font-family: monospace;">LANG</span> is
    776  1.1  christos a setting for the entire locale, including monetary information, and
    777  1.1  christos this depends on the country: en_GB, en_AU, en_ZA all have different
    778  1.1  christos currencies.<br>
    779  1.1  christos <h4><a name="nonascii_strings"></a>I use accented characters in my
    780  1.1  christos source code. How do I tell the
    781  1.1  christos C/C++ compiler in which encoding it is (like <span
    782  1.1  christos  style="font-family: monospace;">xgettext</span>'s <span
    783  1.1  christos  style="font-family: monospace;">--from-code</span> option)?</h4>
    784  1.1  christos Short answer: If you want your program to be useful to other people,
    785  1.1  christos then <span style="font-style: italic;">don't use accented characters</span>
    786  1.1  christos (or other non-ASCII characters) in string literals <span
    787  1.1  christos  style="font-style: italic;">in the source code</span>. Instead, use
    788  1.1  christos only ASCII for string literals, and use <span
    789  1.1  christos  style="font-family: monospace;">gettext()</span> to retrieve their
    790  1.1  christos display-ready form.<br>
    791  1.1  christos <br>
    792  1.1  christos Long explanation:<br>
    793  1.1  christos The reason is that the ISO C standard specifies that the character set
    794  1.1  christos at compilation time can be different from the character set at
    795  1.1  christos execution time.<br>
    796  1.1  christos The character encoding at compilation time is the one which determines
    797  1.1  christos how the source files are interpreted and also how string literals are
    798  1.1  christos stored in the compiled code. This character encoding is generally
    799  1.1  christos unspecified; for recent versions of GCC, it depends on the LC_CTYPE
    800  1.1  christos locale in effect during the compilation process.<br>
    801  1.1  christos The character encoding at execution time is the one which determines
    802  1.1  christos how standard functions like <span style="font-family: monospace;">isprint()</span>,
    803  1.1  christos <span style="font-family: monospace;">wcwidth()</span> etc. work and
    804  1.1  christos how strings written to standard output should be encoded. This
    805  1.1  christos character encoding is specified by POSIX to depend on the LC_CTYPE
    806  1.1  christos locale in effect when the program is executed; see also the description
    807  1.1  christos in the <span style="font-family: monospace;">ABOUT-NLS</span> file.<br>
    808  1.1  christos Strings in the compiled code are not magically converted between the
    809  1.1  christos time the program is compiled and the time it is run.<br>
    810  1.1  christos <br>
    811  1.1  christos Therefore what could you do to get accented characters to work?<br>
    812  1.1  christos <br>
    813  1.1  christos Can you ensure that the execution character set is the same as the
    814  1.1  christos compilation character set? Even if your program is to be used only in a
    815  1.1  christos single country, this is not realistically possible. For example, in
    816  1.1  christos Germany there are currently three character encodings in use: UTF-8,
    817  1.1  christos ISO-8859-15 and ISO-8859-1. Therefore you would have to explicitly
    818  1.1  christos convert the accented strings from the compilation character set to the
    819  1.1  christos execution character set at runtime, for example through iconv().<br>
    820  1.1  christos <br>
    821  1.1  christos Can you ensure that the compilation character set is the one in which
    822  1.1  christos your source files are stored? This is not realistically possible
    823  1.1  christos either: For compilers other than GCC, there is no way to specify the
    824  1.1  christos compilation character set. So let's assume for a moment that everyone
    825  1.1  christos uses GCC; then you will specify the LC_CTYPE or LC_ALL environment
    826  1.1  christos variable in the Makefile. But for this you have to assume that everyone
    827  1.1  christos has a locale in a given encoding. Be it UTF-8 or ISO-8859-1 - this is
    828  1.1  christos not realistic. People often have no locale installed besides the one
    829  1.1  christos they use.<br>
    830  1.1  christos <br>
    831  1.1  christos Use of wide strings <span style="font-family: monospace;">L"..."</span>
    832  1.1  christos doesn't help solving the problem, because on systems like FreeBSD or
    833  1.1  christos Solaris, the way how wide string literals are stored in compiled code
    834  1.1  christos depends on the compilation&nbsp; character set, just as it does for
    835  1.1  christos narrow strings <span style="font-family: monospace;">"..."</span>.
    836  1.1  christos Moreover, wide strings have problems of their own.<br>
    837  1.1  christos <br>
    838  1.1  christos Use of ISO C 99 Unicode escapes "\u<span style="font-style: italic;">xxxx</span>"
    839  1.1  christos doesn't help either because these characters are converted to the
    840  1.1  christos compilation character set at compile time; so again, since you can't
    841  1.1  christos guarantee that the compilation character set is not ASCII, you're
    842  1.1  christos risking compilation errors just as if the real character had been used
    843  1.1  christos in the source instead of the Unicode escape.<br>
    844  1.1  christos <br>
    845  1.1  christos So, in summary, there is no way to make accented characters in string
    846  1.1  christos literals work in C/C++.<br>
    847  1.1  christos <br>
    848  1.1  christos You might then wonder what <span style="font-family: monospace;">xgettext</span>'s
    849  1.1  christos <span style="font-family: monospace;">--from-code</span> option is good
    850  1.1  christos for. The answer is<br>
    851  1.1  christos <ol>
    852  1.1  christos   <li>For the comments in C/C++ source code. The compiler ignores them.<br>
    853  1.1  christos   </li>
    854  1.1  christos   <li>For other programming languages like Java, for which the compiler
    855  1.1  christos converts all string literals to UTF-8.</li>
    856  1.1  christos </ol>
    857  1.1  christos <br>
    858  1.1  christos <hr style="width: 100%; height: 2px;">
    859  1.1  christos <address>GNU gettext FAQ<br>
    860  1.1  christos Bruno Haible &lt;<a href="mailto:bruno (a] clisp.org">bruno (a] clisp.org</a>&gt;</address>
    861  1.1  christos <p>Last modified: 24 February 2004
    862  1.1  christos </p>
    863  1.1  christos </body>
    864  1.1  christos </html>
    865