GNU gettext utilities: Charset conversion
Next: Contexts, Previous: Locating Catalogs, Up: gettext [Contents][Index]
11.2.4 How to specify the output character set gettext uses
gettext
not only looks up a translation in a message catalog. It also converts the translation on the fly to the desired output character set. This is useful if the user is working in a different character set than the translator who created the message catalog, because it avoids distributing variants of message catalogs which differ only in the character set.
The output character set is, by default, the value of nl_langinfo (CODESET)
, which depends on the LC_CTYPE
part of the current locale. But programs which store strings in a locale independent way (e.g. UTF-8) can request that gettext
and related functions return the translations in that encoding, by use of the bind_textdomain_codeset
function.
Note that the msgid
argument to gettext
is not subject to character set conversion. Also, when gettext
does not find a translation for msgid
, it returns msgid
unchanged – independently of the current output character set. It is therefore recommended that all msgid
s be US-ASCII strings.
- Function: char * bind_textdomain_codeset (const char *domainname, const char *codeset)
The
bind_textdomain_codeset
function can be used to specify the output character set for message catalogs for domaindomainname
. Thecodeset
argument must be a valid codeset name which can be used for theiconv_open
function, or a null pointer.If the
codeset
parameter is the null pointer,bind_textdomain_codeset
returns the currently selected codeset for the domain with the namedomainname
. It returnsNULL
if no codeset has yet been selected.The
bind_textdomain_codeset
function can be used several times. If used multiple times with the samedomainname
argument, the later call overrides the settings made by the earlier one.The
bind_textdomain_codeset
function returns a pointer to a string containing the name of the selected codeset. The string is allocated internally in the function and must not be changed by the user. If the system went out of core during the execution ofbind_textdomain_codeset
, the return value isNULL
and the global variableerrno
is set accordingly.
Next: Contexts, Previous: Locating Catalogs, Up: gettext [Contents][Index]