LanguageUtil¶
A singleton utility class to query the language data.
Qualified name: | Wikimedia\LanguageData\LanguageUtil |
---|
-
class
LanguageUtil
¶ -
addLanguage
(string $languageCode, array $options)¶ Adds a language in run time and sets its options as provided. If the target option is provided, the language is defined as a redirect. Other possible options are script (string), regions (array) and autonym (string).
Parameters: - $languageCode (string) – New language code.
- $options (array) – Language properties.
-
getAutonym
(string $languageCode)¶ Returns the autonym of the language
Parameters: - $languageCode (string) – Language code
Returns: string|bool Autonym of the language or false if the language is unknown
-
getAutonyms
() → array¶ Returns all language codes and corresponding autonyms
Returns: array – The key is the language code, and the values are corresponding autonym
-
getDir
(string $languageCode)¶ Return the direction of the language
Parameters: - $languageCode (string) – Language code
Returns: string|bool Returns ‘rtl’ or ‘ltr’. If the language code is unknown, returns false.
-
getGroupOfScript
(string $script) → string¶ Returns the script group of a script or “Other” if it doesn’t belong to any group
Parameters: - $script (string) – Name of the script
Returns: string – Script group name or “Other” if the script doesn’t belong to any group
-
getLanguages
()¶ Get all the languages. The properties in the returned object are ISO 639 language codes The value of each property is an array that has, [writing system code, [regions list], autonym]
Returns: stdClass
-
getLanguagesByScriptGroup
(array $languageCodes) → array¶ Return the list of languages passed, grouped by their script group
Parameters: - $languageCodes (array) – List of language codes to group
Returns: array – List of language codes grouped by script group
-
getLanguagesByScriptGroupInRegion
(string $region) → LanguageUtil::getLanguagesByScriptGroupInRegions¶ Returns an associative array of languages in a region, grouped by their script
Parameters: - $region (string) – Region code
Returns:
-
getLanguagesByScriptGroupInRegions
(array $regions) → array¶ Returns an associative array of languages in several regions, grouped by script group
Parameters: - $regions (array) – List of strings representing region codes
Returns: array – Returns an associative array. They key is the script group name, and the value is a list of language codes in that region.
-
getLanguagesInScript
(string $script) → array¶ Returns all languages written in the given script
Parameters: - $script (string) – Name of the script
Returns: array –
-
getLanguagesInScripts
(array $scripts) → array¶ Returns all languages written in the given scripts
Parameters: - $scripts (array) – List of strings, each being the name of a script
Returns: array –
-
getLanguagesInTerritory
(string $territory)¶ Returns the languages spoken in a territory
Parameters: - $territory (string) – Territory code
Returns: array|bool List of language codes in the territory, or else false if invalid territory is passed
-
getRegions
(string $languageCode)¶ Returns the regions in which a language is spoken
Parameters: - $languageCode (string) – Language code
Returns: array|bool List of regions or false if language is unknown
-
getScript
(string $languageCode)¶ Returns the script of the language
Parameters: - $languageCode (string) – Language code
Returns: string|bool Language script or false if the language is unknown
-
getScriptGroupOfLanguage
(string $languageCode) → string¶ Returns the script group of a language. Language belongs to a script, and the script belongs to a script group
Parameters: - $languageCode (string) – Language code
Returns: string – script group name
-
isKnown
(string $languageCode) → bool¶ Checks if a language code is valid
Parameters: - $languageCode (string) – Language code
Returns: bool –
-
isRedirect
(string $languageCode)¶ Checks if the language is a redirect and returns the target language code
Parameters: - $languageCode (string) – Language code
Returns: string|bool Target language code if it’s a redirect or false if it’s not
-
isRtl
(string $languageCode) → bool¶ Check if a language is right-to-left
Parameters: - $languageCode (string) – Language code
Returns: bool – true if it is an RTL language, else false. Returns false if an unknown language code is passed.
-
sortByAutonym
(array $languageCodes) → array¶ Sort languages by their autonym
Parameters: - $languageCodes (array) – List of language codes to sort
Returns: array – List of sorted language codes returned by their autonym
-
sortByScriptGroup
(array $languageCodes) → array¶ Return the list of languages sorted by their script groups
Parameters: - $languageCodes (array) – List of language codes to sort
Returns: array – Sorted list of strings containing language codes
-
static
get
→ self¶ Returns an instance of the class that can be used to then call the other methods in the class.
Returns: self –
-