PApp::I18n - internationalization support for PApp
use PApp::I18n; # nothing expoted by default
my $translator = PApp::I18n::open_translator("/libdir/i18n/myapp", "de"); my $table = $translator->get_table("uk,de,en"); # will return de translator print $table->gettext("yeah"); # better define __ and N_ functions
This module provides basic translation services, .po-reader and writer support and text and database scanners to identify tagged strings.
A ``language'' can be designated by either a free-form-string (that doesn't match the following formal definition) or a language-region code that must match the following regex:
/^ ([a-z][a-z][a-z]?) (?:[-_] ([a-z][a-z][a-z]?))? (?:\.(\S+))? $/ix ^ ^ ^ ^ "two or three letter code" "optionally followed by" "- or _ as seperator" "two or three letter code" "optionally followed by" ". as seperator" "character encoding"
There is no charset indicator, as only utf-8 is supported currently. The first part must be a two or three letter code from iso639-2/t (alpha2 or alpha3), optionally followed by the two or three letter country/region code from iso3166-1 and -2. Numeric region codes might be supported one day.
$path
. This must be done before any
calls to translate_langid
or when using relative i18n paths.
langid
into a description of itself and translate it
into the language specified by the second langid
(the latter does not
work yet). The output of this function also gets cached.
The charsets returned should be considered to be in priority order, i.e. the first charset is the best. The intention of this function is to provide a list of character sets to try when outputting html text (you can output any html text in any encoding supporting html's active characters, so this is indeed a matter of taste).
If the locale contains a character set it will be the first in the returned list. The other charsets are taken from a list (see the source of this module for details).
Here are some examples of what you might expect:
de => iso-8859-1 iso-8859-15 cp1252 utf-8 rus_ukr => koi8-u iso-8859-5 cp1251 iso-ir-111 cp866 koi8-r iso-8859-5 cp1251 iso-ir-111 cp866 koi8-u utf-8 ja_JP.UTF-8 => utf-8 euc-jp sjis iso-2022-jp jis7 utf-8
This function can be slow and does NOT cache any results.
get_table($languages)
$languages
. This function always succeeds by returning a dummy trable
if no (physical) table can be found. This function is very fast in the
general case.
gettext($msgid)
string => translation \{\string => \translation \{\{string => \{translation \{}string => translation
To ensure that the string is translated ``as is'' just prefix it with ``\{}''.
get_table
get the updated tables instead of already opened ones.
As of yet undocumented
$domain
in binary hash format to directory
$path
, creating it if necessary.
CLASS PApp::I18n::PO_Reader
This class can be used to read serially through a .po file. (where ``po file'' is about the same thing as a standard ``Portable Object'' file from the NLS standard developed by Uniforum).
CLASS PApp::I18n::PO_Writer
This class can be used to write a new .po file. (where ``po file'' is about the same thing as a standard ``Portable Object'' file from the NLS standard developed by Uniforum).
next
method.
Marc Lehmann <pcg@goof.com> http://www.goof.com/pcg/marc/