Country Generator 3.3.2
Procedural country generation for C++23
Loading...
Searching...
No Matches
dasmig::locale Class Reference

A locale of a country: its tag, CLDR formats and calendar data. More...

#include <countrygen.hpp>

Public Member Functions

std::string format_date (std::chrono::year_month_day d, date_style style=date_style::short_) const
 Write a date with one of the locale's date patterns.
 
std::string format_time (std::chrono::hh_mm_ss< std::chrono::seconds > t, time_style style=time_style::short_) const
 Write a time of day with one of the locale's time patterns.
 
std::string format_number (double value, unsigned max_fraction=3) const
 Write a number with the locale's decimal pattern.
 
std::string format_money (const core::money &m) const
 Write an amount with the locale's currency pattern.
 
std::uint64_t seed () const
 The seed this locale was drawn with.
 
const core::seed_signature & signature () const
 The seed and the data this locale was drawn from.
 
void to_json (core::json_writer &w) const
 Write this locale as a JSON object (doc/usage.md, "Locales").
 
std::string to_json () const
 This locale as a JSON document.
 
 operator std::string () const
 Implicit conversion to std::string.
 

Public Attributes

std::string tag
 BCP 47, minimised: "pt-BR", "zh-TW", "sr-Latn-RS".
 
std::string language
 ISO 639 code: "pt".
 
std::string script
 ISO 15924 code when the tag needs one ("Latn"); else empty.
 
std::string language_name
 English, as country::language_shares writes it: "Portuguese".
 
std::string country_code
 ISO 3166-1 alpha-2: "BR".
 
double share {0.0}
 Percent of the country that speaks the language (CLDR).
 
std::string basis
 "cldr", "inherited" or "fallback" (doc/data.md).
 
std::string date_short
 LDML short date pattern: "dd/MM/y".
 
std::string date_medium
 LDML medium date pattern.
 
std::string date_long
 LDML long date pattern.
 
std::string date_full
 LDML full date pattern.
 
std::string time_short
 LDML short time pattern: "HH:mm".
 
std::string time_medium
 LDML medium time pattern: "HH:mm:ss".
 
std::array< std::string, 12 > months {}
 Wide month names, format context, January first.
 
std::array< std::string, 12 > months_abbr {}
 Abbreviated month names.
 
std::array< std::string, 7 > weekdays {}
 Wide weekday names, format context, Sunday first.
 
std::array< std::string, 7 > weekdays_abbr {}
 Abbreviated weekday names, Sunday first.
 
std::string am
 Day period before noon.
 
std::string pm
 Day period after noon.
 
std::array< std::string, 2 > eras {}
 Abbreviated eras: BC, AD.
 
std::string decimal
 Decimal symbol: ",".
 
std::string group
 Grouping symbol: ".".
 
std::string minus
 Minus sign: "-".
 
std::string number_pattern
 CLDR decimal pattern: "#,##0.###".
 
std::string currency_pattern
 CLDR currency pattern: "¤ #,##0.00".
 
std::string currency_spacing
 Put between a letter symbol and the number; usually U+00A0.
 
std::string currency_code
 The country's ISO 4217 code: "BRL".
 
std::string currency_symbol
 This locale's symbol for it: "R$".
 
std::uint8_t currency_digits {2}
 Its ISO 4217 minor unit.
 
std::chrono::weekday first_day {std::chrono::Monday}
 First day of the week.
 
std::chrono::weekday weekend_start {std::chrono::Saturday}
 First day of the weekend.
 
std::chrono::weekday weekend_end {std::chrono::Sunday}
 Last day of the weekend.
 
dasmig::measurement measurement {dasmig::measurement::metric}
 Measurement system.
 

Friends

class cntg
 
std::ostream & operator<< (std::ostream &os, const locale &l)
 Stream the tag.
 

Detailed Description

A locale of a country: its tag, CLDR formats and calendar data.

Every row is complete: the build resolved CLDR's inheritance, so the formatting functions read only these fields.

Definition at line 1214 of file countrygen.hpp.

Member Function Documentation

◆ format_date()

std::string dasmig::locale::format_date ( std::chrono::year_month_day  d,
date_style  style = date_style::short_ 
) const
inline

Write a date with one of the locale's date patterns.

Parameters
dThe date.
styleWhich pattern.
Returns
The text, in UTF-8.
Exceptions
std::invalid_argumentIf d is not a valid date, or the pattern holds a field the formatter does not write.

