js-apis-system-configuration.md 1.8 KB
Newer Older
Z
zengyawen 已提交
1 2
# Application Configuration

S
shawn_he 已提交
3 4
> **NOTE**<br>
> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.i18n`](js-apis-i18n.md) and [`@ohos.intl`](js-apis-intl.md) instead.
Z
zengyawen 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
>
> 
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.


## Modules to Import


```
import configuration from '@system.configuration';
```


## configuration.getLocale

S
shawn_he 已提交
20
static getLocale(): LocaleResponse
Z
zengyawen 已提交
21 22 23 24 25

Obtains the current locale of the application, which is the same as the system locale.

**System capability**: SystemCapability.ArkUI.ArkUI.Lite

S
shawn_he 已提交
26 27 28 29
**Return value**
| Type           | Description           |
| -------------- | ------------- |
| LocaleResponse | Current locale information.|
Z
zengyawen 已提交
30 31

**Example**
S
shawn_he 已提交
32 33 34 35 36 37
  ```
  export default {    
    getLocale() {        
      const localeInfo = configuration.getLocale();        
      console.info(localeInfo.language);    
    }
Z
zengyawen 已提交
38
  }
S
shawn_he 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  ```


## LocaleResponse

Defines attributes of the current locale.

**System capability**: SystemCapability.ArkUI.ArkUI.Lite

| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
| language | string | Yes   | No   | Language, for example, **zh**.|
| countryOrRegion | string | Yes   | No   | Country or region, for example, **CN** or **US**.|
| dir | string | Yes   | No   | Text layout direction. The value can be:<br>- **ltr**: from left to right<br>- **rtl**: from right to left|
| unicodeSetting<sup>5+</sup> | string | Yes   | No   | Unicode language key set determined by the locale. If current locale does not have a specific key set, an empty set is returned.<br>For example, **{"nu":"arab"}** indicates that current locale uses Arabic numerals.|