harmony 鸿蒙@ohos.i18n (Internationalization)

2022-08-09 浏览 (1381)

@ohos.i18n (Internationalization)

This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. The intl module provides basic i18n capabilities through the standard i18n APIs defined in ECMA 402. It works with the i18n module to provide a complete suite of i18n capabilities.

NOTE

  • The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

  • This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see intl.

Modules to Import

import I18n from '@ohos.i18n';

System9+

getDisplayCountry9+

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

Obtains the localized script for the specified country.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
countrystringYesSpecified country.
localestringYesLocale ID.
sentenceCasebooleanNoWhether to use sentence case for the localized script. The default value is true.

Return value

TypeDescription
stringLocalized script for the specified country.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
    let displayCountry: string = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China"
} catch (error) {
    let err: BusinessError = error as BusinessError;
    console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`);
}

getDisplayLanguage9+

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

Obtains the localized script for the specified language.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesSpecified language.
localestringYesLocale ID.
sentenceCasebooleanNoWhether to use sentence case for the localized script. The default value is true.

Return value

TypeDescription
stringLocalized script for the specified language.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  let displayLanguage: string = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getDisplayLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

getSystemLanguages9+

static getSystemLanguages(): Array<string>

Obtains the list of system languages. For details about languages, see Instantiating the Locale Object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>List of the IDs of system languages.

Example

import { BusinessError } from '@ohos.base';

try {
  let systemLanguages: Array<string> = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ]
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getSystemLanguages failed, error code: ${err.code}, message: ${err.message}.`);
}

getSystemCountries9+

static getSystemCountries(language: string): Array<string>

Obtains the list of countries and regions supported for the specified language. For details about countries or regions, see Instantiating the Locale Object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesLanguage ID.

Return value

TypeDescription
Array<string>List of the IDs of the countries and regions supported for the specified language.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  let systemCountries: Array<string> = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getSystemCountries failed, error code: ${err.code}, message: ${err.message}.`);
}

isSuggested9+

static isSuggested(language: string, region?: string): boolean

Checks whether the system language matches the specified region.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesValid language ID, for example, zh.
regionstringNoValid region ID, for example, CN. The default value is the country or region where the SIM card is used.

Return value

TypeDescription
booleanThe value true indicates that the system language matches the specified region, and the value false indicates the opposite.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  let res: boolean = I18n.System.isSuggested('zh', 'CN');  // res = true
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.isSuggested failed, error code: ${err.code}, message: ${err.message}.`);
}

getSystemLanguage9+

static getSystemLanguage(): string

Obtains the system language. For details about languages, see Instantiating the Locale Object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem language ID.

Example

import { BusinessError } from '@ohos.base';