Definition at line 1261 of file countrygen.hpp.

◆ format_money()

std::string dasmig::locale::format_money ( const core::money &  m) const
inline

Write an amount with the locale's currency pattern.

Exactly m.digits fraction digits, from the integer minor units, so nothing is rounded. The symbol is the locale's own for its currency and the ISO code for any other; CLDR's currency spacing puts currency_spacing between a symbol that ends (or starts) with a letter and the number: CHF 1,234.50 but $1,234.50 in en-US.

Parameters
mThe amount.
Returns
The text, in UTF-8.
Exceptions
std::invalid_argumentIf the pattern is not one the formatter writes.

Definition at line 1357 of file countrygen.hpp.

◆ format_number()

std::string dasmig::locale::format_number ( double  value,
unsigned  max_fraction = 3 
) const
inline

Write a number with the locale's decimal pattern.

The value's shortest round-trip digits are rounded half-even, as text, to at most max_fraction fraction digits (and the pattern's maximum), so 2.675 at two digits is 2.68 on every platform.

Parameters
valueThe number.
max_fractionMost fraction digits.
Returns
The text, in UTF-8.
Exceptions
std::invalid_argumentIf value is not finite or the pattern is not one the formatter writes.

Definition at line 1332 of file countrygen.hpp.

◆ format_time()

std::string dasmig::locale::format_time ( std::chrono::hh_mm_ss< std::chrono::seconds >  t,
time_style  style = time_style::short_ 
) const
inline

Write a time of day with one of the locale's time patterns.

Parameters
tThe time (0 to 24 hours).
styleWhich pattern.
Returns
The text, in UTF-8.
Exceptions
std::invalid_argumentIf t is negative or 24 hours or more, or the pattern holds a field the formatter does not write.

Definition at line 1297 of file countrygen.hpp.

◆ operator std::string()

dasmig::locale::operator std::string ( ) const
inline

Implicit conversion to std::string.

Returns
The tag.

Definition at line 1445 of file countrygen.hpp.

◆ seed()

std::uint64_t dasmig::locale::seed ( ) const
inline

The seed this locale was drawn with.

Returns
The per-call seed (0 for find_locale() and locales()).

Definition at line 1371 of file countrygen.hpp.

◆ signature()

const core::seed_signature & dasmig::locale::signature ( ) const
inline

The seed and the data this locale was drawn from.

Returns
The replay signature.

Definition at line 1375 of file countrygen.hpp.

◆ to_json() [1/2]

std::string dasmig::locale::to_json ( ) const
inline

This locale as a JSON document.

Returns
Compact JSON.

Definition at line 1436 of file countrygen.hpp.

◆ to_json() [2/2]

void dasmig::locale::to_json ( core::json_writer &  w) const
inline

Write this locale as a JSON object (doc/usage.md, "Locales").

The month, weekday, era and day-period names are left out: they are data, reachable through cntg::find_locale().

Parameters
wWriter positioned where a value is allowed.

Definition at line 1383 of file countrygen.hpp.

Friends And Related Symbol Documentation

◆ cntg

friend class cntg
friend

Definition at line 1550 of file countrygen.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const locale &  l 
)
friend

Stream the tag.

Parameters
osOutput stream.
lLocale to stream.
Returns
The stream.

Definition at line 1454 of file countrygen.hpp.

Member Data Documentation

◆ am

std::string dasmig::locale::am

Day period before noon.

Definition at line 1235 of file countrygen.hpp.

◆ basis

std::string dasmig::locale::basis

"cldr", "inherited" or "fallback" (doc/data.md).

Definition at line 1223 of file countrygen.hpp.

◆ country_code

std::string dasmig::locale::country_code

ISO 3166-1 alpha-2: "BR".

Definition at line 1221 of file countrygen.hpp.

◆ currency_code

std::string dasmig::locale::currency_code

The country's ISO 4217 code: "BRL".

Definition at line 1245 of file countrygen.hpp.

◆ currency_digits

std::uint8_t dasmig::locale::currency_digits {2}

Its ISO 4217 minor unit.

Definition at line 1247 of file countrygen.hpp.

◆ currency_pattern

std::string dasmig::locale::currency_pattern

CLDR currency pattern: "¤ #,##0.00".

