xtd 0.2.0
Loading...
Searching...
No Matches
xtd::globalization::culture_info Class Reference
Inheritance diagram for xtd::globalization::culture_info:
xtd::object xtd::iequatable< xtd::globalization::culture_info > xtd::interface xtd::extensions::equality_operators< xtd::globalization::culture_info, iequatable< xtd::globalization::culture_info > >

Definition

Provides information about a specific culture (called a locale for unmanaged code development). The information includes the names for the culture, the writing system, the calendar used, the sort order of strings, and formatting for dates and numbers.

class culture_info : public xtd::object, public xtd::iequatable<xtd::globalization::culture_info>
culture_info()
Initializes a new instance of the xtd::globalization::culture_info class.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Inheritance
xtd::object → xtd::collections::culture_not_found_exception
Header
#include <xtd/globalization/culture_not_found_exception>
Namespace
xtd::collections
Library
xtd.core
Examples
The following example shows how to create a xtd::globalization::culture_info object for Spanish (Spain) with the international sort and another xtd::globalization::culture_info object with the traditional sort.

Public Constructors

 culture_info ()
 Initializes a new instance of the xtd::globalization::culture_info class.
 
 culture_info (culture_info &&culture)=default
 Initializes a new instance of the xtd::globalization::culture_info class with specified culture.
 
 culture_info (const culture_info &culture)=default
 Initializes a new instance of the xtd::globalization::culture_info class with specified culture.
 
 culture_info (const std::locale &locale)
 Initializes a new instance of the xtd::globalization::culture_info class with specified locale.
 
 culture_info (xtd::size culture)
 Initializes a new instance of the xtd::globalization::culture_info class based on the culture specified by the culture identifier.
 
 culture_info (const xtd::string &name)
 Initializes a new instance of the xtd::globalization::culture_info class based on the culture specified by name.
 

Public Properties

xtd::globalization::culture_types culture_types () const noexcept
 Gets the culture types that pertain to the current xtd::globalization::culture_info object.
 
const xtd::stringdisplay_name () const noexcept
 
const xtd::stringenglish_name () const noexcept
 
bool is_locale_available () const noexcept
 
xtd::size keyboard_layout_id () const noexcept
 
xtd::size lcid () const noexcept
 
const std::locale & locale () const noexcept
 
const xtd::stringname () const noexcept
 
const xtd::stringnative_name () const noexcept
 

Public Methods

bool equals (const object &obj) const noexcept override
 Determines whether the specified object is equal to the current object.
 
bool equals (const culture_info &obj) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 

Public Operators

culture_infooperator= (culture_info &&culture)=default
 
culture_infooperator= (const culture_info &culture)=default
 
culture_infooperator= (std::locale &&locale)
 
culture_infooperator= (const std::locale &locale)
 
 operator const std::locale & () const noexcept
 

Public Static Properties

static culture_info current_culture () noexcept
 
static void current_culture (const culture_info &value)
 
static culture_info invariant_culture () noexcept
 

Public Static Methods

static xtd::array< culture_infoget_cultures (xtd::globalization::culture_types types) noexcept
 

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ culture_info() [1/6]

xtd::globalization::culture_info::culture_info ( )

Initializes a new instance of the xtd::globalization::culture_info class.

◆ culture_info() [2/6]

xtd::globalization::culture_info::culture_info ( culture_info && culture)
default

Initializes a new instance of the xtd::globalization::culture_info class with specified culture.

Parameters
cultureThe xtd::globalization::culture_info to inititalise this instance.

◆ culture_info() [3/6]

xtd::globalization::culture_info::culture_info ( const culture_info & culture)
default

Initializes a new instance of the xtd::globalization::culture_info class with specified culture.

Parameters
cultureThe xtd::globalization::culture_info to inititalise this instance.

◆ culture_info() [4/6]

xtd::globalization::culture_info::culture_info ( const std::locale & locale)

Initializes a new instance of the xtd::globalization::culture_info class with specified locale.

Parameters
localeThe std::locale to inititalise this instance.

◆ culture_info() [5/6]

xtd::globalization::culture_info::culture_info ( xtd::size culture)
explicit

Initializes a new instance of the xtd::globalization::culture_info class based on the culture specified by the culture identifier.

