To facilitate translation of messages into various languages and to make them available to a program based on a user's locale, it is necessary to keep messages separate from the program and provide them in the form of message catalogs that a program can access at run time. To aid in this task, commands and subroutines are provided by the Message Facility. Message source files containing application messages are created by the programmer and converted to message catalogs. These catalogs are used by the application to retrieve and display messages, as needed. Message source files can be translated into other languages and converted to message catalogs without changing and recompiling a program.
The Message Facility includes the following two commands for displaying messages with a shell script or from the command line:
dspcat | Displays all or part of a message catalog. | |
dspmsg | Displays a selected message from a message catalog. |
These commands use the NLSPATH environment variable to locate the specified message catalog. The NLSPATH environment variable lists the directories containing message catalogs. These directories are searched in the order in which they are listed. For example:
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/prime/%N
The %L and %N special variables are defined as follows:
%L | Specifies the locale-specific directory containing message catalogs. The value of the LC_MESSAGES category or the LANG environment variable is used for the directory name. The LANG, LC_ALL, or LC_MESSAGES environment variable can be set by the user to the locale for message catalogs. |
%N | Specifies the name of the catalog to be opened. |
If the dspcat command cannot find the message, the default message is displayed. You must enclose the default message in single-quotation marks if the default message contains %n$ format strings. If the dspcat command cannot find the message and you do not specify a default message, a system-generated error message is displayed.
The following example uses the dspcat command to display all messages in the existing msgerrs.cat message catalog:
/usr/lib/nls/msg/$LANG/msgerrs.cat: dspcat msgerrs.cat
The following output is displayed:
1:1 Cannot open message catalog %s Maximum number of catalogs already open 1:2 File %s not executable 2:1 Message %d, Set %d not found
By displaying the contents of the message catalog in this manner, you can find the message ID numbers assigned to the msgerrs message source file by the mkcatdefs command to replace the symbolic identifiers. Symbolic identifiers are not readily usable as references for the dspmsg command, but using the dspcat command as shown can give you the necessary ID numbers.
The following is a simple shell script called runtest that shows how to use the dspmsg command:
if [ - x ./test ] ./test; else dspmsg msgerrs.cat -s 1 2 '%s NOT EXECUTABLE \n' "test"; exit;
Note: If you do not use a full path name, as in the preceding examples, be careful to set the NLSPATH environment variable so that the dspcat command searches the proper directory for the catalog. The LC_MESSAGES category or the value of the LANG environment variable also affects the directory search path.