![]() |
![]() ![]() ![]() |
'gettext()' is not a standard C language functionality but a widely-used message extracting mechanism. The basic idea is the same as the standard C language's message catalog but 'gettext()' uses the English message itself (or its transformed value) as the message id.
The following are the functions related to 'gettext()':
------------------------------------------------------------------------- Function Description ------------------------------------------------------------------------- gettext Gets a message dgettext Gets a message dcgettext Gets a message ngettext Gets a message dngettext Gets a message dcngettext Gets a message bindtextdomain Binds a message file with a domain textdomain Selects a domain bind_textdomain_codeset Sets a codeset of message _ Gets a message (macro) N_ Directs message extraction to a tool (macro) gettext_noop Directs message extraction to a tool (macro) -------------------------------------------------------------------------The last three are macros. Their definitions are as follows:
#define _(String) gettext(String) #define N_(String) gettext_noop(String) #define gettext_noop(String) (String)A text extracting tool searches for and extracts messages in these macro calls.
# $NLS-WWNAVI 2008-05-24T17:48:21+0900 msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2008-05-24T17:48:21+0900\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME\n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" <-- *Encoding name "Content-Transfer-Encoding: 8bit\n" # Test.c msgid "Failed to create fontset\n" <-- *Message ID msgstr "Failed to create fontset\n" <-- *Message msgid "Hello, how are you? This is sample for gettext. (Push .)" msgstr "Hello, how are you? This is sample for gettext. (Push .)"
msgfmt -o wwnavi_get.mo wwnavi_get.pot
setlocale (LC_ALL, ""); <-- *Described in the main function. bindtextdomain("wwnavi_get", ".");<-- *Described in the main function. textdomain("wwnavi_get");<-- *Described in the main function. ... printf(_(N_("Failed to create fontset\n"))); <-- *Loading message.
export LANG=en_US.UTF-8 ./Test export LANG=ja_JP.UTF-8 ./TestThe locations of the .mo files will be the following:
./en/LC_MESSAGES/wwnavi_get.mo <-- *English message file ./ja/LC_MESSAGES/wwnavi_get.mo <-- *Japanase message file
Go to Internationalization Programming Top