Locales class
📖 Description
The Locales
class holds locale information and contains functions to format dates and numbers.
📌 Static fields
🏷️ country
Retrieves the country for the current active locale.
Type
string
🏷️ countryCode
Retrieves the country code for the current active locale.
Type
string
🏷️ countryNative
Retrieves the native country name for the current active locale.
Type
string
🏷️ direction
Retrieves the text direction for the current active locale.
Type
"ltr" | "rtl"
🏷️ domain
Retrieves the domain for the current locale.
Type
string
🏷️ domains
Retrieves a list of domains. Each domain contains the locale, language and native language string.
Type
🏷️ identifier
Retrieves the locale identifier string.
Type
string
🏷️ language
Retrieves the language for the current active locale.
Type
string
🏷️ languageNative
Retrieves the language in the native language for the current active locale.
Type
string
🏷️ locale
Retrieves the locale information for the current active locale.
Type
🏷️ locales
Retrieves a list of supported locales.
Type
string[]
📌 Static methods
🔧 dateFull
Formats to a localized full date string (for example, Wednesday, March 23, 2022
).
Signature
dateFull(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date string.
🔧 dateLong
Formats to a localized long date string (for example, March 23, 2022
).
Signature
dateLong(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date string.
🔧 dateMedium
Formats to a localized medium date string (for example, Mar 23, 2022
).
Signature
dateMedium(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date string.
🔧 dateShort
Formats to a localized short date string (for example, 3/23/22
).
Signature
dateShort(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date string.
🔧 dateTime
Formats a date/time to a localized string.
Signature
dateTime(format: string, time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
format | string | No | Specifies the format to use, using the CLDR date/time formatting style. The following variables are available: - y / yyyy : Specifies the full 4-digit year;- yy : Specifies the 2-digit year;- M : Specifies the month number;- MM : Specifies the month number with a minimum of 2 digits;- MMM : Specifies the month as an abbreviated string (e.g. Jan );- MMMM : Specifies the month as a full string (e.g. January );- MMMMM : Specifies the month as a narrow (e.g. J );- LLL : Specifies the month as an abbreviated nominative string (e.g. Jan );- LLLL : Specifies the month as a full nominative string (e.g. January );- LLLLL : Specifies the month as a narrow nominative string (e.g. J );- d : Specifies the day of the month;- dd : Specifies the day of the month with a minimum of 2 digits;- E : Specifies the day of the week;- EE : Specifies the day of the week as a string (e.g. Su );- EEE : Specifies the day of the week as an abbreviated string (e.g. Sun );- EEEE : Specifies the day of the week as a full string (e.g. Sunday );- EEEEE : Specifies the day of the week as a narrow string (e.g. S );- cc : Specifies the day of the week as a nominative string (e.g. Su );- ccc : Specifies the day of the week as an abbreviated nominative string (e.g. Sun );- cccc : Specifies the day of the week as a full nominative string (e.g. Sunday );- ccccc : Specifies the day of the week as a narrow nominative string (e.g. S );- H : Specifies the number of hours in 24-hour format;- HH : Specifies the number of hours in 24-hour format with a minimum of 2 digits;- h : Specifies the number of hours in 12-hour format;- hh : Specifies the number of hours in 12-hour format with a minimum of 2 digits;- a : Specifies the AM or PM hour suffix;- m : Specifies the number of minutes;- mm : Specifies the number of minutes with a minimum of 2 digits;- s : Specifies the number of seconds;- ss : Specifies the number of seconds with a minimum of 2 digits;- S : Specifies the number of milliseconds;- SSS : Specifies the number of milliseconds with a minimum of 3 digits. |
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date string.
🔧 dateTimeFull
Formats to a localized full date/time string (for example, Wednesday, March 23, 2022 at 4:38:47 PM
).
Signature
dateTimeFull(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeLong
Formats to a localized long date/time string (for example, March 23, 2022 at 4:38:38 PM
).
Signature
dateTimeLong(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeMedium
Formats to a localized medium date/time string (for example, Mar 23, 2022, 4:38:29 PM
).
Signature
dateTimeMedium(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeShort
Formats to a localized short date/time string (for example, 3/23/22, 4:38 PM
).
Signature
dateTimeShort(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized date/time string.
🔧 findDomain
Tries to find the most significant domain (ignoring case). This is useful to find an appropiate language code of a locale that's available (is loaded) for a certain domain. For example, if the en
locale is loaded and en-US
is supplied to this function, it will return en
since there is no specific locale information loaded for en-US
.
Signature
findDomain(domain: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
domain | string | No | Specifies the ISO 639-1 language domain. |
Return value
Returns the best matching locale domain. If nothing matches, it will return the default domain en
.
🔧 get
Retrieves the specified locale (or the current locale if no locale identifier is specified).
Signature
get(locale?: string): ILocale
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | string | Yes | Specifies the ISO 639-1 language code to retrieve. |
Return value
Returns the ILocale
object. This method will always return a locale object. If no locales are loaded, the built-in en
locale will return.
🔧 getDomain
Retrieves domain information for the specified locale (or the current locale if no locale identifier is specified).
Signature
getDomain(locale?: string): IDomain
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | string | Yes | Specifies the ISO 639-1 language domain. |
Return value
Returns an IDomain
object with domain info.
🔧 isLoaded
Verifies if the specified locale is loaded.
Signature
isLoaded(locale: string): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | string | No | Specifies the ISO 639-1 language code to verify. |
Return value
Returns true
if the locale is loaded.
🔧 load
Loads the specified locale profiles.
Locale information is stored in a JSON file per locale and are stored in the runner/locales folder of each stock runner package.
Signature
load(locale: ILocale | ILocale[], makeActive?: boolean): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | ILocale | ILocale[] | No |
makeActive | boolean | Yes | Specifies if the locale needs to be selected as the current active locale (default is true , but only when a single locale is supplied). |
Return value
Returns true
if the locale data is successfully loaded.
🔧 number
Formats a number to a localized string by inserting thousands and decimal separators while taking rounding into account.
Signature
number(
n: number | string,
precision?: number | "auto",
thousands?: boolean,
locale?: string
): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
n | number | string | No | Specifies the number to format. |
precision | number | "auto" | Yes | Specifies the precision (set it to auto to allow floating point numbers with automatic precision detection). |
thousands | boolean | Yes | Specifies if thousands separators should be inserted (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted number as a localized string.
🔧 set
Sets the current active locale.
Make sure to load the locale first with the locale
method.
Signature
set(locale: string): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | string | No | Specifies the ISO 639-1 language code to set. |
Return value
Returns true
if the locale is set.
🔧 timeFull
Formats to a localized full time string (for example, 4:39:45 PM
).
Signature
timeFull(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized time string.
🔧 timeLong
Formats to a localized long time string (for example, 4:39:18 PM
).
Signature
timeLong(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized time string.
🔧 timeMedium
Formats to a localized medium time string (for example, 4:39:08 PM
).
Signature
timeMedium(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized time string.
🔧 timeShort
Formats to a localized short time string (for example, 4:38 PM
).
Signature
timeShort(time?: number, UTC?: boolean, locale?: string): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
locale | string | Yes | Specifies the locale to use. If omitted the current active locale will be used. |
Return value
Returns the formatted localized time string.
🗃️ Fields
🏷️ country
Retrieves the country for the current active locale.
Type
string
🏷️ countryCode
Retrieves the country code for the current active locale.
Type
string
🏷️ countryNative
Retrieves the native country name for the current active locale.
Type
string
🏷️ direction
Retrieves the text direction for the current active locale.
Type
"ltr" | "rtl"
🏷️ domain
Retrieves the domain for the current locale.
Type
string
🏷️ identifier
Retrieves the locale identifier string.
Type
string
🏷️ language
Retrieves the language for the current active locale.
Type
string
🏷️ languageNative
Retrieves the language in the native language for the current active locale.
Type
string
🏷️ locale
Retrieves the locale information for the current active locale.
Type
▶️ Methods
🔧 dateFull
Formats to a localized full date string (for example, Wednesday, March 23, 2022
).
Signature
dateFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateLong
Formats to a localized long date string (for example, March 23, 2022
).
Signature
dateLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateMedium
Formats to a localized medium date string (for example, Mar 23, 2022
).
Signature
dateMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateShort
Formats to a localized short date string (for example, 3/23/22
).
Signature
dateShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateTime
Formats a date/time to a localized string.
Signature
dateTime(format: string, time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
format | string | No | Specifies the format to use, using the CLDR date/time formatting style. The following variables are available: - y / yyyy : Specifies the full 4-digit year;- yy : Specifies the 2-digit year;- M : Specifies the month number;- MM : Specifies the month number with a minimum of 2 digits;- MMM : Specifies the month as an abbreviated string (e.g. Jan );- MMMM : Specifies the month as a full string (e.g. January );- MMMMM : Specifies the month as a narrow (e.g. J );- LLL : Specifies the month as an abbreviated nominative string (e.g. Jan );- LLLL : Specifies the month as a full nominative string (e.g. January );- LLLLL : Specifies the month as a narrow nominative string (e.g. J );- d : Specifies the day of the month;- dd : Specifies the day of the month with a minimum of 2 digits;- E : Specifies the day of the week;- EE : Specifies the day of the week as a string (e.g. Su );- EEE : Specifies the day of the week as an abbreviated string (e.g. Sun );- EEEE : Specifies the day of the week as a full string (e.g. Sunday );- EEEEE : Specifies the day of the week as a narrow string (e.g. S );- cc : Specifies the day of the week as a nominative string (e.g. Su );- ccc : Specifies the day of the week as an abbreviated nominative string (e.g. Sun );- cccc : Specifies the day of the week as a full nominative string (e.g. Sunday );- ccccc : Specifies the day of the week as a narrow nominative string (e.g. S );- H : Specifies the number of hours in 24-hour format;- HH : Specifies the number of hours in 24-hour format with a minimum of 2 digits;- h : Specifies the number of hours in 12-hour format;- hh : Specifies the number of hours in 12-hour format with a minimum of 2 digits;- a : Specifies the AM or PM hour suffix;- m : Specifies the number of minutes;- mm : Specifies the number of minutes with a minimum of 2 digits;- s : Specifies the number of seconds;- ss : Specifies the number of seconds with a minimum of 2 digits;- S : Specifies the number of milliseconds;- SSS : Specifies the number of milliseconds with a minimum of 3 digits. |
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateTimeFull
Formats to a localized full date/time string (for example, Wednesday, March 23, 2022 at 4:38:47 PM
).
Signature
dateTimeFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeLong
Formats to a localized long date/time string (for example, March 23, 2022 at 4:38:38 PM
).
Signature
dateTimeLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeMedium
Formats to a localized medium date/time string (for example, Mar 23, 2022, 4:38:29 PM
).
Signature
dateTimeMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeShort
Formats to a localized short date/time string (for example, 3/23/22, 4:38 PM
).
Signature
dateTimeShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 load
Loads the specified locale profile.
Locale information is stored in a JSON file per locale and are stored in the runner/locales folder of each stock runner package.
Signature
load(locale: ILocale): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | ILocale | No | Specifies the locale profile to load. |
Return value
Returns true
if the locale data is successfully loaded.
🔧 number
Formats a number to a localized string by inserting thousands and decimal separators while taking rounding into account.
Signature
number(n: number | string, precision?: number | "auto", thousands?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
n | number | string | No | Specifies the number to format. |
precision | number | "auto" | Yes | Specifies the precision (set it to auto to allow floating point numbers with automatic precision detection). |
thousands | boolean | Yes | Specifies if thousands separators should be inserted (default is false ). |
Return value
Returns the formatted number as a localized string.
🔧 set
Sets the current active locale for the instance.
Make sure to load the locale first with the locale
method.
Signature
set(locale: string): boolean
Parameters
Name | Type | Optional | Description |
---|---|---|---|
locale | string | No | Specifies the ISO 639-1 language code to set. |
Return value
Returns true
if the locale is set.
🔧 timeFull
Formats to a localized full time string (for example, 4:39:45 PM
).
Signature
timeFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeLong
Formats to a localized long time string (for example, 4:39:18 PM
).
Signature
timeLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeMedium
Formats to a localized medium time string (for example, 4:39:08 PM
).
Signature
timeMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeShort
Formats to a localized short time string (for example, 4:38 PM
).
Signature
timeShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.