gettxt(3C) — C LIBRARY FUNCTIONS
NAME
gettxt − retrieve a text string
SYNOPSIS
char ∗gettxt(char ∗msgid, char ∗dflt_str);
DESCRIPTION
The routine gettxt() retrieves a text string from a message file. The arguments to the function are a message identification msgid and a default string dflt_str to be used if the retrieval fails.
The text strings are in files created by mkmsgs [see mkmsgs(1)] and installed in
/usr/lib/locale/locale/LC_MESSAGES
directories.
The directory locale can be viewed as the language in which the text strings are written. The user can request that messages be displayed in a specific language by setting the environment variable LC_MESSAGES. If LC_MESSAGES is not set the environment variable LANG will be used.
If LANG is not set, the locale in which the strings will be retrieved is the C locale and the files containing the strings are in
/usr/lib/locale/C/LC_MESSAGES/∗.
The user can also change the language in which the messages are displayed by invoking the setlocale() [see setlocale(3C)] function with the appropriate arguments.
If gettxt() fails to access the message in a specific locale, it will try to retrieve the same message in the C locale. Upon failure, the processing depends on what the second argument, dflt_str, points to. A pointer to the second argument is returned if the second argument is not the null strings. If dflt_str points to the null string, a pointer to the C locale text string
"Message not found!!\n"
is returned. A pointer to the same string is also returned if the message number is out of range.
The following depicts the acceptable syntax of msgid for a call to gettxt():
<msgid> => <msgfilename>:<msgnumber>
The first argument consists of two fields separated by a colon. The first field is used to indicate the file that contains the text strings and must be limited to 14 characters. These characters must be selected from a set of all character values excluding \0 (null) and the ASCII code for / (slash) and : (colon). The names of message files must be the same as the names of files created by mkmsgs() and installed in /usr/lib/locale/locale/LC_MESSAGES/∗. If no file name is specified, gettxt() will use the name specified with setcat(). If neither a file name nor a default catalog is specified, gettxt() returns a pointer to the text string
"Message not found!!\n".
The numeric field indicates the sequence number of the string in the file. The strings are numbered from 1. If the numeric field is greater than the number of strings in the file, gettxt() will use the defaulting sequence described above.
Upon failure to pass the correct argument to gettxt(), a pointer to the text string
"Message not found!!\n"
is returned.
FILES
/usr/lib/locale/C/LC_MESSAGES/∗ Default message files created by mkmsgs()
/usr/lib/locale/locale/LC_MESSAGES/∗ message files for different languages created by mkmsgs()
EXAMPLE
In the following code fragment:
gettxt("test:10", "hello world\n")
gettxt("test:10", "")
setcat("test");
gettxt(":10", "hello world\n")
test is the name of the file that contains the messages; 10 is the message number.
SEE ALSO
environ(5), gettxt(1), mkmsgs(1), setcat(3C), setlocale(3C), srchtxt(1).
— C Programming Language Utilities