Parameters
cultureA predefined xtd::globalization::culture_info identifier, xtd::globalization::culture_info::lcid property of an existing xtd::globalization::culture_info object, or Windows-only culture identifier.
Exceptions
xtd::globalization::culture_not_found_exceptionculture is not a valid culture identifier. See the Notes to Callers section for more information.
Remarks
Predefined culture identifiers for cultures available on Windows system are listed in the Language tag column in the list of language/region names supported by Windows. Culture names follow the standard defined by BCP 47.

In most cases, the culture parameter is mapped to the corresponding National Language Support (NLS) locale identifier. The value of the culture parameter becomes the value of the xtd::globalization::culture_info::lcid property of the new xtd::globalization::culture_info.

We recommend that you call the locale name constructor xtd::globalization::culture_info::culture_info (const xtd::string& name), because locale names are preferable to LCIDs. For custom locales, a locale name is required.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the specified culture identifier matches the culture identifier of the current Windows culture, this constructor creates a xtd::globalization::culture_info that uses those overrides, including user settings for the properties of the xtd::globalization::date_time_format_info instance returned by the xtd::globalization::culture_info::date_time_format property, and the properties of the xtd::globalization::number_format_info instance returned by the xtd::globalization::culture_info::number_format property. If the user settings are incompatible with the culture associated with the xtd::globalization::culture_info (for example, if the selected calendar is not one of the xtd::globalization::culture_info::optional_calendars) the results of the methods and the values of the properties are undefined.

For example, suppose that Arabic (Saudi Arabia) is the current Windows culture and the user has changed the calendar from Hijri to Gregorian.
  • With culture_info {0x0401} (culture name ar-SA), xtd::globalization::culture_info::calendar is set to xtd::globalization::gregorian_calendar (which is the user setting).
  • With culture_info {0x041E} (culture name th-TH), xtd::globalization::culture_info::calendar is set to xtd::globalization::thai_buddhist_calendar (which is the default calendar for th-TH).
Note
For backwards compatibility, a culture constructed using a culture parameter of 0x0004 or 0x7c04 will have a xtd::globalization::culture_info::name property of zh-CHS or zh-CHT, respectively. You should instead prefer to construct the culture using the current standard culture names of zh-Hans or zh-Hant, unless you have a reason for using the older names.

LCIDs are being deprecated, and implementers are strongly encouraged to use newer versions of APIs that support BCP 47 locale names instead. Each LCID can be represented by a BCP 47 locale name, but the reverse is not true. The LCID range is restricted and unable to uniquely identify all the possible combinations of language and region.

◆ culture_info() [6/6]

xtd::globalization::culture_info::culture_info ( const xtd::string & name)
explicit

Initializes a new instance of the xtd::globalization::culture_info class based on the culture specified by name.

Parameters
nameA predefined xtd::globalization::culture_info name, xtd::globalization::culture_info::name of an existing xtd::globalization::culture_info, or Windows-only culture name. name is not case-sensitive.
examples
The following example retrieves the current culture. If it is anything other than the French (France) culture, it calls the xtd::globalization::culture_info::culture_info (const string&) constructor to instantiate a xtd::globalization::culture_info object that represents the French (France) culture and makes it the current culture. Otherwise, it instantiates a xtd::globalization::culture_info object that represents the French (Luxembourg) culture and makes it the current culture.
#include <xtd/xtd>
using namespace globalization;
auto main() -> int {
auto current = culture_info::current_culture();
console::write_line("The current culture is {}", current.name());
auto new_culture = culture_info {};
if (current.name().equals("fr-FR"))
new_culture = culture_info {"fr-LU"};
else
new_culture = culture_info {"fr-FR"};
culture_info::current_culture(new_culture);
console::write_line("The current culture is now {}", culture_info::current_culture().name());
}
// This code produces the following output :
//
// The current culture is en-US
// The current culture is now fr-FR
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:37
Contains classes that define culture-related information, including language, country/region,...
Definition culture_info.hpp:18
Remarks
For a list of predefined culture names on Windows systems, see the Language tag column in the list of language/region names supported by Windows. Culture names follow the standard defined by BCP 47.

If name is xtd::string::empty_string, the constructor creates an instance of the invariant culture; this is equivalent to retrieving the value of the xtd::globalization::culture_info::invariant_culture property.