try {
  let systemLanguage: string = I18n.System.getSystemLanguage();  // systemLanguage indicates the current system language.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

setSystemLanguage9+

static setSystemLanguage(language: string): void

Sets the system language. Currently, this API does not support real-time updating of the system language.

To listen for common_event_locale_changed events after the system language is set, you need to add an event subscriber.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesLanguage ID.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';
import CommonEventManager from '@ohos.commonEventManager';

// Set the system language
try {
  I18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.setSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

// Subscribe to a common event.
let subscriber: CommonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
let subscribeInfo: CommonEventManager.CommonEventSubscribeInfo = { // Define the subscriber information.
  events: [CommonEventManager.Support.COMMON_EVENT_LOCALE_CHANGED]
};
CommonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { // Create a subscriber.
    console.info("createSubscriber");
    subscriber = commonEventSubscriber;
    CommonEventManager.subscribe(subscriber, (err, data) => {
      if (err) {
        console.error(`Failed to subscribe common event. error code: ${err.code}, message: ${err.message}.`);
        return;
      }
      console.info("the subscribed event has occurred."); // Triggered when the subscribed event occurs.
    })
}).catch((err: BusinessError) => {
    console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`);
});  

getSystemRegion9+

static getSystemRegion(): string

Obtains the system region. For details about system regions, see Instantiating the Locale Object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem region ID.

Example

import { BusinessError } from '@ohos.base';

try {
  let systemRegion: string = I18n.System.getSystemRegion(); // Obtain the current system region.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
}

setSystemRegion9+

static setSystemRegion(region: string): void

Sets the system region.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
regionstringYesSystem region ID.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  I18n.System.setSystemRegion('CN'); // Set the current system region to CN.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.setSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
}

getSystemLocale9+

static getSystemLocale(): string

Obtains the system locale. For details about system locales, see Instantiating the Locale Object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem locale ID.

Example

import { BusinessError } from '@ohos.base';

try {
  let systemLocale: string = I18n.System.getSystemLocale();  // Obtain the current system locale.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
}

setSystemLocale9+

static setSystemLocale(locale: string): void

Sets the system locale.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesSystem locale ID, for example, zh-CN.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.setSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
}

is24HourClock9+

static is24HourClock(): boolean

Checks whether the 24-hour clock is used.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
booleanThe value true indicates that the 24-hour clock is used, and the value false indicates the opposite.

Example

import { BusinessError } from '@ohos.base';

try {
  let is24HourClock: boolean = I18n.System.is24HourClock();  // Check whether the 24-hour clock is enabled.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.is24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
}

set24HourClock9+

static set24HourClock(option: boolean): void

Sets the system time to the 24-hour clock.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
optionbooleanYesWhether to enable the 24-hour clock. The value true means to enable the 24-hour clock, and the value false means the opposite.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

// Set the system time to the 24-hour clock.
try {
  I18n.System.set24HourClock(true);
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
}

addPreferredLanguage9+

static addPreferredLanguage(language: string, index?: number): void

Adds a preferred language to the specified position on the preferred language list.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesPreferred language to add.
indexnumberNoPosition to which the preferred language is added. The default value is the length of the preferred language list.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

// Add zh-CN to the preferred language list.
let language = 'zh-CN';
let index = 0;
try {
  I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.addPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

removePreferredLanguage9+

static removePreferredLanguage(index: number): void

Deletes a preferred language from the specified position on the preferred language list.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
indexnumberYesPosition of the preferred language to delete.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

// Delete the first preferred language from the preferred language list.
let index: number = 0;
try {
  I18n.System.removePreferredLanguage(index);
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.removePreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

getPreferredLanguageList9+

static getPreferredLanguageList(): Array<string>

Obtains the list of preferred languages.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>List of preferred languages.

Example

import { BusinessError } from '@ohos.base';

try {
  let preferredLanguageList: Array<string> = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getPreferredLanguageList failed, error code: ${err.code}, message: ${err.message}.`);
}

getFirstPreferredLanguage9+

static getFirstPreferredLanguage(): string

Obtains the first language in the preferred language list.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringFirst language in the preferred language list.

Example

import { BusinessError } from '@ohos.base';

try {
  let firstPreferredLanguage: string = I18n.System.getFirstPreferredLanguage();  // Obtain the first language in the preferred language list.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getFirstPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

setAppPreferredLanguage11+

static setAppPreferredLanguage(language: string): void

Sets the preferred language of the application.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesLanguage ID.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  I18n.System.setAppPreferredLanguage('zh'); // Set the current language of the application to zh.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.setAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

getAppPreferredLanguage9+

static getAppPreferredLanguage(): string

Obtains the preferred language of an application.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringPreferred language of the application.

Example

import { BusinessError } from '@ohos.base';

try {
  let appPreferredLanguage: string = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
}

setUsingLocalDigit9+

static setUsingLocalDigit(flag: boolean): void

Specifies whether to enable use of local digits.

System API: This is a system API.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
flagbooleanYesWhether to turn on the local digit switch. The value true means to turn on the local digit switch, and the value false indicates the opposite.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  I18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
}

getUsingLocalDigit9+

static getUsingLocalDigit(): boolean

Checks whether use of local digits is enabled.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
booleanThe value true indicates that the local digit switch is turned on, and the value false indicates the opposite.

Example

import { BusinessError } from '@ohos.base';

try {
  let status: boolean = I18n.System.getUsingLocalDigit();  // Check whether the local digit switch is enabled.
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call System.getUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
}

I18n.isRTL7+

isRTL(locale: string): boolean

Checks whether a locale uses an RTL language.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesLocale ID.

Return value

TypeDescription
booleanThe value true indicates that the localized script is displayed from right to left, and the value false indicates the opposite.

Example

i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.

I18n.getCalendar8+

getCalendar(locale: string, type? : string): Calendar

Obtains a Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesValid locale value, for example, zh-Hans-CN.
typestringNoValid calendar type. Currently, the valid types are as follows: buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, and persian. The default value is the default calendar type of the locale.

Return value

TypeDescription
CalendarCalendar object.

Example

I18n.getCalendar("zh-Hans", "chinese"); // Obtain the Calendar object for the Chinese lunar calendar.

EntityRecognizer11+

constructor11+

constructor(locale: string)

Creates an entityRecognizer object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesLocale ID.

Example

let entityRecognizer: I18n.EntityRecognizer = new I18n.EntityRecognizer("zh-CN");

findEntityInfo11+

findEntityInfo(text: string): Array<EntityInfoItem>

Recognizes entities in text.

Parameters

NameTypeMandatoryDescription
textstringYesText for entity recognition.

Return value

TypeDescription
Array<EntityInfoItem>List of recognized entities.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

let entityRecognizer: I18n.EntityRecognizer = new I18n.EntityRecognizer("zh-CN");
let text: string = " If you have any questions, call us by phone 12345678";
let result: Array<EntityInfoItem> = entityRecognizer.findEntityInfo(text); // result[0].type = "phone_number", result[0].begin = 8, result[0].end = 19

EntityInfoItem11+

Defines an entity information object.

System capability: SystemCapability.Global.I18n

NameTypeReadableWritableDescription
typestringYesYesEntity type. Currently, only phone_number is supported.
beginnumberYesYesStart position of an entity.
endnumberYesYesEnd position of an entity.

Calendar8+

setTime8+

setTime(date: Date): void

Sets the date for this Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
dateDateYesDate to be set for the Calendar object.

Example

let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory");
let date: Date = new Date(2021, 10, 7, 8, 0, 0, 0);
calendar.setTime(date);

setTime8+

setTime(time: number): void

Sets the date and time for this Calendar object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
timenumberYesNumber of milliseconds that have elapsed since the Unix epoch.

Example

let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory");
calendar.setTime(10540800000);

set8+

set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void

Sets the year, month, day, hour, minute, and second for this Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
yearnumberYesYear to set.
monthnumberYesMonth to set.
datenumberYesDay to set.
hournumberNoHour to set. The default value is the system hour.
minutenumberNoMinute to set. The default value is the system minute.
secondnumberNoSecond to set. The default value is the system second.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00

setTimeZone8+

setTimeZone(timezone: string): void

Sets the time zone of this Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
timezonestringYesTime zone, for example, Asia/Shanghai.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.setTimeZone("Asia/Shanghai");

getTimeZone8+

getTimeZone(): string

Obtains the time zone of this Calendar object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringTime zone of the Calendar object.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.setTimeZone("Asia/Shanghai");
let timezone: string = calendar.getTimeZone(); // timezone = "Asia/Shanghai"

getFirstDayOfWeek8+

getFirstDayOfWeek(): number

Obtains the start day of a week for this Calendar object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberStart day of a week. The value 1 indicates Sunday, and the value 7 indicates Saturday.

Example

let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory");
let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1

setFirstDayOfWeek8+

setFirstDayOfWeek(value: number): void

Sets the start day of a week for this Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
valuenumberYesStart day of a week. The value 1 indicates Sunday, and the value 7 indicates Saturday.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.setFirstDayOfWeek(3);
let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3

getMinimalDaysInFirstWeek8+

getMinimalDaysInFirstWeek(): number

Obtains the minimum number of days in the first week of a year.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberMinimum number of days in the first week of a year.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1

setMinimalDaysInFirstWeek8+

setMinimalDaysInFirstWeek(value: number): void

Sets the minimum number of days in the first week of a year.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
valuenumberYesMinimum number of days in the first week of a year.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.setMinimalDaysInFirstWeek(3);
let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3

get8+

get(field: string): number

Obtains the value of the specified field in the Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
fieldstringYesValue of the specified field in the Calendar object. Currently, a valid field can be any of the following: era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, dow_local, extended_year, julian_day, milliseconds_in_day, is_leap_month.

Return value

TypeDescription
numberValue of the specified field. For example, if the year in the internal date of this Calendar object is 1990, the get("year") function will return 1990.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
let hourOfDay: number = calendar.get("hour_of_day"); // hourOfDay = 8

getDisplayName8+

getDisplayName(locale: string): string

Obtains the displayed name of the Calendar object for the specified locale.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesLocale for the displayed name of the Calendar object. For example, displayed name of buddhist is Buddhist Calendar when the locale is set to en-US.

Return value

TypeDescription
stringDisplayed name of the Calendar object for the specified locale.

Example

let calendar: I18n.Calendar = I18n.getCalendar("en-US", "buddhist");
let calendarName: string = calendar.getDisplayName("zh"); // calendarName = "Buddhist Calendar"

isWeekend8+

isWeekend(date?: Date): boolean

Checks whether a given date is a weekend in the calendar.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
dateDateNoSpecified date. If this parameter is left empty, the system checks whether the current date is a weekend. The default value is the system date.

Return value

TypeDescription
booleanThe value true indicates that the specified date is a weekend, and the value false indicates the opposite.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
calendar.isWeekend(); // false
let date: Date = new Date(2011, 11, 6, 9, 0, 0);
calendar.isWeekend(date); // true

add11+

add(field: string, amount: number): void

Performs addition and subtraction operations on the specified field of the Calendar object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
fieldstringYesSpecified field of the Calendar object. The supported value year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond.
amountnumberYesAddition or subtraction amount.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
  calendar.add("year", 8); // 2021 + 8
  let year: number = calendar.get("year"); // year = 2029
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call Calendar.add failed, error code: ${err.code}, message: ${err.message}.`);
}

getTimeInMillis11+

getTimeInMillis(): number

Obtains number of milliseconds that have elapsed since the Unix epoch in the current Calendar object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberNumber of milliseconds that have elapsed since the Unix epoch.

Example

let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
calendar.setTime(5000);
let millisecond: number = calendar.getTimeInMillis(); // millisecond = 5000

compareDays11+

compareDays(date: Date): number

Compares the number of days between the calendar date and the specified date. The value is accurate to milliseconds. If the value is less than one day, it is treated as one day.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
dateDateYesSpecified date.

Return value

TypeDescription
numberNumber of days between the calendar date and the specified date. A positive number indicates that the calendar date is earlier, and a negative number indicates the opposite.

Example

import { BusinessError } from '@ohos.base';

try {
  let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans");
  calendar.setTime(5000);
  let date: Date = new Date(6000);
  let diff: number = calendar.compareDays(date); // diff = 1
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call Calendar.compareDays failed, error code: ${err.code}, message: ${err.message}.`);
}

