1# Locale and Cultural Habit Division
2
3
4## Use Cases
5
6In a broad sense, a locale uniquely identifies a specific geographical region by using digits, letters, symbols, or their combinations.
7
8Regarding internationalization, a locale is an abstraction of a user group, including the user language, script (for example, simplified Chinese or traditional Chinese), country/region, and other cultural habits (for example, calendar and numeral system). Locales are the basis for an application to implement internationalization capabilities.
9
10
11## How It Works
12
13A locale consists of four parts: language, script, country/region, and extended parameters. The language is mandatory. For details, see Table 1. For supported extended parameters, see Table 2. For numeral systems corresponding to different languages, see Table 3. The Arabic numeral system is used for languages that are not listed in the table by default.
14
15**Table 1** Description of the locale
16
17| Part| Description|
18| -------- | -------- |
19| Language| Language used by the user. The value consists of two or three lowercase letters. For example, **zh** indicates Chinese.<br>For more language codes, see the ISO-639 standard.|
20| Script| Character set used by the user. The value consists of four letters with the first letter being capitalized. For example, **Hans** indicates simplified Chinese.<br>For more script codes, see the ISO-15924 standard.|
21| Country/region| Country/region where the user is located. The value consists of two uppercase letters. For example, **CN** indicates China.<br>For more country/region codes, see the ISO-3166 standard.|
22| Extensions| Extended parameters that indicate other features of the user, including the calendar, string collation, numeral system, and hour cycle. The value starts with a lowercase letter **u**. Each extended parameter consists of a key and a value, which are separated using a hyphen (-). For example, **u-ca-chinese-co-pinyin** means collation by lunar calendar and pinyin.<br>For supported extended parameters, see Table 2. For more extended parameters, see BCP 47 Extensions.|
23
24**Table 2** Supported extended parameters
25
26| Parameter| Description|
27| -------- | -------- |
28| ca | Calendar system used by the user. For example, **chinese** indicates the lunar calendar.|
29| co | String collation rule used by the user. For example, **pinyin** means collation by Pinyin.|
30| hc | Hour cycle used by the user. For example, **h11** indicates the hour cycle from 0 to 11.|
31| nu | Numeral system used by the user. For example, **arab** indicates the Arabic numeral system. For details, see Table 3.|
32| kn | Processing specific to digits during collation.<br>- **true**: Digits are treated as a whole.<br>- **false**: Digits are treated as common characters.|
33| kf | Processing specific to case capitalization during collation.<br>- **upper**: Uppercase letters are placed in the front.<br>- **lower**: Lowercase letters are placed in the front.<br>- **false**: The default value of the current locale is used.|
34
35**Table 3** Languages and numeral systems
36
37| Language| Numeral System|
38| -------- | -------- |
39| ar | arab |
40| as | beng |
41| bn | beng |
42| fa | arabext |
43| mr | deva |
44| my | mymr |
45| ne | deva |
46| ur | latn |
47| Others| arab |
48
49
50## How to Develop
51
52The following uses date and time formatting as an example. For details about APIs, see [getPluralStringValueSync](../reference/apis-localization-kit/js-apis-resource-manager.md#getpluralstringvaluesync10).
53
541. Import the **intl** module.
55   ```ts
56   import { intl } from '@kit.LocalizationKit';
57   ```
58
592. Create a **Locale** object. Three methods are provided:
60   - According to the format provided in [How It Works](#how-it-works), pass in the locale string to the **Locale** constructor to create a **Locale** object.
61   - Configure locale features in **LocaleOptions**, and then use the locale string and **LocaleOptions** to create a **Locale** object. The attributes configured in **LocaleOptions** automatically overwrite the corresponding attributes in the locale string.
62   - Use the default **Locale** constructor to create a **Locale** object. This object will be used to represent the current system locale.
63
64   ```ts
65   let date = new Date(2023, 9, 15);
66
67   // Method 1: Create a Locale object using the locale string.
68   let zhLocale = new intl.Locale("zh-Hans-CN-u-nu-latn");
69
70   // Method 2: Create a Locale object using the locale string and LocaleOptions.
71   let enLocale = new intl.Locale("en", {numberingSystem: "latn"});
72
73   // Method 3: Create a Locale object using the default Locale constructor.
74   let systemLocale = new intl.Locale();
75   ```
76
773. Format the date and time.
78   Pass the **Locale** object to the **DateTimeFormat** constructor to create a **DateTimeFormat** class to implement date and time formatting for the locale. Similarly, three methods are provided.
79
80   ```ts
81   // Method 1
82   let zhDateTimeFmt = new intl.DateTimeFormat(zhLocale.toString());
83   let result = zhDateTimeFmt.format(date); // result = "2023/10/15"
84
85   // Method 2
86   let enDateTimeFmt = new intl.DateTimeFormat(enLocale.toString());
87   result = enDateTimeFmt.format(date); // result = "10/15/23"
88
89   // Method 3
90   let systemDateTimeFmt = new intl.DateTimeFormat(systemLocale.toString());
91   result = systemDateTimeFmt.format(date); // result = "2023/10/15" (The display effect depends on the current system environment.)
92   ```
93