The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the specified culture identifier matches the culture identifier of the current Windows culture, this constructor creates a xtd::globalization::culture_info that uses those overrides, including user settings for the properties of the xtd::globalization::date_time_format_info instance returned by the xtd::globalization::culture_info::date_time_format property, and the properties of the xtd::globalization::number_format_info instance returned by the xtd::globalization::culture_info::number_format property. If the user settings are incompatible with the culture associated with the xtd::globalization::culture_info (for example, if the selected calendar is not one of the xtd::globalization::culture_info::optional_calendars) the results of the methods and the values of the properties are undefined.

For example, suppose that Arabic (Saudi Arabia) is the current Windows culture and the user has changed the calendar from Hijri to Gregorian.
  • With culture_info {0x0401} (culture name ar-SA), xtd::globalization::culture_info::calendar is set to xtd::globalization::gregorian_calendar (which is the user setting).
  • With culture_info {0x041E} (culture name th-TH), xtd::globalization::culture_info::calendar is set to xtd::globalization::thai_buddhist_calendar (which is the default calendar for th-TH).

Member Function Documentation

◆ culture_types()

xtd::globalization::culture_types xtd::globalization::culture_info::culture_types ( ) const
noexcept

Gets the culture types that pertain to the current xtd::globalization::culture_info object.

Returns
A bitwise combination of one or more xtd::globalization::culture_types values. There is no default value.
Examples
The following example demonstrates the xtd::globalization::culture_types enumeration and the xtd::globalization::culture_info::culture_types property.
#include <xtd/xtd>
using namespace globalization;
auto main() -> int {
// Get and enumerate all cultures.
auto all_cultures = culture_info::get_cultures(culture_types::all_cultures);
for (auto ci : all_cultures) {
// Display the name of each culture.
console::write("{} ({}): ", ci.english_name(), ci.name());
// Indicate the culture type.
console::write(" neutral_culture");
if (enum_object {ci.culture_types()}.has_flag(culture_types::specific_cultures))
console::write(" spsecific_culture");
}
}
// This code produces the following output :
//
// Invariant Language (Invariant Country) (): spsecific_culture
// Afrikaans (af): neutral_culture
// Afrikaans (Namibia) (af-NA): spsecific_culture
// ...
// Chinese, Traditional (Taiwan) (zh-Hant-TW): spsecific_culture
// Zulu (zu): neutral_culture
// Zulu (South Africa) (zu-ZA): spsecific_culture
static void write(arg_t &&value)
Writes the text representation of the specified value to the standard output stream.
Definition console.hpp:462
@ all_cultures
All cultures that are recognized by xtd, including neutral and specific cultures and custom cultures ...
Definition culture_types.hpp:30
@ neutral_cultures
Cultures that are associated with a language but are not specific to a country/region.
Definition culture_types.hpp:23
Provides the base class for enumerations.
Definition enum_object.hpp:48
bool has_flag(enum_type flag) const noexcept
Retrieves an array of the values of the constants in a specified enumeration.
Definition enum_object.hpp:90

◆ equals() [1/2]

bool xtd::globalization::culture_info::equals ( const object & obj) const
overridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.
#include <xtd/xtd>
auto main() -> int {
auto object1 = new_ptr<object>();
auto object2 = new_ptr<object>();
auto object3 = object2;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
object3 = object1;
console::write_line(object1->equals(*object3));
console::write_line(*object1 == *object3);
}
// This code produces the following output :
//
// false
// false
// true
// true
ptr< type_t > new_ptr(args_t &&... args)
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24

Reimplemented from xtd::object.

◆ equals() [2/2]

bool xtd::globalization::culture_info::equals ( const culture_info & obj) const
overridevirtualnoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

Implements xtd::iequatable< xtd::globalization::culture_info >.

◆ to_string()

xtd::string xtd::globalization::culture_info::to_string ( ) const
overridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.
#include <xtd/xtd>
namespace examples {
namespace object_test {
class object1 : public object {
};
}
}
auto main() -> int {
ptr<object> obj1 = new_ptr<examples::object_test::object1>();
console::write_line(obj1->to_string());
ptr<object> obj2 = new_ptr<date_time>(1971, 1, 5, 23, 5, 0);
console::write_line(obj2->to_string());
ptr<object> obj3 = new_ptr<boolean_object>();
console::write_line(obj3->to_string());
}
// This code produces the following output :
//
// examples::object_test::object1
// Tue Jan 5 23:05:00 1971
// false
object()=default
Create a new instance of the ultimate base class object.

Reimplemented from xtd::object.


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