Textpattern PHP Cross Reference Content Management Systems

Summary: /textpattern/vendors/Textpattern/L10n/Locale.php - 407 lines - 16648 bytes - Source - Print

Description: Handles locales.

Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Locale:: (8 methods):
setLocale()
getLocale()
getLanguageLocale()
getLocaleLanguage()
getCharset()
getLanguage()
getLocaleIdentifiers()
validLocale()

Class: Locale


setLocale($category, $locale line: 155
Sets the locale.

This method wraps around system setlocale. It takes an IETF language code
and sets the locale accordingly.

The following would set the locale to English:

<code>
Txp::get('\Textpattern\L10n\Locale')->setLocale(LC_ALL, 'en-GB');
</code>

This would format currencies according to the French localisation:

<code>
Txp::get('\Textpattern\L10n\Locale')->setLocale(LC_MONETARY, 'fr-FR');
echo money_format('%i', 51.99);
</code>

The '51.99' would be returned as '51,99 EUR' if you have up to date
French locale installed on your system.

If an array of locales is provided, the first one that works is used.

return: Locale
param: int          $category The localisation category to change
param: string|array $locale   The language code
getLocale($category = LC_ALL)  line: 202
Gets the current locale.

<code>
echo Txp::get('\Textpattern\L10n\Locale')->getLocale(LC_ALL);
</code>

return: mixed
param: int $category The localisation category
getLanguageLocale($language line: 218
Gets a locale identifier for the given language code.

This method takes an IETF language code and returns a locale for it that
works on the current system.

The following returns 'en_GB.UTF-8':

<code>
echo Txp::get('\Textpattern\L10n\Locale')->getLanguageLocale('en-GB');
</code>

Returns the default locale name if the system doesn't have anything
more appropriate.

return: string|bool Locale code, or FALSE on error
param: string $language The language
getLocaleLanguage($locale line: 249
Gets a language code for the given locale identifier.

This method supports various different formats used by different host
platform. These formats include IETF language tag, POSIX locale name and
language name in English.

All these will return 'en-gb':

<code>
echo Txp::get('\Textpattern\L10n\Locale')->getLocaleLanguage('en_GB.UTF-8');
echo Txp::get('\Textpattern\L10n\Locale')->getLocaleLanguage('en-gb');
echo Txp::get('\Textpattern\L10n\Locale')->getLocaleLanguage('english');
echo Txp::get('\Textpattern\L10n\Locale')->getLocaleLanguage('c');
echo Txp::get('\Textpattern\L10n\Locale')->getLocaleLanguage('English_UK.1252');
</code>

If the specified locale isn't supported, FALSE will be returned.

return: string|bool The language code, or FALSE on failure
param: string $locale The locale identifier
getCharset($category = LC_ALL, $default = false)  line: 289
Gets the character set from the current locale.

This method exports the character set from the current locale string as
returned by the OS.

<code>
echo Txp::get('\Textpattern\L10n\Locale')->getCharset();
</code>

return: string|bool The character set, or FALSE on failure
param: int $category The localisation category
getLanguage($category = LC_ALL)  line: 323
Gets the language from the current locale.

<code>
echo Txp::get('\Textpattern\L10n\Locale')->getLanguage();
</code>

return: string|bool The language code, or FALSE on failure
param: int $category The localisation category
getLocaleIdentifiers($locale line: 345
Gets locale identifiers mapped to the given language.

Returns all locale identifiers that match the given language or locale
code. For instance providing 'en', will return both en-US and en-GB
locale identifiers.

<code>
print_r(Txp::get('\Textpattern\L10n\Locale')->getLocaleIdentifiers('english'));
print_r(Txp::get('\Textpattern\L10n\Locale')->getLocaleIdentifiers('en'));
print_r(Txp::get('\Textpattern\L10n\Locale')->getLocaleIdentifiers('en-gb'));
</code>

return: array|bool An array of identifiers, or FALSE if not supported
param: string $locale The locale or language code
validLocale($code line: 384
Return valid locale, if possible.

title

Body