Here's how gettext works.

1. In a C or C++ program, the text strings that need to be translated are encoded as, for example gettext("Hello World").

2. Then use xgettext.exe to scan the source file and extract the strings into a .pot file, a template file to be used for translation work.

An example pot file looks like this:
Code:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2003-12-20 11:56+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"

#: sample.c:63
msgid "Hello World"
msgstr ""

#: sample.c:63
msgid "This is english ( default )"
msgstr ""


So the string "Hello World" is now a msgid.

3. Then copy sample.pot to say fr.po and some person has to do the actual translation work.

Example for fr.po
Code:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Free Software Foundation, Inc.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 1999-07-19 11:15+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"

#: sample.cpp:23
msgid "This is english ( default )"
msgstr "c'est franais (fr)"

#: sample.cpp:24
msgid "Hello World"
msgstr "bonjour"


4. Then use msgfmt.exe to compile .po to binary file .mo
msgfmt -o fr.mo fr.po

5. Finally copy .mo file into directory for each language,
for example:
\fr\LC_MESSAGES.

6. So there can be many languages, each with its own directory for LC_MESSAGES with its own .mo. There can be many .mo files, perhaps for many different programs, each with its own .mo file.

7. In code, at any time, to switch language the api to call is:
call 'gnu_gettext.gettext_putenv' French
where French is [French: B$ "LANGUAGE=fr",0]

The gettext dll will then load the .mo file for that language. So only changing the text string in the program will not work. You still need to generate the .pot file, thenthe .po file and compile it to .mo binary file.

Since xgettext.exe scans for strings in a pre-defined way, we can put strings like this, example:
; gettext("Hello World") gettext("This is english ( default )")

Note the comment ";". xgettext will be able to scan a .asm file to produce a .pot file.

Gettext is an interesting way to build multi-lingual programs. I will continue to explore it deeper whenever I have the time.

Best Regards,
Yeoh
--