Inflection
Morphology Inflection
Loading...
Searching...
No Matches
Public Member Functions | List of all members
inflection::util::ULocale Class Reference

An object that represents a specific geographical, political, or cultural region. More...

#include <ULocale.hpp>

+ Inheritance diagram for inflection::util::ULocale:

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::ULocaleoperator= (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
 
- Public Member Functions inherited from inflection::Object
virtual ::std::u16string toString () const
 
virtual ~Object ()
 

Detailed Description

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:

      ULocale(const char* language,
              const char* country,
              const char* variant)

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:
http://www.loc.gov/standards/iso639-2/

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.

Constructor & Destructor Documentation

◆ ULocale() [1/2]

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).

Parameters
languageLowercase 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")'
countryUppercase two-letter ISO-3166 code. (optional)
variantUppercase vendor and browser specific code. See class description. (optional)
keywordsAndValuesA string consisting of keyword/values pairs, such as "collation=phonebook;currency=euro"

◆ ULocale() [2/2]

inflection::util::ULocale::ULocale ( const ::inflection::util::ULocale other)

Initializes a Locale object from another Locale object.

Parameters
otherThe Locale object being copied in.

◆ ~ULocale()

inflection::util::ULocale::~ULocale ( )
override

Destructor

Member Function Documentation

◆ getCountry()

std::string_view inflection::util::ULocale::getCountry ( ) const
inline

Returns the locale's ISO-3166 country code.

Returns
An alias to the code

Definition at line 226 of file ULocale.hpp.

◆ getFallback()

ULocale inflection::util::ULocale::getFallback ( ) const

Returns the fallback locale for this locale.

◆ getLanguage()

std::string_view inflection::util::ULocale::getLanguage ( ) const
inline

Returns the locale's ISO-639 language code.

Returns
An alias to the code

Definition at line 232 of file ULocale.hpp.

◆ getName()

const ::std::string & inflection::util::ULocale::getName ( ) const
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"

Returns
A pointer to "name".

Definition at line 250 of file ULocale.hpp.

◆ getScript()

std::string_view inflection::util::ULocale::getScript ( ) const
inline

Returns the locale's ISO-15924 abbreviation script code.

Returns
An alias to the code
See also
uscript_getShortName
uscript_getCode

Definition at line 238 of file ULocale.hpp.

◆ getVariant()

std::string_view inflection::util::ULocale::getVariant ( ) const
inline

Returns the locale's variant code.

Returns
An alias to the code

Definition at line 244 of file ULocale.hpp.

◆ operator()()

std::size_t inflection::util::ULocale::operator() ( const inflection::util::ULocale locale) const
noexcept

Generates a hash code compatible with std::hash for the locale.

◆ operator<=>()

std::strong_ordering inflection::util::ULocale::operator<=> ( const ::inflection::util::ULocale other) const
inline

String compares the order of the locale key.

Parameters
otherThe locale key object to be compared with this.

Definition at line 219 of file ULocale.hpp.

◆ operator=()

::inflection::util::ULocale & inflection::util::ULocale::operator= ( const ::inflection::util::ULocale other)

Replaces the entire contents of *this with the specified value.

Parameters
otherThe Locale object being copied in.
Returns
*this

◆ operator==()

bool inflection::util::ULocale::operator== ( const ::inflection::util::ULocale other) const
inline

Checks if two locale keys are the same.

Parameters
otherThe locale key object to be compared with this.
Returns
True if the two locale keys are the same, false otherwise.

Definition at line 214 of file ULocale.hpp.

◆ toString()

::std::u16string inflection::util::ULocale::toString ( ) const
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"

Returns
A pointer to "name".

The documentation for this class was generated from the following file: