Skip to content

Commit e509776

Browse files
authored
Reference for new Intl.Locale.p.variants (#40497)
1 parent fcd1d9c commit e509776

File tree

14 files changed

+145
-71
lines changed

14 files changed

+145
-71
lines changed

files/en-us/web/javascript/guide/internationalization/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ new Intl.SomeObject(locales, options)
4848

4949
Locales underlie all behaviors of `Intl`. A _locale_ is a set of conventions, represented in the `Intl` API by the {{jsxref("Intl.Locale")}} object. All `Intl` constructors that accept language tags also accept `Intl.Locale` objects.
5050

51-
Each locale is primarily defined by three things: a {{jsxref("Intl/Locale/language", "language")}}, a {{jsxref("Intl/Locale/script", "script")}}, and a {{jsxref("Intl/Locale/region", "region")}}. When connected together by `-` in that order, they form a [BCP 47 language tag](https://datatracker.ietf.org/doc/html/rfc5646).
51+
Each locale is primarily defined by four things: a {{jsxref("Intl/Locale/language", "language")}}, a {{jsxref("Intl/Locale/script", "script")}}, a {{jsxref("Intl/Locale/region", "region")}}, and sometimes some {{jsxref("Intl/Locale/variants", "variants")}}. When connected together by `-` in that order, they form a [BCP 47 language tag](https://datatracker.ietf.org/doc/html/rfc5646).
5252

5353
- The language is the most important part of the locale and is mandatory. When given a single language, like `en` or `fr`, there are algorithms to infer the rest of the information (see {{jsxref("Intl/Locale/maximize", "Intl.Locale.prototype.maximize()")}}).
5454
- However, you often want to specify the region as well, because conventions can differ drastically between regions that speak the same language. For example, the date format in the US is MM/DD/YYYY, whereas in the UK it is DD/MM/YYYY, so specifying `en-US` or `en-GB` is important.
5555
- You can also specify a script. The script is the writing system, or the characters used to transcribe the language. In practice, the script is often unnecessary, because the language used in a certain region is only written in one script. However, there are exceptions such as the Serbian language, which can be written in both the Latin and Cyrillic scripts (`sr-Latn` and `sr-Cyrl`), or the Chinese language, which can be written in both the Simplified and Traditional scripts (`zh-Hans` and `zh-Hant`).
56+
- The variants are rarely used. Usually, they denote different orthographies; for example, German has the `1901` and `1996` orthography variants, which are written as `de-1901` and `de-1996`.
5657

5758
```js
5859
// These two are equivalent when passed to other Intl APIs

files/en-us/web/javascript/reference/global_objects/intl/locale/basename/index.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ browser-compat: javascript.builtins.Intl.Locale.baseName
77
sidebar: jsref
88
---
99

10-
The **`baseName`** accessor property of {{jsxref("Intl.Locale")}} instances returns a substring of this locale's string representation, containing core information about this locale, including the language, and the script and region if available.
10+
The **`baseName`** accessor property of {{jsxref("Intl.Locale")}} instances returns a substring of this locale's string representation, containing core information about this locale, including the language, script, region, and variants, if available.
1111

1212
## Description
1313

@@ -17,34 +17,32 @@ The set accessor of `baseName` is `undefined`. You cannot change this property d
1717

1818
## Examples
1919

20-
### Basic Example
20+
### Basic example
2121

2222
```js
2323
const myLoc = new Intl.Locale("fr-Latn-CA"); // Sets locale to Canadian French
24-
console.log(myLoc.toString()); // Prints out "fr-Latn-CA-u-ca-gregory"
25-
console.log(myLoc.baseName); // Prints out "fr-Latn-CA"
24+
console.log(myLoc.toString()); // "fr-Latn-CA-u-ca-gregory"
25+
console.log(myLoc.baseName); // "fr-Latn-CA"
2626
```
2727

28-
### Example with options in the input string
28+
### Example with extension tags in the input string
2929

3030
```js
3131
// Sets language to Japanese, region to Japan,
32-
3332
// calendar to Gregorian, hour cycle to 24 hours
3433
const japan = new Intl.Locale("ja-JP-u-ca-gregory-hc-24");
35-
console.log(japan.toString()); // Prints out "ja-JP-u-ca-gregory-hc-h24"
36-
console.log(japan.baseName); // Prints out "ja-JP"
34+
console.log(japan.toString()); // "ja-JP-u-ca-gregory-hc-h24"
35+
console.log(japan.baseName); // "ja-JP"
3736
```
3837

3938
### Example with options that override input string
4039

4140
```js
4241
// Input string indicates language as Dutch and region as Belgium,
43-
4442
// but options object overrides the region and sets it to the Netherlands
4543
const dutch = new Intl.Locale("nl-Latn-BE", { region: "NL" });
4644

47-
console.log(dutch.baseName); // Prints out "nl-Latn-NL"
45+
console.log(dutch.baseName); // "nl-Latn-NL"
4846
```
4947

5048
## Specifications

files/en-us/web/javascript/reference/global_objects/intl/locale/calendar/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The **`calendar`** accessor property of {{jsxref("Intl.Locale")}} instances retu
1111

1212
## Description
1313

14-
While most of the world uses the Gregorian calendar, there are several regional calendar eras used around the world. The `calendar` property's value is set at construction time, either through the `ca` key of the locale identifier or through the `calendar` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
14+
While most of the world uses the Gregorian calendar, there are several regional calendar eras used around the world. For a list of supported calendar types, see [`Intl.supportedValuesOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf#supported_calendar_types).
1515

16-
For a list of supported calendar types, see [`Intl.supportedValuesOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf#supported_calendar_types).
16+
The `calendar` property's value is set at construction time, either through the `ca` key of the locale identifier or through the `calendar` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
1717

1818
The set accessor of `calendar` is `undefined`. You cannot change this property directly.
1919

@@ -23,11 +23,11 @@ Like other locale subtags, the calendar type can be added to the {{jsxref("Intl.
2323

2424
### Adding a calendar type via the locale string
2525

26-
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), calendar era types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the `-u` extension. Thus, the calendar era type can be added to the initial locale identifier string that is passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. To add the calendar type, first add the `-u` extension to the string. Next, add the `-ca` extension to indicate that you are adding a calendar type. Finally, add the calendar era type to the string.
26+
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), `calendar` is an "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers using the `-u` extension key. To add the calendar type to the initial locale identifier string passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor, first add the `-u` extension key if it doesn't exist. Next, add the `-ca` extension to indicate that you are adding a calendar type. Finally, add the calendar era type.
2727

2828
```js
2929
const locale = new Intl.Locale("fr-FR-u-ca-buddhist");
30-
console.log(locale.calendar); // Prints "buddhist"
30+
console.log(locale.calendar); // "buddhist"
3131
```
3232

3333
### Adding a calendar type via the configuration object argument

files/en-us/web/javascript/reference/global_objects/intl/locale/casefirst/index.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@ The **`caseFirst`** accessor property of {{jsxref("Intl.Locale")}} instances ret
1111

1212
## Description
1313

14-
A locale's collation rules are used to determine how strings are ordered in that locale. Certain locales use a character's case (UPPERCASE or lowercase) in the collation process. This additional rule can be expressed in a {{jsxref("Intl.Locale")}} object's `caseFirst` property.
15-
16-
There are 3 values that the `caseFirst` property can have, outlined in the table below.
17-
18-
### `caseFirst` values
14+
A locale's collation rules are used to determine how strings are ordered in that locale. Certain locales use a character's case (UPPERCASE or lowercase) in the collation process. This additional rule can be expressed in a {{jsxref("Intl.Locale")}} object's `caseFirst` property. There are 3 values that the `caseFirst` property can have, outlined in the table below.
1915

2016
| Value | Description |
2117
| ------- | ------------------------------------------ |
2218
| `upper` | Upper case to be sorted before lower case. |
2319
| `lower` | Lower case to be sorted before upper case. |
2420
| `false` | No special case ordering. |
2521

22+
The `caseFirst` property's value is set at construction time, either through the `kf` key of the locale identifier or through the `caseFirst` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
23+
24+
The set accessor of `caseFirst` is `undefined`. You cannot change this property directly.
25+
2626
## Examples
2727

28-
### Setting the caseFirst value via the locale string
28+
Like other locale subtags, the `caseFirst` value can be added to the {{jsxref("Intl.Locale")}} object via the locale string, or a configuration object argument to the constructor.
29+
30+
### Adding a caseFirst value via the locale string
2931

30-
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), the values that `caseFirst` represents correspond to the key `kf`. `kf` is treated as a locale string "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers by using the `-u` extension key. Thus, the `caseFirst` value can be added to the initial locale identifier string that is passed into the `Locale` constructor. To add the `caseFirst` value, first add the `-u` extension key to the string. Next, add the `-kf` extension key to indicate that you are adding a value for `caseFirst`. Finally, add the `caseFirst` value to the string.
32+
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), `caseFirst` is an "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers using the `-u` extension key. To add the `caseFirst` value to the initial locale identifier string passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor, first add the `-u` extension key if it doesn't exist. Next, add the `-kf` extension to indicate that you are adding a value for `caseFirst`. Finally, add the `caseFirst` value.
3133

3234
```js
3335
const locale = new Intl.Locale("fr-Latn-FR-u-kf-upper");
34-
console.log(locale.caseFirst); // Prints "upper"
36+
console.log(locale.caseFirst); // "upper"
3537
```
3638

37-
### Setting the caseFirst value via the configuration object argument
39+
### Adding a caseFirst value via the configuration object argument
3840

39-
The {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor has an optional configuration object argument, which can be used to pass extension types. Set the `caseFirst` property of the configuration object to your desired `caseFirst` value, and then pass it into the constructor.
41+
The {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor has an optional configuration object argument, which can contain any of several extension types, including `caseFirst`. Set the `caseFirst` property of the configuration object to your desired `caseFirst` value, and then pass it into the constructor.
4042

4143
```js
4244
const locale = new Intl.Locale("en-Latn-US", { caseFirst: "lower" });
43-
console.log(locale.caseFirst); // Prints "lower"
45+
console.log(locale.caseFirst); // "lower"
4446
```
4547

4648
## Specifications

files/en-us/web/javascript/reference/global_objects/intl/locale/collation/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The **`collation`** accessor property of {{jsxref("Intl.Locale")}} instances ret
1111

1212
## Description
1313

14-
Collation is the process of ordering strings of characters. It is used whenever strings must be sorted and placed into a certain order, from search query results to ordering records in a database. While the idea of placing strings in order might seem trivial, the idea of order can vary from region to region and language to language. The `collation` property's value is set at construction time, either through the `co` key of the locale identifier or through the `collation` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
14+
Collation is the process of ordering strings of characters. It is used whenever strings must be sorted and placed into a certain order, from search query results to ordering records in a database. While the idea of placing strings in order might seem trivial, the idea of order can vary from region to region and language to language. For a list of supported collation types, see [`Intl.supportedValuesOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf#supported_collation_types).
1515

16-
For a list of supported collation types, see [`Intl.supportedValuesOf()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/supportedValuesOf#supported_collation_types).
16+
The `collation` property's value is set at construction time, either through the `co` key of the locale identifier or through the `collation` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
1717

1818
The set accessor of `collation` is `undefined`. You cannot change this property directly.
1919

@@ -23,7 +23,7 @@ Like other locale subtags, the collation type can be added to the {{jsxref("Intl
2323

2424
### Adding a collation type via the locale string
2525

26-
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), collation types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the `-u` extension. Thus, the collation type can be added to the initial locale identifier string that is passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. To add the collation type, first add the `-u` extension to the string. Next, add the `-co` extension to indicate that you are adding a collation type. Finally, add the collation type to the string.
26+
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), `collation` is an "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers using the `-u` extension key. To add the collation type to the initial locale identifier string passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor, first add the `-u` extension key if it doesn't exist. Next, add the `-co` extension to indicate that you are adding a collation type. Finally, add the collation type.
2727

2828
```js
2929
const locale = new Intl.Locale("zh-Hant-u-co-zhuyin");

files/en-us/web/javascript/reference/global_objects/intl/locale/hourcycle/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The **`hourCycle`** accessor property of {{jsxref("Intl.Locale")}} instances ret
1111

1212
## Description
1313

14-
There are 2 main types of time keeping conventions (clocks) used around the world: the 12 hour clock and the 24 hour clock. The `hourCycle` property's value is set at construction time, either through the `hc` key of the locale identifier or through the `hourCycle` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
14+
There are 2 main types of time keeping conventions (clocks) used around the world: the 12 hour clock and the 24 hour clock. For a list of supported hour cycle types, see [`Intl.Locale.prototype.getHourCycles()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles#supported_hour_cycle_types).
1515

16-
For a list of supported hour cycle types, see [`Intl.Locale.prototype.getHourCycles()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getHourCycles#supported_hour_cycle_types).
16+
The `hourCycle` property's value is set at construction time, either through the `hc` key of the locale identifier or through the `hourCycle` option of the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. The latter takes priority if they are both present; and if neither is present, the property has value `undefined`.
1717

1818
The set accessor of `hourCycle` is `undefined`. You cannot change this property directly.
1919

@@ -23,7 +23,7 @@ Like other locale subtags, the hour cycle type can be added to the {{jsxref("Int
2323

2424
### Adding an hour cycle via the locale string
2525

26-
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), hour cycle types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the `-u` extension. Thus, the hour cycle type can be added to the initial locale identifier string that is passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor. To add the hour cycle type, first add the `-u` extension key to the string. Next, add the `-hc` extension to indicate that you are adding an hour cycle. Finally, add the hour cycle type to the string.
26+
In the [Unicode locale string spec](https://www.unicode.org/reports/tr35/), `hourCycle` is an "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers using the `-u` extension key. To add the hour cycle type to the initial locale identifier string passed into the {{jsxref("Intl/Locale/Locale", "Intl.Locale()")}} constructor, first add the `-u` extension key if it doesn't exist. Next, add the `-hc` extension to indicate that you are adding an hour cycle. Finally, add the hour cycle type.
2727

2828
```js
2929
const locale = new Intl.Locale("fr-FR-u-hc-h23");

0 commit comments

Comments
 (0)