The following code uses the message just created
in
``Creating a message catalog''.
Rather than hard-coding output directly,
it reads the proper message catalog
depending on the LANG
environment variable.
Example 3-3 Internationalized ``Hello, world'' program (hello.c)
Needs to be included to use standard routines like
printf(S).
line 2
Needs to be included to use time-related functions and data types.
line 3
Needs to be included to use the catalog routines.
lines 4-5
Needs to be included to use the
LC_*
and
LANG
environment variables.
line 6
Defines the maximum size of a temporary buffer.
line 9
Defines a variable to be of a type that
identifies a catalog (referred to as a
catalog descriptor).
line 10
Defines a variable to store the time.
line 11
Defines a temporary buffer of size TEMPBUF_SIZE
to store the formatted string corresponding to the time.
line 12
Needs to be included
so that the local environment
variable LANG is read.
line 13
Checks to see if a catalog with the
name argument
matching ``hello'' can be opened.
If successful, this message catalog will
now be referenced by the
catalog variable.
If the program is to use the
LC_MESSAGES environment variable,
use NL_CAT_LOCALE
as the second argument to the
catopen(S)
call instead of the 0 shown in the example.
lines 14-16
Prints out error message upon failure.
line 17
Sets the clock
variable to UNIX operating system
Epoch time.
lines 18-20
Formats the time according to the format
in the message catalog designated by the
variable catalog.
(The final format specification is a
default if there is an error in reading
the message catalog.)
lines 21-24
Retrieves message number 1 of set number 1
in the message catalog designated by the
variable catalog.
(The final string is a default if there is
an error in reading the message catalog.)
The retrieved message is printed and
followed by the preformatted time string
stored in tempbuffer.
line 25
Closes the message catalog identified by the
variable catalog.