![]() |
![]() ![]() ![]() |
An international program should provide a user interface in the user's native language. Language C provides the message catalog, a mechanism to select messages dynamically depending on the current locale. You can use the message catalog as follows:
------------------------------------------------------ Function Description ------------------------------------------------------ catopen() Opens a message catalog catgets() Gets a message from a message catalog catclose() Closes a message catalog ------------------------------------------------------
Most string literals should be translated into a natural language but some string literals, such as pathnames, are common for all languages. A string literal may not have to be translated if it is an argument of a certain function. Generally speaking, you may not have to translate string literals such as the following:
$ $NLS-WWNAVI 2008-05-24T16:48:54+0900
$
$quote "
$set 1
1 "Failed to create fontset\n" <-- *Message ID and Message
2 "Hello, how are you? This is sample for catgets. (Push <enter>.)"
The locations
of the .cat files depend on the environment variable NLSPATH.
export NLSPATH=./%L/%N export LANG=en_US.UTF-8 ./Test export LANG=ja_JP.UTF-8 ./TestThe location of the .cat files will be the following:
./en_US.UTF-8/wwnavi_cat.cat <-- *English message catalog ./ja_JP.UTF-8/wwnavi_cat.cat <-- *Japanese message catalogLoading messages in the source codes is described below.
setlocale (LC_ALL, ""); <-- *Described in the main function nl_catd wwnavi_cd = catopen ("wwnavi_cat.cat", NL_CAT_LOCALE); <-- *Described in the main function ... printf(catgets(wwnavi_cd, 1, 1, "Failed to create fontset\n")); <-- *Loading messagesThis process can be checked with 'catgets' externalization of the sample 'linux_catgets' in World Wide Navi.
Go to Internationalization Programming Top