PhoneNumberFormat8+

constructor8+

constructor(country: string, options?: PhoneNumberFormatOptions)

Creates a PhoneNumberFormat object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
countrystringYesCountry or region to which the phone number to be formatted belongs.
optionsPhoneNumberFormatOptionsNoOptions of the PhoneNumberFormat object. The default value is NATIONAL.

Example

let option: I18n.PhoneNumberFormatOptions = {type: "E164"};
let phoneNumberFormat: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN", option);

isValidNumber8+

isValidNumber(number: string): boolean

Checks whether the format of the specified phone number is valid.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
numberstringYesPhone number to be checked.

Return value

TypeDescription
booleanThe value true indicates that the phone number format is valid, and the value false indicates the opposite.

Example

let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN");
let isValidNumber: boolean = phonenumberfmt.isValidNumber("158****2312"); // isValidNumber = true

format8+

format(number: string): string

Formats a phone number.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
numberstringYesPhone number to be formatted.

Return value

TypeDescription
stringFormatted phone number.

Example

let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN");
let formattedPhoneNumber: string = phonenumberfmt.format("158****2312"); // formattedPhoneNumber = "158 **** 2312"

getLocationName9+

getLocationName(number: string, locale: string): string

Obtains the home location of a phone number.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
numberstringYesPhone number.
localestringYesLocale ID.

Return value

TypeDescription
stringHome location of the phone number.

Example

let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN");
let locationName: string = phonenumberfmt.getLocationName("158****2345", "zh-CN"); // locationName = "Zhanjiang, Guangdong Province"

PhoneNumberFormatOptions8+

Defines the options for this PhoneNumberFormat object.

System capability: SystemCapability.Global.I18n

NameTypeReadableWritableDescription
typestringYesYesFormat type of a phone number. The value can be E164, INTERNATIONAL, NATIONAL, or RFC3966.
- In API version 8, type is mandatory.
- In API version 9 or later, type is optional.

UnitInfo8+

Defines the measurement unit information.

System capability: SystemCapability.Global.I18n

NameTypeReadableWritableDescription
unitstringYesYesName of the measurement unit, for example, meter, inch, or cup.
measureSystemstringYesYesMeasurement system. The value can be SI, US, or UK.

getInstance8+

getInstance(locale?:string): IndexUtil

Creates an IndexUtil object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringNoA string containing locale information, including the language, optional script, and region. The default value is the system locale.

Return value

TypeDescription
IndexUtilIndexUtil object mapping to the locale object.

Example

let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN");

IndexUtil8+

getIndexList8+

getIndexList(): Array<string>

Obtains the index list for this locale object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>Index list for the locale object.

Example

let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN");
// indexList = [ "...", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
//              "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "..." ]
let indexList: Array<string> = indexUtil.getIndexList();

addLocale8+

addLocale(locale: string): void

Adds a locale object to the current index list.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesA string containing locale information, including the language, optional script, and region.

Example

let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN");
indexUtil.addLocale("en-US");

getIndex8+

getIndex(text: string): string

Obtains the index of a text object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
textstringYestext object whose index is to be obtained.

Return value

TypeDescription
stringIndex of the text object.

Example

let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN");
let index: string = indexUtil.getIndex("hi");  // index = "H"

I18n.getLineInstance8+

getLineInstance(locale: string): BreakIterator

Obtains a BreakIterator object for text segmentation.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesValid locale value, for example, zh-Hans-CN. The BreakIterator object segments text according to the rules of the specified locale.

Return value

TypeDescription
BreakIteratorBreakIterator object used for text segmentation.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");

BreakIterator8+

setLineBreakText8+

setLineBreakText(text: string): void

