国际化(I18n)

说明: 从 API Version 7 开始支持。

导入模块

import i18n from '@ohos.i18n';

权限

i18n.getDisplayLanguage

getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string

获取指定语言的本地化显示文本。

  • 参数:

    参数名

    类型

    必填

    说明

    language

    string

    指定语言

    locale

    string

    显示指定语言的区域ID

    sentenceCase

    boolean

    本地化显示文本是否要首字母大写

  • 返回值:

    类型

    说明

    string

    指定语言的本地化显示文本

  • 示例:

    i18n.getDisplayLanguage("zh", "en-GB", true);
    i18n.getDisplayLanguage("zh", "en-GB");
    

i18n.getDisplayCountry

getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string

获取指定国家的本地化显示文本。

  • 参数:

    参数名

    类型

    必填

    说明

    country

    string

    指定国家

    locale

    string

    显示指定国家的区域ID

    sentenceCase

    boolean

    本地化显示文本是否要首字母大写

  • 返回值:

    类型

    说明

    string

    指定国家的本地化显示文本

  • 示例:

    i18n.getDisplayCountry("zh-CN", "en-GB", true);
    i18n.getDisplayCountry("zh-CN", "en-GB");
    

i18n.getSystemLanugage

getSystemLanguage(): string

获取系统语言。

  • 返回值:

    类型

    说明

    string

    系统语言ID

  • 示例:

    i18n.getSystemLanguage();
    

i18n.getSystemRegion

getSystemRegion(): string

获取系统地区。

  • 返回值:

    类型

    说明

    string

    系统地区ID

  • 示例:

    i18n.getSystemRegion();
    

i18n.getSystemLocale

getSystemLocale(): string

获取系统区域。

  • 返回值:

    类型

    说明

    string

    系统区域ID

  • 示例:

    i18n.getSystemLocale();