Sympa::Language(3Sympa) | sympa 6.2.70 | Sympa::Language(3Sympa) |
Sympa::Language - Handling languages and locales
use Sympa::Language; my $language = Sympa::Language->instance; $language->set_lang('zh-TW', 'zh', 'en'); print $language->gettext('Lorem ipsum dolor sit amet.');
This package provides interfaces for i18n (internationalization) of Sympa.
The language tags are used to determine each language. A language tag consists of one or more subtags: language, script, region and variant. Below are some examples.
Other two sorts of identifiers are derived from language tags: gettext locales and POSIX locales.
The gettext locales determine each translation catalog. It consists of one to three parts: language, territory and modifier. For example, their equivalents of language tags above are "ar", "ain", "pt_BR", "be@latin" and "ca_ES@valencia", respectively.
The POSIX locales determine each locale. They have similar forms to gettext locales and are used by this package internally.
Manipulating language tags
Parameter:
Returns:
Canonicalized language tag. In array context, returns an array "(language, script, region, variant)". For malformed inputs, returns "undef" or empty array.
See "CAVEATS" about details on format.
Parameters:
Returns:
A list of implicated languages, if any. If no $lang arguments were given, this function will die.
Parameter:
Returns:
The gettext locale name. For malformed inputs returns "undef".
Parameters:
Returns:
The best language or, if negotiation failed, "undef".
Compatibility
As of Sympa 6.2b, language tags are used to specify languages along with locales. Earlier releases used POSIX locale names.
These functions are used to migrate data structures and configurations of earlier versions.
Parameter:
Returns:
Old-style "locale". If corresponding locale could not be determined, returns "undef".
Note: In earlier releases this function was named Lang2Locale() (don't confuse with "lang2locale"()).
Getting/setting language context
Parameter:
Returns:
Always 1.
Parameters:
None.
Returns:
Always 1.
Parameter:
Note that 'en' will always succeed. Thus, putting it at the end of argument list may be useful.
Returns:
Canonic language tag actually set or, if no usable catalogs were found, "undef". If no arguments are given, do nothing and returns "undef".
Note that the language actually set may not be identical to the parameter $lang, even when latter has been canonicalized.
The language tag 'en' is special: It is used to set 'C' locale and will succeed always.
Note: This function of Sympa 6.2a or earlier returned old style "locale" names.
Parameters:
None.
Returns:
Name of the language in native notation. If it was not found, returns an empty string ''.
Note: The name is the content of "Language-Team:" field in the header of catalog.
Parameters:
None.
Returns:
Current language. If it is not known, returns default language tag.
Native language support (NLS)
Parameter:
Returns:
Translated string or, if it wasn't found, original string.
Parameter:
Returns:
Translated string or, if it wasn't found, original string.
If special argument '_language_' is given, returns the name of language in native form (See native_name()). For argument '' returns empty string.
This is equivalent to "sprintf( gettext($format), $args, ... )" with appropriate POSIX locale if possible.
Parameters:
Returns:
Translated and formatted string.
If appropriate POSIX locale is not available, parts of result (names of days, months etc.) will be taken from the catalog.
Parameters:
Returns:
Translated and formatted string.
Numeric arguments will be formatted using appropriate locale, if any: Typically, the decimal point specific to each locale may be used.
Parameters:
Returns:
Translated and replaced string.
Note:
Calls of "gettext"(), "gettext_sprintf"() and "gettext_strftime"() are extracted during packaging process and are added to translation catalog.
RFC 5646 Tags for Identifying Languages. <http://tools.ietf.org/html/rfc5646>.
Translating Sympa. <https://translate.sympa.community/pages/help>.
Language module supporting multiple languages by single installation and using NLS catalog in msgcat format appeared on Sympa 3.0a.
Sympa 4.2b.3 adopted gettext portable object (PO) catalog and POSIX locale.
On Sympa 6.2, rewritten module Sympa::Language adopted BCP 47 language tag to determine language context, and installing POSIX locale became optional.
2023-01-26 | 6.2.70 |