harmony 鸿蒙Language and Locale Name Localization

  • 2025-06-12
  • 浏览 (4)

Language and Locale Name Localization

Use Cases

Language and locale name localization means to localize language and locale names on the UI based on local language habits. For example, Simplified Chinese and English are used in an English environment while 简体中文 and 英文 are used in a Chinese environment.

How to Develop

For details about the APIs, see getDisplayCountry and getDisplayLanguage.

  1. Import the i18n module.

    import { i18n } from '@kit.LocalizationKit';
    
  2. Localize language names. Language names can be localized into representations in different languages. The following uses German as an example:

    let displayLanguage: string = i18n.System.getDisplayLanguage('de', 'zh-Hans-CN'); // displayLanguage = 'German'
    // language: two-letter language code, for example, zh, de, or fr.
    // locale: locale ID, for example, en-GB, en-US, or zh-Hans-CN.
    // sentenceCase: whether the first letter of the language name needs to be capitalized. The default value is true.
    
  3. Localize country/region names. Country/region names can be localized into representations in different languages. The following uses Saudi Arabia as an example:

    let displayCountry: string = i18n.System.getDisplayCountry('SA', 'en-GB'); // displayCountry = 'Saudi Arabia'
    // country: two-letter country/region code, for example, CN, DE, or SA.
    // locale: locale ID, for example, en-GB, en-US, or zh-Hans-CN.
    // sentenceCase: whether the first letter of the country/region name needs to be capitalized. The default value is true.
    

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Localization Kit

harmony 鸿蒙Calendar Setting

harmony 鸿蒙Character Processing

harmony 鸿蒙Overview

harmony 鸿蒙DST Transition

harmony 鸿蒙Overview of Internationalization and Localization

harmony 鸿蒙Locale ID and Cultural Habit Division

harmony 鸿蒙Number and Unit of Measurement Formatting

harmony 鸿蒙Phone Number Formatting

harmony 鸿蒙Preferred Language Setting

0  赞