Re: language support

From: Roger Leigh (${roger}_at_invalid.whinlatter.uklinux.net.invalid)
Date: 10/09/04


Date: Sat, 09 Oct 2004 01:54:03 +0100

ask8y@yahoo.com (Ask) writes:

> I want to know how language support works in LInux.
> Let assume I wrote a program, working in English version Linux.

> Now I want port it inot a foreign language, say Chinese, and assume I
> know the language well enough, from programming prespective, what are
> steps I have to follow to get it ported?

You need to use gettext. This can be done roughly like so:

- Add gettext infrastructure (autoconf/automake bits)
- Add init code to your program or library initialisation routine
  to get the locale and load the message catalogues.
- Mark translatable strings in your source using _() and N_()
  and manually translate with gettext() where required.
- Run xgettext to pull out the translatable strings
- Translate the strings

The main part is translating stuff like this:

  printf("Processing foo: %d-%s\n", foo, bar);

to this:

  printf(_("Processing foo: %d-%s\n"), foo, bar);

This expands the string literal to gettext("Processing foo: %d-%s\n")
which returns the translated version of the string. It's pretty neat.
The _() is also used by xgettext to identify which strings need
translation.

> You might find dificult ot explain all to someone who does not know
> anything about it like, you could point me to some introduction
> material.

This is documented in the GNU gettext and GNU libc manuals. Lots of
programs use it, so there's a lot of example code out there. The
gettext manual has instructions for adding gettext support.

> Also is there a tool that helps this?

gettextize. Make a backup of your source tree before you run it--it
thinks it's too clever by half, and broke my carefully crafted
configure.ac and Makefile.ams. This should add the necessary
infrastructure, but do check exactly what it's done to correct any
damage.

-- 
Roger Leigh
                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.


Relevant Pages

  • Re: GNU gettext
    ... The gettext documentation explains how the keys work. ... translation files, or that you'd need to write a small utility to help ... gettext was desined for plain C, the keys are C strings ... as a developer you have no clue what every language ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RfD: XCHAR wordset
    ... to be translated from XHCARS to UTF-16 and back; ... And here you mean 127 xchars in a counted string. ... the short count is one of the disadvantages of counted strings. ... functions taking or returning UTF-16 strings, you have to translate ...
    (comp.lang.forth)
  • Re: Anyone interested in . . .
    ... If someone needs to translate characters, requiring the use of a wire ... what I was suggesting is that "mainly just text strings" ... (necessarily with an extra nibble of padding to fill up the last byte). ...
    (comp.sys.hp48)
  • Re: RfD: XCHAR wordset
    ... than with chars. ... And here you mean 127 xchars in a counted string. ... the short count is one of the disadvantages of counted strings. ... functions taking or returning UTF-16 strings, you have to translate ...
    (comp.lang.forth)
  • Re: python tr equivalent (non-ascii)
    ... What I want to do is translate fullwidth numbers and roman alphabet ... characters into their halfwidth ascii equivalents. ... 'ascii' codec can't encode characters in position ... maketrans only works for byte strings. ...
    (comp.lang.python)

Loading