Sets the text to be processed by the BreakIterator object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
textstringYesText to be processed by the BreakIterator object.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit ."); // Set a short sentence as the text to be processed by the BreakIterator object.

getLineBreakText8+

getLineBreakText(): string

Obtains the text being processed by the BreakIterator object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringText being processed by the BreakIterator object.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let breakText: string = iterator.getLineBreakText(); // breakText = "Apple is my favorite fruit."

current8+

current(): number

Obtains the position of the BreakIterator object in the text being processed.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberPosition of the BreakIterator object in the text being processed.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let currentPos: number = iterator.current(); // currentPos = 0

first8+

first(): number

Puts the BreakIterator object to the first break point, which is always at the beginning of the processed text.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberOffset to the first break point of the processed text.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let firstPos: number = iterator.first(); // firstPos = 0

last8+

last(): number

Puts the BreakIterator object to the last break point, which is always the next position after the end of the processed text.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberOffset to the last break point of the processed text.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let lastPos: number = iterator.last(); // lastPos = 27

next8+

next(index?: number): number

Moves the BreakIterator object backward by the corresponding number of break points.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
indexnumberNoNumber of break points to be moved by the BreakIterator object. A positive value indicates that the break point is moved backward by the specified number of break points, and a negative value indicates the opposite. The default value is 1.

Return value

TypeDescription
numberPosition of the BreakIterator object in the text after it is moved by the specified number of break points. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of break points.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let pos: number = iterator.first(); // pos = 0
pos = iterator.next(); // pos = 6
pos = iterator.next(10); // pos = -1

previous8+

previous(): number

Moves the BreakIterator object forward by one break point.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberPosition of the BreakIterator object in the text after it is moved to the previous break point. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of break points.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let pos: number = iterator.first(); // pos = 0
pos = iterator.next(3); // pos = 12
pos = iterator.previous(); // pos = 9

following8+

following(offset: number): number

Moves the BreakIterator to the break point following the specified position.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
offsetnumberYesMoves the BreakIterator to the break point following the specified position.

Return value

TypeDescription
numberThe value -1 is returned if the break point to which the BreakIterator object is moved is outside of the processed text.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let pos: number = iterator.following(0); // pos = 6
pos = iterator.following(100); // pos = -1
pos = iterator.current(); // pos = 27

isBoundary8+

isBoundary(offset: number): boolean

Checks whether the specified position of the text is a break point.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
offsetnumberYesOffset to the specified position of the text. The value true is returned if the position specified by offset is a break point, and the value false is returned otherwise. If true is returned, the BreakIterator object is moved to the position specified by offset. Otherwise, following is called.

Return value

TypeDescription
booleanThe value true indicates that the position specified by the offset is a break point, and the value false indicates the opposite.

Example

let iterator: I18n.BreakIterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let isBoundary: boolean = iterator.isBoundary(0); // isBoundary = true;
isBoundary = iterator.isBoundary(5); // isBoundary = false;

I18n.getTimeZone7+

getTimeZone(zoneID?: string): TimeZone

Obtains the TimeZone object corresponding to the specified time zone ID.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
zondIDstringNoTime zone ID. The default value is the system time zone.

Return value

TypeDescription
TimeZoneTimeZone object corresponding to the time zone ID.

Example

let timezone: I18n.TimeZone = I18n.getTimeZone();

TimeZone

getID

getID(): string

Obtains the ID of the specified TimeZone object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringTime zone ID corresponding to the TimeZone object.

Example

let timezone: I18n.TimeZone = I18n.getTimeZone();
let timezoneID: string = timezone.getID(); // timezoneID = "Asia/Shanghai"

getDisplayName

getDisplayName(locale?: string, isDST?: boolean): string

Obtains the localized representation of a TimeZone object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringNoLocale ID. The default value is the system locale.
isDSTbooleanNoWhether DST is considered in the localized representation of the TimeZone object. The default value is false.

Return value

TypeDescription
stringRepresentation of the TimeZone object in the specified locale.

Example

let timezone: I18n.TimeZone = I18n.getTimeZone();
let timezoneName: string = timezone.getDisplayName("zh-CN", false); // timezoneName = "China Standard Time"

getRawOffset

getRawOffset(): number

Obtains the offset between the time zone represented by a TimeZone object and the UTC time zone.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
numberOffset between the time zone represented by the TimeZone object and the UTC time zone.

Example

let timezone: I18n.TimeZone = I18n.getTimeZone();
let offset: number = timezone.getRawOffset(); // offset = 28800000

getOffset

getOffset(date?: number): number

Obtains the offset between the time zone represented by a TimeZone object and the UTC time zone at a certain time.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
datenumberNoDate and time.

Return value

TypeDescription
numberOffset between the time zone represented by the TimeZone object and the UTC time zone at a certain time. The default value is the system time.

Example

let timezone: I18n.TimeZone = I18n.getTimeZone();
let offset: number = timezone.getOffset(1234567890); // offset = 28800000

getAvailableIDs9+

static getAvailableIDs(): Array<string>

Obtains the list of time zone IDs supported by the system.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>List of time zone IDs supported by the system.

Example

// ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 24 time zones supported in total
let ids: Array<string> = I18n.TimeZone.getAvailableIDs();

getAvailableZoneCityIDs9+

static getAvailableZoneCityIDs(): Array<string>

Obtains the list of time zone city IDs supported by the system.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>List of time zone city IDs supported by the system.

Example

// cityIDs = ["Auckland", "Magadan", "Lord Howe Island", "Tokyo", "Shanghai", "Hovd", "Omsk", "Ashgabat", "Yerevan", "Moscow", "Tel Aviv", "Dublin", "London", "Praia", "Montevideo", "Brasília", "Santiago", "Bogotá", "Easter Island", "Salt Lake City", "Los Angeles", "Anchorage", "Adak", "Pago Pago"], 24 time zone cities supported in total
let cityIDs: Array<string> = I18n.TimeZone.getAvailableZoneCityIDs();

getCityDisplayName9+

static getCityDisplayName(cityID: string, locale: string): string

Obtains the localized representation of a time zone city in the specified locale.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
cityIDstringYesTime zone city ID.
localestringYesLocale ID.

Return value

TypeDescription
stringLocalized representation of the time zone city in the specified locale.

Example

let displayName: string = I18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN"); // displayName = "Shanghai (China)"

