We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesApplication FrameworkArkUIArkTS APIDeprecated APIs@system.configuration (Application Configuration)

@system.configuration (Application Configuration)

Phone12+PC/2in113+Tablet12+TV19+Wearable18+Lite Wearable12+
NOTE
  • The APIs of this module are deprecated since API version 7. You are advised to use @ohos.i18n and @ohos.intl instead.

  • 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

Collapse
Word wrap
Dark theme
Copy code
  1. import Configuration from '@system.configuration';

configuration.getLocale

Phone12+PC/2in113+Tablet12+TV19+Wearable18+Lite Wearable12+

static getLocale(): LocaleResponse

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

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Lite

Return value

Expand
Type Description
LocaleResponse Current locale information.

Example

ArkTS example:

Collapse
Word wrap
Dark theme
Copy code
  1. export default {
  2. getLocale() {
  3. const localeInfo = configuration.getLocale();
  4. console.info(localeInfo.language);
  5. }
  6. }

JS example:

Collapse
Word wrap
Dark theme
Copy code
  1. <!-- xxx.hml -->
  2. <div class="container">
  3. <text class="title" style="font-size: {{fontSize}}; color: {{fontColor}};">
  4. configuration.getLocale example
  5. </text>
  6. <div class="section">
  7. <text class="section-title">Language Settings:</text>
  8. <div class="info-item">
  9. <text class="value">{{language}}</text>
  10. </div>
  11. </div>
  12. <div class="section">
  13. <text class="section-title">Region Settings:</text>
  14. <div class="info-item">
  15. <text class="value">{{countryOrRegion}}</text>
  16. </div>
  17. </div>
  18. <div class="section">
  19. <text class="section-title">Layout direction:</text>
  20. <div class="info-item">
  21. <text class="value">{{dir}}</text>
  22. </div>
  23. </div>
  24. <input type="button" value="Refresh configuration" style="width: 350px; height: 50px; margin: 5px;" onclick="getLocaleInfo"></input>
  25. </div>
Collapse
Word wrap
Dark theme
Copy code
  1. /* xxx.css */
  2. .container {
  3. display: flex;
  4. flex-direction: column;
  5. align-items: center;
  6. left: 0px;
  7. top: 0px;
  8. width: 454px;
  9. height: 454px;
  10. background-color: #000000;
  11. }
  12. .title {
  13. font-size: 24px;
  14. text-align: center;
  15. width: 320px;
  16. height: 100px;
  17. margin-top: 40px;
  18. color: #ffffff;
  19. }
  20. .section {
  21. width: 400px;
  22. height: 60px;
  23. padding: 15px;
  24. background-color: #1a1a1a;
  25. border-radius: 10px;
  26. }
  27. .section-title {
  28. font-size: 24px;
  29. color: #007dff;
  30. height: 35px;
  31. margin-bottom: 10px;
  32. }
  33. .info-item {
  34. width: 100%;
  35. height: 35px;
  36. }
  37. .label {
  38. font-size: 24px;
  39. height: 40px;
  40. color: #aaaaaa;
  41. }
  42. .value {
  43. font-size: 24px;
  44. height: 40px;
  45. color: #ffffff;
  46. }
Collapse
Word wrap
Dark theme
Copy code
  1. // xxx.js
  2. import configuration from '@system.configuration';
  3. export default {
  4. data: {
  5. fontSize: '28px',
  6. fontColor: '#ffffff',
  7. language: '',
  8. countryOrRegion: '',
  9. dir: '',
  10. displayLanguage: '',
  11. displayRegion: '',
  12. displayDir: ''
  13. },
  14. onInit() {
  15. this.getLocaleInfo();
  16. },
  17. getLocaleInfo() {
  18. try {
  19. const localeInfo = configuration.getLocale();
  20. console.info('configuration.getLocale success');
  21. console.info('language: ' + localeInfo.language);
  22. console.info('countryOrRegion: ' + localeInfo.countryOrRegion);
  23. console.info('dir: ' + localeInfo.dir);
  24. this.language = localeInfo.language || 'Unknown';
  25. this.countryOrRegion = localeInfo.countryOrRegion || 'Unknown';
  26. this.dir = localeInfo.dir || 'Unknown';
  27. this.displayLanguage = this.getDisplayLanguage(this.language);
  28. this.displayRegion = this.getDisplayRegion(this.countryOrRegion);
  29. this.displayDir = this.getDisplayDirection(this.dir);
  30. } catch (error) {
  31. console.error('configuration.getLocale failed: ' + error.message);
  32. this.language = 'Failed';
  33. this.countryOrRegion = 'Failed';
  34. this.dir = 'Failed';
  35. this.displayLanguage = 'Failed';
  36. this.displayRegion = 'Failed';
  37. this.displayDir = 'Failed';
  38. }
  39. },
  40. getDisplayLanguage(language) {
  41. const map = {
  42. 'zh': 'Chinese',
  43. 'en': 'English',
  44. 'ja': 'Japanese',
  45. 'ko': 'Korean'
  46. };
  47. return map[language] || language;
  48. },
  49. getDisplayRegion(region) {
  50. const map = {
  51. 'CN': 'China',
  52. 'US': 'United States',
  53. 'JP': 'Japan',
  54. 'KR': 'South Korea'
  55. };
  56. return map[region] || region;
  57. },
  58. getDisplayDirection(dir) {
  59. if (dir === 'ltr') {
  60. return 'Left to Right';
  61. } else if (dir === 'rtl') {
  62. return 'Right to Left';
  63. }
  64. return dir;
  65. }
  66. }

LocaleResponse

Phone12+PC/2in113+Tablet12+TV19+Wearable18+Lite Wearable12+

Defines attributes of the current locale.

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Lite

Expand
Name Type Readable Writable Description
language string Yes No Language, for example, zh.
countryOrRegion string Yes No Country or region, for example, CN.
dir string Yes No

Text layout direction. Available values are as follows:

- ltr: from left to right

- rtl: from right to left