Using the message facility
To facilitate the translation of messages into various languages and to make them available to a program based on a users 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, the Message Facility provides commands and subroutines. 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.
Command | Description |
---|---|
dspcat | Displays all or part of a message catalog |
dspmsg | Displays a selected message from a message catalog |
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/prime/%N
%L
and %N
special variables
are defined as follows:
Special Variable | Description |
---|---|
%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.
msgerrs.cat
message
catalog:/usr/lib/nls/msg/$LANG/msgerrs.cat:
dspcat msgerrs.cat
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.
if [ - x ./test ]
./test;
else
dspmsg msgerrs.cat -s 1 2 '%s NOT EXECUTABLE \n' "test";
exit;