[Top][All Lists]

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

Re: Question: Why does 'es' fail when 'es_ES' works fine?

From: Bruno Haible
Subject: Re: Question: Why does 'es' fail when 'es_ES' works fine?
Date: Fri, 10 Sep 2004 13:22:07 +0200
User-agent: KMail/1.5

Dan Libby wrote:
> My problem is that gettext() is not returning the translated strings
> when a two letter ISO 639 language code is used (via setlocale() or
> 'LANG', "LANGUAGE', etc environment variables).  Yet it does work when I
> pass the language code plus country code.

This is explained in the ABOUT-NLS file of GNU gettext:

   Using This Package

   As a user, if your language has been installed for this package, you
   only have to set the `LANG' environment variable to the appropriate
   `LL_CC' combination.  Here `LL' is an ISO 639 two-letter language code,
   and `CC' is an ISO 3166 two-letter country code.  For example, let's
   suppose that you speak German and live in Germany.  At the shell
   prompt, merely execute `setenv LANG de_DE' (in `csh'),
   `export LANG; LANG=de_DE' (in `sh') or `export LANG=de_DE' (in `bash').
   This can be done from your `.login' or `.profile' file, once and for

      You might think that the country code specification is redundant.
   But in fact, some languages have dialects in different countries.  For
   example, `de_AT' is used for Austria, and `pt_BR' for Brazil.  The
   country code serves to distinguish the dialects.


      In the `LANGUAGE' environment variable, but not in the `LANG'
   environment variable, `LL_CC' combinations can be abbreviated as `LL'
   to denote the language's main dialect.  For example, `de' is equivalent
   to `de_DE' (German as spoken in Germany), and `pt' to `pt_PT'
   (Portuguese as spoken in Portugal) in this context.

> This is a problem for me because web browsers allow users to specify eg:
> 'en' or 'es' without specifying a country, and I use the
> HTTP_ACCEPT_LANGUAGE http header to switch among languages.  There is
> also a mechanism on the website for the user to override the browser
> setting, and again that does not ask for a country.  It is far more
> important that the languge be spanish and not english than that it be
> Costa Rican spanish and not Spanish spanish.

You could probably convert 'es' to 'es_ES' using the
locales_with_principal_territory table that you find in

> I have tried adding 'es' to my /usr/share/locales/locale.alias file,
> using the same value as 'spanish'.  However, that does not do anything.

On recent GNU systems, you need to "localedef --add-to-archive" after
changing the locale.alias file, to update the big locales archive.

> 1)  How can I make all the two letter language codes work as
> expected?

Convert "es" to "es_ES" yourself.

> 2) Out of curiosity, why does gettext care so much about locales?  Maybe
> I want to add a 'jive' or 'swedish chef' translation to my program.
> Does that mean I have to also create a locale definition for 'jive' and
> 'swedish chef' on each machine that my app gets installed to?

Yes, this is the case with the current gettext API.

The reason is that you might not only need translations, but also
sorting rules, time representation preferences, etc. - and for these
you need the locale as well.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]