[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] Re: context menu

Carsten Haitzler (The Rasterman) <raster@rasterman.com> writes:

> there's no documented call though to tell gettext to "flush your
> mush" :(

I found this in the Gettext info pages, so for GNU Gettext there is a
way to make it change language at runtime:

10.5 Being a `gettext' grok

To fully exploit the functionality of the GNU `gettext' library it is
surely helpful to read the source code.  But for those who don't want
to spend that much time in reading the (sometimes complicated) code
here is a list comments:

   * Changing the language at runtime 

     For interactive programs it might be useful to offer a selection
     of the used language at runtime.  To understand how to do this
     one need to know how the used language is determined while
     executing the `gettext' function.  The method which is presented
     here only works correctly with the GNU implementation of the
     `gettext' functions.

     In the function `dcgettext' at every call the current setting of
     the highest priority environment variable is determined and used.
     Highest priority means here the following list with decreasing

       1. `LANGUAGE' 

       2. `LC_ALL' 

       3. `LC_xxx', according to selected locale 

       4. `LANG'

     Afterwards the path is constructed using the found value and the
     translation file is loaded if available.

     What happens now when the value for, say, `LANGUAGE' changes?
     According to the process explained above the new value of this
     variable is found as soon as the `dcgettext' function is called.
     But this also means the (perhaps) different message catalog file
     is loaded.  In other words: the used language is changed.

     But there is one little hook.  The code for gcc-2.7.0 and up
     provides some optimization.  This optimization normally prevents
     the calling of the `dcgettext' function as long as no new catalog
     is loaded.  But if `dcgettext' is not called the program also
     cannot find the `LANGUAGE' variable be changed (*note Optimized
     gettext::).  A solution for this is very easy.  Include the
     following code in the language switching function.

            /* Change language.  */
            setenv ("LANGUAGE", "fr", 1);

            /* Make change known.  */
              extern int  _nl_msg_cat_cntr;

     The variable `_nl_msg_cat_cntr' is defined in `loadmsgcat.c'.
     You don't need to know what this is for.  But it can be used to
     detect whether a `gettext' implementation is GNU gettext and not
     non-GNU system's native gettext implementation.

Martin Geisler                                     GnuPG Key: 0x7E45DD38

PHP Exif Library      |  PHP Weather             |  PHP Shell
http://pel.sf.net/    |  http://phpweather.net/  |  http://mgeisler.net/
Read/write Exif data  |  Show current weather    |  A shell in a browser

Attachment: pgpTAWEdxs3OK.pgp
Description: PGP signature