LOCALES
Table of Contents
Functions
- get_core_message() : string
- Translate a message from a domain
- get_message() : string
- Translate a message from a domain
- translate_message() : string
- Translate a message from a domain
- dateFormatFromString() : string
- Format dates and times for localization in numeric short format
- dateFormatFromTimeStamp() : string
- Format dates and times for localization in numeric short format
- codeISO639a1toName() : string
- Return the name of a language defined by its locale code or its ISO 639-1 (alpha-2) code.
- set_locales() : void
- Set the default locale of Intl library with the user's preferred locale
- load_locales() : array<string|int, mixed>
- Load the translation catalogs of the user's preferred language.
- determine_locale() : string
- Determine the user's preferred language.
- determine_locale_priority_stack() : array<string|int, string>
- Determine the user's preferred language.
- getAllLocales() : array<string|int, string>
- Return a selected list of all locales recognised by Intl and usable for translation and formatting
- localetoBCP47() : string
- Return the BCP 47 code that matches the code of a locale.
- getTranslatableLocales() : array<string|int, string>
- Get a list of translatable locales sorted by locale name
- searchLanguageCode() : string
- Return the language code matching a language name
- sort() : bool
- Sort an array according to the current Intl locale in ascending order
- asort() : bool
- Sort an array according to the current Intl locale in ascending order and maintain index association
- ksort() : bool
- Sort an array according to the current Intl locale in ascending order and maintain index association
- rsort() : bool
- Sort an array according to the current Intl locale in descending order
- arsort() : bool
- Sort an array according to the current Intl locale in descending order and maintain index association
- krsort() : bool
- Sort an array according to the current Intl locale in descending order and maintain index association
- messageTranslatorNeeded() : string
- Return a message if the project need translation contribution for the current locale
Functions
get_core_message()
Translate a message from a domain
get_core_message(string $sectionKey, string $messageKey[, mixed $messageParam = "" ]) : string
This function is mimicking dgettext().
Parameters
- $sectionKey : string
-
Section key of the catalog
- $messageKey : string
-
Message key of the catalog
- $messageParam : mixed = ""
-
Optional array or single value that replaces '###' in the message. Default is ""
Tags
Return values
stringget_message()
Translate a message from a domain
get_message(string $domain, string $sectionKey, string $messageKey[, mixed $messageParam = "" ]) : string
This function is mimicking dgettext().
Parameters
- $domain : string
-
Catalog domain name
- $sectionKey : string
-
Section key of the catalog
- $messageKey : string
-
Message key of the catalog
- $messageParam : mixed = ""
-
Optional array or single value that replaces '###' in the message. Default is ""
Tags
Return values
stringtranslate_message()
Translate a message from a domain
translate_message(string $domain, string $message) : string
This function is mimicking dgettext().
Parameters
- $domain : string
-
Catalog domain name
- $message : string
-
Message to translate
Tags
Return values
stringdateFormatFromString()
Format dates and times for localization in numeric short format
dateFormatFromString(string $datetime) : string
Use it for displaying data to the user, not formatting data for the db.
If $datetime is not parseable then its value is returned unformated.
If IntlDateFormatter instanciation fails then the date is formated with "Y-M-d H:i:s" pattern.
Parameters
- $datetime : string
-
comes in from the database in the format 'YYYY-MM-DD HH:MM:SS' e.g. 2013-01-31 15:54:55
Return values
stringdateFormatFromTimeStamp()
Format dates and times for localization in numeric short format
dateFormatFromTimeStamp(int $timestamp) : string
Use it for displaying data to the user, not formatting data for the db.
If IntlDateFormatter instanciation fails then the date is formated with "Y-M-d H:i:s" pattern.
Parameters
- $timestamp : int
Return values
stringcodeISO639a1toName()
Return the name of a language defined by its locale code or its ISO 639-1 (alpha-2) code.
codeISO639a1toName(string $codeISO) : string
Parameters
- $codeISO : string
Tags
Return values
stringset_locales()
Set the default locale of Intl library with the user's preferred locale
set_locales() : void
load_locales()
Load the translation catalogs of the user's preferred language.
load_locales(string $domain, string $locale) : array<string|int, mixed>
Parameters
- $domain : string
- $locale : string
Return values
array<string|int, mixed>determine_locale()
Determine the user's preferred language.
determine_locale([string|null $force_locale = NULL ]) : string
This function builds a language priority stack and return the first entry as the user's preferred language.
If $force_locale is passed, this function will try to use this locale first.
Parameters
- $force_locale : string|null = NULL
-
Code of a locale (format: ll[_Script][_CC])(optional, NULL by default)
Return values
stringdetermine_locale_priority_stack()
Determine the user's preferred language.
determine_locale_priority_stack([string|null $force_locale = NULL ]) : array<string|int, string>
This function builds a language priority stack. The first is the highest priority.
If $force_locale is passed, this function will try to use this locale first.
Parameters
- $force_locale : string|null = NULL
-
Code of a locale (format: ll[_Script][_CC])(optional, NULL by default)
Return values
array<string|int, string>getAllLocales()
Return a selected list of all locales recognised by Intl and usable for translation and formatting
getAllLocales([bool $sorted_by_key = FALSE ]) : array<string|int, string>
Each entry of the returned array is locale code (format: ll[_Script][_CC]) as key and its name as value [format: language (Country, Variant)].
ll is a mandatory language code CC is an optional country code variant is an optional script, money or collation code
Parameters
- $sorted_by_key : bool = FALSE
-
If TRUE, sort the table by keys instead of values
Tags
Return values
array<string|int, string>localetoBCP47()
Return the BCP 47 code that matches the code of a locale.
localetoBCP47(string $locale) : string
The BCP 47 code is used in the lang attribute of any HTML tag. The list of supported languages is simple enough to avoid having to encounter any particular case.
Parameters
- $locale : string
-
Code of a locale (format: ll[_Script][_CC])
Tags
Return values
string —If a BCP47 code is missing, return 'en'
getTranslatableLocales()
Get a list of translatable locales sorted by locale name
getTranslatableLocales(string $in_locale) : array<string|int, string>
This is a list of locales that a translator can use to translate a text, and not a list of locales currently available on the system.
Parameters
- $in_locale : string
-
Transalate locales names with local $in_locale
Return values
array<string|int, string> —Each key is a locale code and its value a displayname.
searchLanguageCode()
Return the language code matching a language name
searchLanguageCode(string $language_name) : string
If no language code matchs the name, return "".
NB: this function is slow and should not be used outside the upgrade code
Parameters
- $language_name : string
Return values
stringsort()
Sort an array according to the current Intl locale in ascending order
sort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of collator_sort() that works as sort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolasort()
Sort an array according to the current Intl locale in ascending order and maintain index association
asort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of collator_asort() that works as asort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolksort()
Sort an array according to the current Intl locale in ascending order and maintain index association
ksort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of Collator::compare() that works as ksort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolrsort()
Sort an array according to the current Intl locale in descending order
rsort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of Collator::compare() that works as rsort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolarsort()
Sort an array according to the current Intl locale in descending order and maintain index association
arsort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of Collator::compare() that works as arsort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolkrsort()
Sort an array according to the current Intl locale in descending order and maintain index association
krsort(array<string|int, mixed> &$array[, int $flags = Collator::SORT_REGULAR ]) : bool
This function is a wrapper of Collator::compare() that works as krsort().
If you really need more flexibility or the full power of an Unicode sort algo, use the original function.
Parameters
- $array : array<string|int, mixed>
-
Array of strings to sort.
- $flags : int = Collator::SORT_REGULAR
-
Optional sorting type, one of the following:
- Collator::SORT_REGULAR - compare items normally (don't change types)
- Collator::SORT_NUMERIC - compare items numerically
- Collator::SORT_STRING - compare items as strings Default sorting type is Collator::SORT_REGULAR. It is also used if an invalid flags value has been specified.
return bool TRUE on success, FALSE otherwise
Tags
Return values
boolmessageTranslatorNeeded()
Return a message if the project need translation contribution for the current locale
messageTranslatorNeeded() : string
return string