Locale::getPrimaryLanguage
locale_get_primary_language
(No version information available, might be only in CVS)
locale_get_primary_language — Gets the primary language for the input locale
Описание
Object oriented style
static
string
Locale::getPrimaryLanguage
( string $locale
)
Procedural style
string
locale_get_primary_language
( string $locale
)
Gets the primary language for the input locale
Список параметров
- locale
-
The locale to extract the primary language code from
Возвращаемые значения
The language code associated with the language or NULL in case of error.
Примеры
Пример #1 locale_get_primary_language() example
<?php
echo locale_get_primary_language('zh-Hant');
?>
Пример #2 OO example
<?php
echo Locale::getPrimaryLanguage('zh-Hant');
?>
Результат выполнения данного примера:
zh
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Поддержка языков и кодировок
- Internationalization Functions
- Функция Locale::acceptFromHttp() - Tries to find out best available locale based on HTTP "Accept-Language" header
- Функция Locale::canonicalize() - Canonicalize the locale string
- Функция Locale::composeLocale() - Returns a correctly ordered and delimited locale ID
- Функция Locale::filterMatches() - Checks if a language tag filter matches with locale
- Функция Locale::getAllVariants() - Gets the variants for the input locale
- Функция Locale::getDefault() - Gets the default locale value from the INTL global 'default_locale'
- Функция Locale::getDisplayLanguage() - Returns an appropriately localized display name for language of the inputlocale
- Функция Locale::getDisplayName() - Returns an appropriately localized display name for the input locale
- Функция Locale::getDisplayRegion() - Returns an appropriately localized display name for region of the input locale
- Функция Locale::getDisplayScript() - Returns an appropriately localized display name for script of the input locale
- Функция Locale::getDisplayVariant() - Returns an appropriately localized display name for variants of the input locale
- Функция Locale::getKeywords() - Gets the keywords for the input locale
- Функция Locale::getPrimaryLanguage() - Gets the primary language for the input locale
- Функция Locale::getRegion() - Gets the region for the input locale
- Функция Locale::getScript() - Gets the script for the input locale
- Функция Locale::lookup() - Searches the language tag list for the best match to the language
- Функция Locale::parseLocale() - Returns a key-value array of locale ID subtag elements.
- Функция Locale::setDefault() - sets the default runtime locale
Коментарии
The behaviour when a falsy value is passed as the $locale is undocumented, but it appears that it returns the primary language of the default system language. In my case:
Locale::getPrimaryLanguage(null);
Returns 'en'. So make sure to test $locale before passing it to the method.