getTimezoneFromCity9+

static getTimezoneFromCity(cityID: string): TimeZone

Obtains the TimeZone object corresponding to the specified time zone city ID.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
cityIDstringYesTime zone city ID.

Return value

TypeDescription
TimeZoneTimeZone object corresponding to the specified time zone city ID.

Example

let timezone: I18n.TimeZone = I18n.TimeZone.getTimezoneFromCity("Shanghai");

getTimezonesByLocation10+

static getTimezonesByLocation(longitude: number, latitude: number): Array<TimeZone>

Creates an array of TimeZone objects corresponding to the specified longitude and latitude.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
longitudenumberYesLongitude. The value ranges from -180 to 179.9. A positive value is used for east longitude and a negative value is used for west longitude.
latitudenumberYesLatitude. The value ranges from -90 to 89.9. A positive value is used for north latitude and a negative value is used for south latitude.

Return value

TypeDescription
Array<TimeZone>Array of TimeZone objects.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

let timezoneArray: Array<I18n.TimeZone> = I18n.TimeZone.getTimezonesByLocation(-118.1, 34.0);
for (let i = 0; i < timezoneArray.length; i++) {
    let tzId: string = timezoneArray[i].getID();
}

Transliterator9+

getAvailableIDs9+

static getAvailableIDs(): string[]

Obtains a list of IDs supported by the Transliterator object.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
string[]List of IDs supported by the Transliterator object.

Example

// A total of 671 IDs are supported. One ID is comprised of two parts separated by a hyphen (-) in the format of source-destination. For example, in **ids = ["Han-Latin","Latin-ASCII", "Amharic-Latin/BGN","Accents-Any", ...]**, **Han-Latin** indicates conversion from Chinese to Latin, and **Amharic-Latin** indicates conversion from Amharic to Latin.
// For more information, see ISO-15924.
let ids: string[] = I18n.Transliterator.getAvailableIDs();

getInstance9+

static getInstance(id: string): Transliterator

Creates a Transliterator object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
idstringYesID supported by the Transliterator object.

Return value

TypeDescription
TransliteratorTransliterator object.

Example

let transliterator: I18n.Transliterator = I18n.Transliterator.getInstance("Any-Latn");

transform9+

transform(text: string): string

Converts the input string from the source format to the target format.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
textstringYesInput string.

Return value

TypeDescription
stringTarget string.

Example

let transliterator: I18n.Transliterator = I18n.Transliterator.getInstance("Any-Latn");
let res: string = transliterator.transform("China"); // res = "zhōng guó"

Unicode9+

isDigit9+

static isDigit(char: string): boolean

Checks whether the input string is composed of digits.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a digit, and the value false indicates the opposite.

Example

let isdigit: boolean = I18n.Unicode.isDigit("1");  // isdigit = true

isSpaceChar9+

static isSpaceChar(char: string): boolean

Checks whether the input character is a space.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a space, and the value false indicates the opposite.

Example

let isspacechar: boolean = I18n.Unicode.isSpaceChar("a");  // isspacechar = false

isWhitespace9+

static isWhitespace(char: string): boolean

Checks whether the input character is a white space.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a white space, and the value false indicates the opposite.

Example

let iswhitespace: boolean = I18n.Unicode.isWhitespace("a");  // iswhitespace = false

isRTL9+

static isRTL(char: string): boolean

Checks whether the input character is of the right to left (RTL) language.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is of the RTL language, and the value false indicates the opposite.

Example

let isrtl: boolean = I18n.Unicode.isRTL("a");  // isrtl = false

isIdeograph9+

static isIdeograph(char: string): boolean

Checks whether the input character is an ideographic character.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is an ideographic character, and the value false indicates the opposite.

Example

let isideograph: boolean = I18n.Unicode.isIdeograph("a");  // isideograph = false

isLetter9+

static isLetter(char: string): boolean

Checks whether the input character is a letter.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a letter, and the value false indicates the opposite.

Example

let isletter: boolean = I18n.Unicode.isLetter("a");  // isletter = true

isLowerCase9+

static isLowerCase(char: string): boolean

Checks whether the input character is a lowercase letter.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a lowercase letter, and the value false indicates the opposite.

Example

let islowercase: boolean = I18n.Unicode.isLowerCase("a");  // islowercase = true

isUpperCase9+

static isUpperCase(char: string): boolean

Checks whether the input character is an uppercase letter.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is an uppercase letter, and the value false indicates the opposite.

Example

let isuppercase: boolean = I18n.Unicode.isUpperCase("a");  // isuppercase = false

getType9+

static getType(char: string): string

Obtains the type of the input string.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
stringType of the input character.

The following table lists only the common types. For more details, see the Unicode Standard.

