There are several ways to access the locale information. The simplest way is to let the C library itself do the work. Several of the functions in this library access implicitly the locale data and use what information is available in the currently selected locale. This is how the locale model is meant to work normally.
As an example take the strftime
function which is meant to nicely
format date and time information (see section Formatting Date and Time).
Part of the standard information contained in the LC_TIME
category are, e.g., the names of the months. Instead of requiring the
programmer to take care of providing the translations the
strftime
function does this all by itself. When using %A
in the format string this will be replaced by the appropriate weekday
name of the locale currently selected for LC_TIME
. This is the
easy part and wherever possible functions do things automatically as in
this case.
But there are quite often situations when there is simply no functions
to perform the task or it is simply not possible to do the work
automatically. For these cases it is necessary to access the
information in the locale directly. To do this the C library provides
two functions: localeconv
and nl_langinfo
. The former is
part of ISO C and therefore portable, but has a brain-damaged
interface. The second is part of the Unix interface and is portable in
as far as the system follows the Unix standards.
Go to the first, previous, next, last section, table of contents.