Locale::gettext - message handling functions
use Locale::gettext;
use POSIX; # Needed for setlocale()
setlocale(LC_MESSAGES, "");
# OO interface
my $d = Locale::gettext->domain("my_program");
print $d->get("Welcome to my program"), "\n";
# (printed in the local language)
# Direct access to C functions
textdomain("my_program");
print gettext("Welcome to my program"), "\n";
# (printed in the local language)
gettext(), dgettext(), and dcgettext() attempt to retrieve a string matching their "msgid" parameter within the context of the current locale. dcgettext() takes the message's category and the text domain as parameters while dgettext() defaults to the LC_MESSAGES category and gettext() defaults to LC_MESSAGES and uses the current text domain. If the string is not found in the database, then "msgid" is returned.
ngettext(), dngettext(), and dcngettext() function similarily but implement differentiation of messages between singular and plural. See the documentation for the corresponding C functions for details.
textdomain() sets the current text domain and returns the previously active domain.
bindtextdomain(domain, dirname) instructs the retrieval functions to look for the databases belonging to domain "domain" in the directory "dirname"
bind_textdomain_codeset(domain, codeset) instructs the retrieval functions to translate the returned messages to the character encoding given by codeset if the encoding of the message catalog is known.
Perl programs should use the object interface. In addition to being able to return native Perl wide character strings, "bind_textdomain_codeset" will be emulated if the C library does not provide it.
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |