mirror of
https://github.com/wiosna-dev/common-library.git
synced 2026-03-12 01:31:45 +01:00
Utilities - Locale - getLocale() method - returns locale for given category
This commit is contained in:
@@ -61,6 +61,27 @@ class Locale
|
||||
return setlocale($category, $localeLongForm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns locale for given category
|
||||
*
|
||||
* @param int $category Named constant specifying the category of the functions affected by the locale setting.
|
||||
* It's the same constant as required by setlocale() function.
|
||||
* @return string
|
||||
*
|
||||
* Available categories (values of $category argument):
|
||||
* - LC_ALL for all of the below
|
||||
* - LC_COLLATE for string comparison, see strcoll()
|
||||
* - LC_CTYPE for character classification and conversion, for example strtoupper()
|
||||
* - LC_MONETARY for localeconv()
|
||||
* - LC_NUMERIC for decimal separator (See also localeconv())
|
||||
* - LC_TIME for date and time formatting with strftime()
|
||||
* - LC_MESSAGES for system responses (available if PHP was compiled with libintl)
|
||||
*/
|
||||
public static function getLocale($category)
|
||||
{
|
||||
return setlocale($category, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns long form of the locale
|
||||
*
|
||||
|
||||
@@ -75,6 +75,21 @@ class LocaleTest extends BaseTestCase
|
||||
self::assertEquals($expectedLocale, Locale::setLocale($category, $languageCode, $countryCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category Named constant specifying the category of the functions affected by the locale setting.
|
||||
* It's the same constant as required by setlocale() function.
|
||||
* @param string $languageCode Language code, in ISO 639-1 format. Short form of the locale, e.g. "fr".
|
||||
* @param string $countryCode Country code, in ISO 3166-1 alpha-2 format, e.g. "FR"
|
||||
* @param string $expectedLocale Expected locale
|
||||
*
|
||||
* @dataProvider provideCategoryLanguageCodeAndExpectedLocale
|
||||
*/
|
||||
public function testGetLocale($category, $languageCode, $countryCode, $expectedLocale)
|
||||
{
|
||||
Locale::setLocale($category, $languageCode, $countryCode);
|
||||
self::assertEquals($expectedLocale, Locale::getLocale($category));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides language, encoding and country code
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user