When NLS is not supported or disabled, the Ada library implements the NLS operations by using empty suitable stubs that skip the NLS transformation and emit the English default message.
The first step in using the NLS library is to call the
that handles the setup of
bindtextdomain to configure the
language according to the user’s locale. The program localized messages are
stored in a catalog file that is created by
msginit (1) and
msgfmt (1) tools.
In most cases catalog file are identified by a unique name that must be given
Initialize procedure (below, it will be
with Intl; ... PROG_NAME : constant String := "mytool"; ... Intl.Initialize (PROG_NAME, "/usr/share/locale");
To localize a message, the
"-" function is provided to encapsulate the call
to the gettext (3) method. If the message
is translated and the catalog contains it in the user’s language, it will be
gettext and the
"-" function returns the localized message.
with GNAT.IO; ... function "-" (Message : in String) return String is (Intl."-" (Message)); ... GNAT.IO.Put_Line (-("Hello world!"));
To build the message translation file (
PO files), a tool can be used to extract
from the source code the default messages. This process is
explained in the GNU gettext documentation.