harmony 鸿蒙Globalization Subsystem Changelog
Globalization Subsystem Changelog
cl.resourceManager.1 Addition of getStringSync and getStringByNameSync APIs
Added the getStringSync and getStringByNameSync APIs and error codes to obtain and format strings.
Bundle Name | API |
---|---|
ohos.resourceManager.d.ts | getStringSync(resId: number, …args: Array |
ohos.resourceManager.d.ts | getStringSync(resource: Resource, …args: Array |
ohos.resourceManager.d.ts | getStringByNameSync(resName: string, …args: Array |
Change Impact
In versions earlier than 4.0.6.2, only the values of string resources can be directly obtained. In 4.0.6.2 or later, the values of string resources can be formatted based on the input arguments for enhanced query.
The following error codes are added:
9001007 If the resource obtained by resId formatting error.
9001008 If the resource obtained by resName formatting error.
Sample Code
The following uses getStringSync as an example. Before the change, only example 1 is supported. After the change, both example 1 and example 2 are supported.
Example 1:
try {
this.context.resourceManager.getStringSync($r('app.string.test').id);
} catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
}
Example 2:
try {
this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 787, 98.78);
} catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
}
Adaptation Guide For details, see the API reference.
你可能感兴趣的鸿蒙文章
harmony 鸿蒙OpenHarmony Docker镜像
harmony 鸿蒙OpenHarmony Docker Image
harmony 鸿蒙IDL Specifications and User Guide (for System Applications Only)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