Definition at line 1243 of file countrygen.hpp.

◆ currency_spacing

std::string dasmig::locale::currency_spacing

Put between a letter symbol and the number; usually U+00A0.

Definition at line 1244 of file countrygen.hpp.

◆ currency_symbol

std::string dasmig::locale::currency_symbol

This locale's symbol for it: "R$".

Definition at line 1246 of file countrygen.hpp.

◆ date_full

std::string dasmig::locale::date_full

LDML full date pattern.

Definition at line 1228 of file countrygen.hpp.

◆ date_long

std::string dasmig::locale::date_long

LDML long date pattern.

Definition at line 1227 of file countrygen.hpp.

◆ date_medium

std::string dasmig::locale::date_medium

LDML medium date pattern.

Definition at line 1226 of file countrygen.hpp.

◆ date_short

std::string dasmig::locale::date_short

LDML short date pattern: "dd/MM/y".

Definition at line 1225 of file countrygen.hpp.

◆ decimal

std::string dasmig::locale::decimal

Decimal symbol: ",".

Definition at line 1239 of file countrygen.hpp.

◆ eras

std::array<std::string, 2> dasmig::locale::eras {}

Abbreviated eras: BC, AD.

Definition at line 1237 of file countrygen.hpp.

◆ first_day

std::chrono::weekday dasmig::locale::first_day {std::chrono::Monday}

First day of the week.

Definition at line 1249 of file countrygen.hpp.

◆ group

std::string dasmig::locale::group

Grouping symbol: ".".

Definition at line 1240 of file countrygen.hpp.

◆ language

std::string dasmig::locale::language

ISO 639 code: "pt".

Definition at line 1218 of file countrygen.hpp.

◆ language_name

std::string dasmig::locale::language_name

English, as country::language_shares writes it: "Portuguese".

Definition at line 1220 of file countrygen.hpp.

◆ measurement

dasmig::measurement dasmig::locale::measurement {dasmig::measurement::metric}

Measurement system.

Definition at line 1252 of file countrygen.hpp.

◆ minus

std::string dasmig::locale::minus

Minus sign: "-".

Definition at line 1241 of file countrygen.hpp.

◆ months

std::array<std::string, 12> dasmig::locale::months {}

Wide month names, format context, January first.

Definition at line 1231 of file countrygen.hpp.

◆ months_abbr

std::array<std::string, 12> dasmig::locale::months_abbr {}

Abbreviated month names.

Definition at line 1232 of file countrygen.hpp.

◆ number_pattern

std::string dasmig::locale::number_pattern

CLDR decimal pattern: "#,##0.###".

Definition at line 1242 of file countrygen.hpp.

◆ pm

std::string dasmig::locale::pm

Day period after noon.

Definition at line 1236 of file countrygen.hpp.

◆ script

std::string dasmig::locale::script

ISO 15924 code when the tag needs one ("Latn"); else empty.

Definition at line 1219 of file countrygen.hpp.

◆ share

double dasmig::locale::share {0.0}

Percent of the country that speaks the language (CLDR).

Definition at line 1222 of file countrygen.hpp.

◆ tag

std::string dasmig::locale::tag

BCP 47, minimised: "pt-BR", "zh-TW", "sr-Latn-RS".

Definition at line 1217 of file countrygen.hpp.

◆ time_medium

std::string dasmig::locale::time_medium

LDML medium time pattern: "HH:mm:ss".

Definition at line 1230 of file countrygen.hpp.

◆ time_short

std::string dasmig::locale::time_short

LDML short time pattern: "HH:mm".

Definition at line 1229 of file countrygen.hpp.

◆ weekdays

std::array<std::string, 7> dasmig::locale::weekdays {}

Wide weekday names, format context, Sunday first.

Definition at line 1233 of file countrygen.hpp.

◆ weekdays_abbr

std::array<std::string, 7> dasmig::locale::weekdays_abbr {}

Abbreviated weekday names, Sunday first.

Definition at line 1234 of file countrygen.hpp.

◆ weekend_end

std::chrono::weekday dasmig::locale::weekend_end {std::chrono::Sunday}

Last day of the weekend.

Definition at line 1251 of file countrygen.hpp.

◆ weekend_start

std::chrono::weekday dasmig::locale::weekend_start {std::chrono::Saturday}

First day of the weekend.

Definition at line 1250 of file countrygen.hpp.


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