NameValueDescription
U_UNASSIGNEDU_UNASSIGNEDNon-category for unassigned and non-character code points.
U_GENERAL_OTHER_TYPESU_GENERAL_OTHER_TYPESSame as U_UNASSIGNED.
U_UPPERCASE_LETTERU_UPPERCASE_LETTERUppercase letter.
U_LOWERCASE_LETTERU_LOWERCASE_LETTERLowercase letter.
U_TITLECASE_LETTERU_TITLECASE_LETTERTitle case letter.
U_MODIFIER_LETTERU_MODIFIER_LETTERModifier letter.
U_OTHER_LETTERU_OTHER_LETTERLetters other than the uppercase letter, lowercase letter, title case letter, and modifier letter.
U_NON_SPACING_MARKU_NON_SPACING_MARKNon-spacing mark, such as the accent symbol ' and the variable symbol #.
U_ENCLOSING_MARKU_ENCLOSING_MARKEnclosing mark, for example, a circle or a box.
U_COMBINING_SPACING_MARKU_COMBINING_SPACING_MARKSpacing mark, for example, the vowel symbol [].
U_DECIMAL_DIGIT_NUMBERU_DECIMAL_DIGIT_NUMBERDecimal number.
U_LETTER_NUMBERU_LETTER_NUMBERLetter and number (including Roman numeral).
U_OTHER_NUMBERU_OTHER_NUMBEROther numbers, which are used as encryption symbols, marker symbols, or non-Arabic numerals, such as @, #, (1), and .
U_SPACE_SEPARATORU_SPACE_SEPARATORSpace separator, for example, a space character, uninterrupted space character, or space character with a fixed width.
U_LINE_SEPARATORU_LINE_SEPARATORLine separator.
U_PARAGRAPH_SEPARATORU_PARAGRAPH_SEPARATORParagraph separator.
U_CONTROL_CHARU_CONTROL_CHARControl character.
U_FORMAT_CHARU_FORMAT_CHARFormat character.
U_PRIVATE_USE_CHARU_PRIVATE_USE_CHARPrivately used character, for example, a company logo.
U_SURROGATEU_SURROGATESurrogate, which is used to represent supplementary characters in UTF-16.
U_DASH_PUNCTUATIONU_DASH_PUNCTUATIONDash punctuation.
U_START_PUNCTUATIONU_START_PUNCTUATIONStart punctuation, for example, the left parenthesis.
U_END_PUNCTUATIONU_END_PUNCTUATIONEnd punctuation, for example, the right parenthesis.
U_INITIAL_PUNCTUATIONU_INITIAL_PUNCTUATIONInitial punctuation, for example, the left double quotation mark or left single quotation mark.
U_FINAL_PUNCTUATIONU_FINAL_PUNCTUATIONFinal punctuation, for example, the right double quotation mark or right single quotation mark.
U_CONNECTOR_PUNCTUATIONU_CONNECTOR_PUNCTUATIONConnector punctuation.
U_OTHER_PUNCTUATIONU_OTHER_PUNCTUATIONOther punctuations.
U_MATH_SYMBOLU_MATH_SYMBOLMathematical symbol.
U_CURRENCY_SYMBOLU_CURRENCY_SYMBOLCurrency symbol.
U_MODIFIER_SYMBOLU_MODIFIER_SYMBOLModifier symbol.
U_OTHER_SYMBOLU_OTHER_SYMBOLOther symbols.

Example

let type: string = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER"

I18NUtil9+

unitConvert9+

static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string

Converts one measurement unit into another and formats the unit based on the specified locale and style.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
fromUnitUnitInfoYesMeasurement unit to be converted.
toUnitUnitInfoYesMeasurement unit to be converted to.
valuenumberYesValue of the measurement unit to be converted.
localestringYesLocale used for formatting, for example, zh-Hans-CN.
stylestringNoStyle used for formatting. The value can be long, short, or narrow. The default value is short.

Return value

TypeDescription
stringString obtained after formatting based on the measurement unit specified by toUnit.

Example

let fromUnit: I18n.UnitInfo = {unit: "cup", measureSystem: "US"};
let toUnit: I18n.UnitInfo = {unit: "liter", measureSystem: "SI"};
let res: string = I18n.I18NUtil.unitConvert(fromUnit, toUnit, 1000, "en-US", "long"); // res = 236.588 liters

getDateOrder9+

static getDateOrder(locale: string): string

Obtains the sequence of the year, month, and day in the specified locale.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
localestringYesLocale used for formatting, for example, zh-Hans-CN.

Return value

TypeDescription
stringSequence of the year, month, and day in the locale.

Example

let order: string = I18n.I18NUtil.getDateOrder("zh-CN");  // order = "y-L-d"

getTimePeriodName11+

static getTimePeriodName(hour:number, locale?: string): string

Obtains the localized expression for the specified time of the specified locale.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
hournumberYesSpecified time, for example, 16.
localestringNoSpecified locale. By default, the locale of the application is used, for example, zh-Hans-CN.

Return value

TypeDescription
stringLocalized expression for the specified time of the specified locale.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

try {
  let name: string = I18n.I18NUtil.getTimePeriodName(2, "zh-CN");  // name = "a.m."
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call I18NUtil.getTimePeriodName failed, error code: ${err.code}, message: ${err.message}.`);
}

Normalizer10+

getInstance10+

static getInstance(mode: NormalizerMode): Normalizer

Obtains a Normalizer object for text normalization.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
modeNormalizerModeYesText normalization mode.

Return value

TypeDescription
NormalizerNormalizer object for text normalization.

Example

let normalizer: I18n.Normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC);

normalize10+

normalize(text: string): string

Normalizes text strings.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
textstringYesText strings to be normalized.

Return value

TypeDescription
stringNormalized text strings.

Example

let normalizer: I18n.Normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC);
let normalizedText: string = normalizer.normalize('\u1E9B\u0323'); // normalizedText = \u1E9B\u0323

NormalizerMode10+

Enumerates text normalization modes.

System capability: SystemCapability.Global.I18n

NameValueDescription
NFC1NFC.
NFD2NFD.
NFKC3NFKC.
NFKD4NFKD.

SystemLocaleManager10+

constructor10+

constructor()

Creates a SystemLocaleManager object.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

Example

let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager();

getLanguageInfoArray10+

getLanguageInfoArray(languages: Array<string>, options?: SortOptions): Array<LocaleItem>

Obtains the language sorting array.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagesArray<string>YesList of languages to be sorted.
optionsSortOptionsNoLanguage sorting option.

Return value

TypeDescription
Array<LocaleItem>Language list after sorting.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

// Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager();
let languages: string[] = ["zh-Hans", "en-US", "pt", "ar"];
let sortOptions: I18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: true, isSuggestedFirst: true};
try {
    // The language list after sorting is [zh-Hans, en-US, pt, ar].
    let sortedLanguages: Array<I18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions);
} catch(error) {
    let err: BusinessError = error as BusinessError;
    console.error(`call systemLocaleManager.getLanguageInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
}

getRegionInfoArray10+

getRegionInfoArray(regions: Array<string>, options?: SortOptions): Array<LocaleItem>

Obtains the country/region sorting array.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
regionsArray<string>YesList of countries/regions to be sorted.
optionsSortOptionsNoCountry/region sorting option. The default value of locale is the system locale, the default value of isUseLocalName is false, and the default value of isSuggestedFirst is true.

Return value

TypeDescription
Array<LocaleItem>Country/region list after sorting.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

import { BusinessError } from '@ohos.base';

// Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager();
let regions: string[] = ["CN", "US", "PT", "EG"];
let sortOptions: I18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: false, isSuggestedFirst: true};
try {
    // The country/region list after sorting is [CN, EG, US, PT].
    let sortedRegions: Array<I18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions);
} catch(error) {
    let err: BusinessError = error as BusinessError;
    console.error(`call systemLocaleManager.getRegionInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
}

getTimeZoneCityItemArray10+

static getTimeZoneCityItemArray(): Array<TimeZoneCityItem>

Obtains the array of time zone city items after sorting.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<TimeZoneCityItem>Array of time zone city items.

Example

import { BusinessError } from '@ohos.base';

try {
  let timeZoneCityItemArray: Array<I18n.TimeZoneCityItem> = I18n.SystemLocaleManager.getTimeZoneCityItemArray();
  for (let i = 0; i < timeZoneCityItemArray.length; i++) {
      console.log(timeZoneCityItemArray[i].zoneId + ", " + timeZoneCityItemArray[i].cityId + ", " + timeZoneCityItemArray[i].cityDisplayName +
          ", " + timeZoneCityItemArray[i].offset + "\r\n");
  }
} catch(error) {
  let err: BusinessError = error as BusinessError;
  console.error(`call SystemLocaleManager.getTimeZoneCityItemArray failed, error code: ${err.code}, message: ${err.message}.`);
}

LocaleItem10+

Represents the list of languages or countries/regions sorted by SystemLocaleManager.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

NameTypeMandatoryDescription
idstringYesLanguage code or country/region code, for example, zh or CN.
suggestionTypeSuggestionTypeYesLanguage or country/region suggestion type.
displayNamestringYesDisplayed name of ID in the locale of SystemLocaleManager.
localNamestringNoLocal name of the ID.

TimeZoneCityItem10+

Represents the time zone and city combination information.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

NameTypeMandatoryDescription
zoneIdstringYesTime zone ID, for example, Asia/Shanghai.
cityIdstringYesCity ID, for example, Shanghai.
cityDisplayNamestringYesDisplayed name of the city ID in the system locale.
offsetintYesOffset of the time zone ID.
zoneDisplayNamestringYesDisplayed name of the time zone ID in the system locale.
rawOffsetintNoFixed offset of the time zone ID.

SuggestionType10+

Represents the language or country/region suggestion type.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

NameValueDescription
SUGGESTION_TYPE_NONE0x00Not a recommended language or country/region.
SUGGESTION_TYPE_RELATED0x01Country/region recommended by the system language or language recommended by the system country/region.
SUGGESTION_TYPE_SIM0x02Language recommended by the country/region of the SIM card.

SortOptions10+

Represents the language or country/region sorting option.

System API: This is a system API.

System capability: SystemCapability.Global.I18n

NameTypeMandatoryDescription
localestringNoSystem locale, for example, zh-Hans-CN. The default value of locale is the system locale.
isUseLocalNamebooleanNoWhether to use the local name for sorting. If getLanguageInfoArray is called, the default value of isUseLocalName is true. If getRegionInfoArray is called, the default value of isUseLocalName is false.
isSuggestedFirstbooleanNoWhether to move the recommended language or country/region to the top in the sorting result. The default value of isSuggestedFirst is true.

HolidayManager11+

constructor11+

constructor(icsPath: String)

Creates a HolidayManager object.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
icsPathStringYesPath of the .ics file with the read permission granted for applications.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

let holidayManager= new I18n.HolidayManager("/system/lib/US.ics");

isHoliday11+

isHoliday(date?: Date): boolean;

Determines whether the specified date is a holiday.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
dateDateNoDate object.
If no date is specified, the current date is used by default.

Return value

TypeDescription
booleanThe value true indicates that the specified date is a holiday, and the value false indicates the opposite.

Example

try {
  let holidayManager= new I18n.HolidayManager("/system/lib/US.ics");
  let isHoliday = holidayManager.isHoliday();
  console.log(isHoliday);
  let isHoliday2 = holidayManager.isHoliday(new Date(2023,5,25));
  console.log(isHoliday2);
} catch(error) {
  console.error(`call holidayManager.isHoliday failed, error code: ${error.code}, message: ${error.message}.`);
}

getHolidayInfoItemArray11+

getHolidayInfoItemArray(year?: number): Array<HolidayInfoItem>

Obtains the holiday information list of the specified year.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
yearnumberNoSpecified year, for example, 2023.
If no year is specified, the current year is used by default.

Return value

TypeDescription
Array<HolidayInfoItem>Holiday information list.

Error codes

For details about the error codes, see I18N Error Codes.

IDError Message
890001param value not valid

Example

try {
  let holidayManager= new I18n.HolidayManager("/system/lib/US.ics");
  let holidayInfoItemArray = holidayManager.getHolidayInfoItemArray(2023);
  for (let i =0 ;i < holidayInfoItemArray.length; i++) {
      console.log(JSON.stringify(holidayInfoItemArray[i]));
  }
} catch(error) {
  console.error(`call holidayManager.getHolidayInfoItemArray failed, error code: ${error.code}, message: ${error.message}.`);
}

HolidayInfoItem11+

Represents the holiday information.

System capability: SystemCapability.Global.I18n

NameTypeMandatoryDescription
baseNamestringYesHoliday name.
yearnumberYesYear of the holiday.
monthnumberYesMonth of the holiday.
daynumberYesDay of the holiday.
localNamesArray<HolidayLocalName>NoLocal names of the holiday.

HolidayLocalName11+

Defines the local names of a holiday.

System capability: SystemCapability.Global.I18n

NameTypeMandatoryDescription
languagestringYesLocal language of a holiday, for example, ar, en, or tr.
namestringYesLocal name of a holiday. For example, the Turkish name of Sacrifice Feast is Kurban Bayrami.

I18n.getDisplayCountry(deprecated)

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

Obtains the localized script for the specified country.

This API is deprecated since API version 9. You are advised to use System.getDisplayCountry.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
countrystringYesSpecified country.
localestringYesLocale ID.
sentenceCasebooleanNoWhether to use sentence case for the localized script. The default value is true.

Return value

TypeDescription
stringLocalized script for the specified country.

Example

let countryName: string = I18n.getDisplayCountry("zh-CN", "en-GB", true); // countryName = true
countryName = I18n.getDisplayCountry("zh-CN", "en-GB"); // countryName = true

I18n.getDisplayLanguage(deprecated)

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

Obtains the localized script for the specified language.

This API is deprecated since API version 9. You are advised to use System.getDisplayLanguage.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesSpecified language.
localestringYesLocale ID.
sentenceCasebooleanNoWhether to use sentence case for the localized script. The default value is true.

Return value

TypeDescription
stringLocalized script for the specified language.

Example

let languageName: string = I18n.getDisplayLanguage("zh", "en-GB", true); // languageName = "Chinese"
languageName = I18n.getDisplayLanguage("zh", "en-GB"); // languageName = "Chinese"

I18n.getSystemLanguage(deprecated)

getSystemLanguage(): string

Obtains the system language.

This API is deprecated since API version 9. You are advised to use System.getSystemLanguage.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem language ID.

Example

let systemLanguage: string = I18n.getSystemLanguage(); // Obtain the current system language.

I18n.getSystemRegion(deprecated)

getSystemRegion(): string

Obtains the system region.

This API is deprecated since API version 9. You are advised to use System.getSystemRegion.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem region ID.

Example

let region: string = I18n.getSystemRegion(); // Obtain the current system region.

I18n.getSystemLocale(deprecated)

getSystemLocale(): string

Obtains the system locale.

This API is deprecated since API version 9. You are advised to use System.getSystemLocale.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringSystem locale ID.

Example

let locale: string = I18n.getSystemLocale (); // Obtain the system locale.

I18n.is24HourClock(deprecated)

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

This API is deprecated since API version 9. You are advised to use System.is24HourClock.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
booleanThe value true indicates that the 24-hour clock is used, and the value false indicates the opposite.

Example

let is24HourClock: boolean = I18n.is24HourClock();

I18n.set24HourClock(deprecated)

set24HourClock(option: boolean): boolean

Sets the 24-hour clock.

This API is deprecated since API version 9. You are advised to use System.set24HourClock.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
optionbooleanYesWhether to enable the 24-hour clock. The value true means to enable the 24-hour clock, and the value false means the opposite.

Return value

TypeDescription
booleanThe value true indicates that the 24-hour clock is enabled, and the value false indicates the opposite.

Example

// Set the system time to the 24-hour clock.
let success: boolean = I18n.set24HourClock(true);

I18n.addPreferredLanguage(deprecated)

addPreferredLanguage(language: string, index?: number): boolean

Adds a preferred language to the specified position on the preferred language list.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use System.addPreferredLanguage.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
languagestringYesPreferred language to add.
indexnumberNoPosition to which the preferred language is added. The default value is the length of the preferred language list.

Return value

TypeDescription
booleanThe value true indicates that the preferred language is successfully added, and the value false indicates the opposite.

Example

// Add zh-CN to the preferred language list.
let language: string = 'zh-CN';
let index: number = 0;
let success: boolean = I18n.addPreferredLanguage(language, index);

I18n.removePreferredLanguage(deprecated)

removePreferredLanguage(index: number): boolean

Deletes a preferred language from the specified position on the preferred language list.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use System.removePreferredLanguage.

Permission required: ohos.permission.UPDATE_CONFIGURATION

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
indexnumberYesPosition of the preferred language to delete.

Return value

TypeDescription
booleanThe value true indicates that the preferred language is deleted, and the value false indicates the opposite.

Example

// Delete the first preferred language from the preferred language list.
let index: number = 0;
let success: boolean = I18n.removePreferredLanguage(index);

I18n.getPreferredLanguageList(deprecated)

getPreferredLanguageList(): Array<string>

Obtains the list of preferred languages.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use System.getPreferredLanguageList.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
Array<string>List of preferred languages.

Example

let preferredLanguageList: Array<string> = I18n.getPreferredLanguageList(); // Obtain the preferred language list.

I18n.getFirstPreferredLanguage(deprecated)

getFirstPreferredLanguage(): string

Obtains the first language in the preferred language list.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use System.getFirstPreferredLanguage.

System capability: SystemCapability.Global.I18n

Return value

TypeDescription
stringFirst language in the preferred language list.

Example

let firstPreferredLanguage: string = I18n.getFirstPreferredLanguage();

Util(deprecated)

unitConvert(deprecated)

static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string

Converts one measurement unit into another and formats the unit based on the specified locale and style.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use unitConvert.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
fromUnitUnitInfoYesMeasurement unit to be converted.
toUnitUnitInfoYesMeasurement unit to be converted to.
valuenumberYesValue of the measurement unit to be converted.
localestringYesLocale used for formatting, for example, zh-Hans-CN.
stylestringNoStyle used for formatting. The value can be long, short, or narrow. The default value is short.

Return value

TypeDescription
stringString obtained after formatting based on the measurement unit specified by toUnit.

Character(deprecated)

isDigit(deprecated)

static isDigit(char: string): boolean

Checks whether the input string is composed of digits.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isDigit.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a digit, and the value false indicates the opposite.

isSpaceChar(deprecated)

static isSpaceChar(char: string): boolean

Checks whether the input character is a space.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isSpaceChar.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a space, and the value false indicates the opposite.

isWhitespace(deprecated)

static isWhitespace(char: string): boolean

Checks whether the input character is a white space.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isWhitespace.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a white space, and the value false indicates the opposite.

isRTL(deprecated)

static isRTL(char: string): boolean

Checks whether the input character is of the right to left (RTL) language.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isRTL.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is of the RTL language, and the value false indicates the opposite.

isIdeograph(deprecated)

static isIdeograph(char: string): boolean

Checks whether the input character is an ideographic character.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isIdeograph.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is an ideographic character, and the value false indicates the opposite.

isLetter(deprecated)

static isLetter(char: string): boolean

Checks whether the input character is a letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isLetter.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a letter, and the value false indicates the opposite.

isLowerCase(deprecated)

static isLowerCase(char: string): boolean

Checks whether the input character is a lowercase letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isLowerCase.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is a lowercase letter, and the value false indicates the opposite.

isUpperCase(deprecated)

static isUpperCase(char: string): boolean

Checks whether the input character is an uppercase letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use isUpperCase.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
booleanThe value true indicates that the input character is an uppercase letter, and the value false indicates the opposite.

getType(deprecated)

static getType(char: string): string

Obtains the type of the input string.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use getType.

System capability: SystemCapability.Global.I18n

Parameters

NameTypeMandatoryDescription
charstringYesInput character.

Return value

TypeDescription
stringType of the input character.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/96de2427a94d41c48b1cffbd58ec0ba0