bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: LC_CTYPE implementation help


From: Bruno Haible
Subject: Re: LC_CTYPE implementation help
Date: Wed, 27 Aug 2008 12:03:07 +0200
User-agent: KMail/1.5.4

Hi,

Aragon Gouveia wrote:
> I am having difficulty understanding how an application can or should
> implement gettext's LC_CTYPE category.
> 
> Specifically my questions are:
> 
> * how and where does a translator define the character types for a locale?
> * how do functions like isalnum() hook into gettext to resolve whether
> or not a character falls within the alnum ctype for the chosen locale?

Character types and isalnum() implementations are part of the locale.
This is a set of files, usually stored in /usr/lib/locale/ and used by the
libc at runtime. On glibc systems a localizing person can create new locales
by using the 'localedef' program. But this step is part of creating support
for a new language or territory in glibc, not the job that an average
translator does. Anyway, for reference about the glibc locale format:
  - http://people.debian.org/~barbier/talks/debconf5/glibc-locale_handout.pdf
  - look also at the existing locale files in /usr/share/i18n/locales/

gettext is not used to implement locales. Locales are not specified in PO files.

> * what does a programmer need to do to make sure ctype functions follow the
> locale?

At the beginning of the program he needs:

#include <locale.h>
setlocale (LC_ALL, "");

And be aware that the <ctype.h> functions are meaningless in multibyte locales
(that is, most of the locales in use today). Any time you are tempted to use
isalnum() or similar, ask yourself "what if the character is a multibyte
character?". Because "ä" and "ø" are multibyte characters, you cannot pass
them to isalnum(). - GNU gnulib contains a few modules for string manipulation,
see  http://www.gnu.org/software/gnulib/MODULES.html#module=mbslen

Bruno





reply via email to

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