Inflection
Morphology Inflection
|
An object that represents a specific geographical, political, or cultural region. More...
#include <ULocale.hpp>
Public Member Functions | |
ULocale (std::string_view language, std::string_view country=std::string_view(), std::string_view variant=std::string_view(), std::string_view keywordsAndValues=std::string_view()) | |
ULocale (const ::inflection::util::ULocale &other) | |
~ULocale () override | |
::inflection::util::ULocale & | operator= (const ::inflection::util::ULocale &other) |
bool | operator== (const ::inflection::util::ULocale &other) const |
std::strong_ordering | operator<=> (const ::inflection::util::ULocale &other) const |
std::string_view | getLanguage () const |
std::string_view | getScript () const |
std::string_view | getCountry () const |
std::string_view | getVariant () const |
ULocale | getFallback () const |
::std::u16string | toString () const override |
const ::std::string & | getName () const |
std::size_t | operator() (const inflection::util::ULocale &locale) const noexcept |
![]() | |
virtual ::std::u16string | toString () const |
virtual | ~Object () |
An object that represents a specific geographical, political, or cultural region.
A ULocale
object represents a specific geographical, political, or cultural region. An operation that requires a Locale
to perform its task is called locale-sensitive and uses the Locale
to tailor information for the user. For example, displaying a number is a locale-sensitive operation–the number should be formatted according to the customs/conventions of the user's native country, region, or culture.
The Locale class is not suitable for subclassing. It is similar to std::locale, ICU4J ULocale, ICU4C Locale and CFLocale. ICU and Core Foundation support BCP 47. C++ std::locale does not support BCP 47.
You can create a Locale
object using the constructor in this class:
The first argument to the constructors is a valid ISO Language Code. These codes are the lower-case two to three letter codes as defined by ISO-639. You can find a full list of these codes at:ULocale(const char* language, const char* country, const char* variant)
The second argument to the constructors is a valid ISO Country Code. These codes are the upper-case two-letter codes as defined by ISO-3166. You can find a full list of these codes at a number of sites, such as:
https://www.iso.org/obp/ui/#iso:pub:PUB500001:en
The third constructor requires a third argument–the Variant. The Variant codes are vendor and browser-specific. For example, use REVISED for a language's revised script orthography, and POSIX for POSIX. Where there are two variants, separate them with an underscore, and put the most important one first. For example, a Traditional Spanish collation might be referenced, with "ES", "ES", "Traditional_POSIX".
Because a ULocale
object is just an identifier for a region, no validity check is performed when you construct a Locale
.
Once you've created a Locale
you can query it for information about itself. Use getCountry
to get the ISO Country Code and getLanguage
to get the ISO Language Code. You can use getDisplayCountry
to get the name of the country suitable for displaying to the user. Similarly, you can use getDisplayLanguage
to get the name of the language suitable for displaying to the user. Interestingly, the getDisplayXXX
methods are themselves locale-sensitive and have two versions: one that uses the default locale and one that takes a locale as an argument and displays the name or country in a language appropriate to that locale.
A Locale
is the mechanism for identifying the kind of object (NumberFormat
) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves.
Definition at line 81 of file ULocale.hpp.
inflection::util::ULocale::ULocale | ( | std::string_view | language, |
std::string_view | country = std::string_view() , |
||
std::string_view | variant = std::string_view() , |
||
std::string_view | keywordsAndValues = std::string_view() |
||
) |
Construct a locale from language, country, variant. If an error occurs, then the constructed object will be "bogus" (isBogus() will return TRUE).
language | Lowercase two-letter or three-letter ISO-639 code. This parameter can instead be an ICU style C locale (e.g. "en_US"), but the other parameters must not be used. This parameter can be NULL; if so, the locale is initialized to match the current default locale. (This is the same as using the default constructor.) Please note: The Java Locale class does NOT accept the form 'new Locale("en_US")' but only 'new Locale("en","US")' |
country | Uppercase two-letter ISO-3166 code. (optional) |
variant | Uppercase vendor and browser specific code. See class description. (optional) |
keywordsAndValues | A string consisting of keyword/values pairs, such as "collation=phonebook;currency=euro" |
inflection::util::ULocale::ULocale | ( | const ::inflection::util::ULocale & | other | ) |
Initializes a Locale object from another Locale object.
other | The Locale object being copied in. |
|
override |
Destructor
|
inline |
Returns the locale's ISO-3166 country code.
Definition at line 226 of file ULocale.hpp.
ULocale inflection::util::ULocale::getFallback | ( | ) | const |
Returns the fallback locale for this locale.
|
inline |
Returns the locale's ISO-639 language code.
Definition at line 232 of file ULocale.hpp.
|
inline |
Returns the programmatic name of the entire locale, with the language, country and variant separated by underbars. If a field is missing, up to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"
Definition at line 250 of file ULocale.hpp.
|
inline |
Returns the locale's ISO-15924 abbreviation script code.
Definition at line 238 of file ULocale.hpp.
|
inline |
Returns the locale's variant code.
Definition at line 244 of file ULocale.hpp.
|
noexcept |
Generates a hash code compatible with std::hash for the locale.
|
inline |
String compares the order of the locale key.
other | The locale key object to be compared with this. |
Definition at line 219 of file ULocale.hpp.
::inflection::util::ULocale & inflection::util::ULocale::operator= | ( | const ::inflection::util::ULocale & | other | ) |
Replaces the entire contents of *this with the specified value.
other | The Locale object being copied in. |
|
inline |
Checks if two locale keys are the same.
other | The locale key object to be compared with this. |
Definition at line 214 of file ULocale.hpp.
|
override |
Returns the programmatic name of the entire locale, with the language, country and variant separated by underbars. If a field is missing, up to two leading underbars will occur. Example: "en", "de_DE", "en_US_WIN", "de__POSIX", "fr__MAC", "__MAC", "_MT", "_FR_EURO"