Standard C Language Internationalization Programming
Messaging

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:

  1. Create a translated message catalog

  2. Use the message catalog from the program

The following are the standard C library functions related to message catalog:
------------------------------------------------------
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:

World Wide Navi regards the messages which do not have to be translated. This setting can be changed by the DB customizing functionality.

*** Message Catalog Details ***

The format of the .msg files is described below.

wwnavi_cat.msg
$ $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.

For example, run the program 'Test' according to the settings below.
export NLSPATH=./%L/%N

export LANG=en_US.UTF-8
./Test

export LANG=ja_JP.UTF-8
./Test
The 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 catalog   
Loading 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 messages
This process can be checked with 'catgets' externalization of the sample 'linux_catgets' in World Wide Navi.

Go to Internationalization Programming Top


Copyright (C) 2012 Kokusaika JP, Inc.
All rights reserved. No reproduction or republication without written permission.