Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d758c082
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d758c082
编写于
4月 11, 2023
作者:
O
openharmony_ci
提交者:
Gitee
4月 11, 2023
浏览文件
操作
浏览文件
下载
差异文件
!16797 string同步接口变更
Merge pull request !16797 from zt147369/master
上级
ea5489e5
ac4df16f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
219 addition
and
1 deletion
+219
-1
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
...pplication-dev/reference/apis/js-apis-resource-manager.md
+128
-0
zh-cn/application-dev/reference/errorcodes/errorcode-resource-manager.md
...on-dev/reference/errorcodes/errorcode-resource-manager.md
+45
-1
zh-cn/release-notes/changelogs/OpenHarmony_4.0.6.2/changelogs-global.md
...notes/changelogs/OpenHarmony_4.0.6.2/changelogs-global.md
+46
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md
浏览文件 @
d758c082
...
...
@@ -2057,6 +2057,47 @@ getStringSync(resId: number): string
}
```
### getStringSync<sup>10+</sup>
getStringSync(resId: number, ...args: Array
<string
|
number
>
): string
用户获取指定资源ID对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ------ | ---- | ----- |
| resId | number | 是 | 资源ID值 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
-%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | 资源ID值对应的格式化字符串|
以下错误码的详细介绍请参见
[
资源管理错误码
](
../errorcodes/errorcode-resource-manager.md
)
。
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ----------------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
```
ts
try
{
this
.
context
.
resourceManager
.
getStringSync
(
$r
(
'
app.string.test
'
).
id
,
"
format string
"
,
10
,
98.78
);
}
catch
(
error
)
{
console
.
error
(
`getStringSync failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
)
}
```
### getStringSync<sup>9+</sup>
getStringSync(resource: Resource): string
...
...
@@ -2101,6 +2142,52 @@ getStringSync(resource: Resource): string
}
```
### getStringSync<sup>10+</sup>
getStringSync(resource: Resource, ...args: Array
<string
|
number
>
): string
用户获取指定resource对象对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
**系统能力**
:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---- |
| resource |
[
Resource
](
#resource9
)
| 是 | 资源信息 |
| args | Array
<string
\|
number
>
| 否 | 格式化字符串资源参数
<br>
支持参数类型:
<br
/>
-%d、%f、%s、%%
<br>
说明:%%转译符,转译%
<br>
举例:%%d格式化后为%d字符串|
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | resource对象对应的格式化字符串|
以下错误码的详细介绍请参见
[
资源管理错误码
](
../errorcodes/errorcode-resource-manager.md
)
。
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001001 | If the resId invalid. |
| 9001002 | If the resource not found by resId. |
| 9001006 | If the resource re-ref too much. |
| 9001007 | If the resource obtained by resId formatting error. |
**示例:**
```
ts
let
resource
=
{
bundleName
:
"
com.example.myapplication
"
,
moduleName
:
"
entry
"
,
id
:
$r
(
'
app.string.test
'
).
id
};
try
{
this
.
context
.
resourceManager
.
getStringSync
(
resource
,
"
format string
"
,
10
,
98.78
);
}
catch
(
error
)
{
console
.
error
(
`getStringSync failed, error code:
${
error
.
code
}
, message:
${
error
.
message
}
.`
)
}
```
### getStringByNameSync<sup>9+</sup>
getStringByNameSync(resName: string): string
...
...
@@ -2140,6 +2227,47 @@ getStringByNameSync(resName: string): string
}
```
### getStringByNameSync<sup>10+</sup>
getStringByNameSync(resName: string, ...args: Array<string | number>): string
用户获取指定资源名称对应的字符串,根据args参数进行格式化,使用同步方式返回相应字符串。
**系统能力**:SystemCapability.Global.ResourceManager
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------ | ---- | ---- |
| resName | string | 是 | 资源名称 |
| args | Array<string \| number> | 否 | 格式化字符串资源参数 <br> 支持参数类型:<br /> -%d、%f、%s、%% <br> 说明:%%转译符,转译%<br>举例:%%d格式化后为%d字符串|
**返回值:**
| 类型 | 说明 |
| ------ | ---------------------------- |
| string | 资源名称对应的格式化字符串|
以下错误码的详细介绍请参见[资源管理错误码](../errorcodes/errorcode-resource-manager.md)。
**错误码:**
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
| 9001003 | If the resName invalid. |
| 9001004 | If the resource not found by resName. |
| 9001006 | If the resource re-ref too much. |
| 9001008 | If the resource obtained by resName formatting error. |
**示例:**
```
ts
try {
this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
} catch (error) {
console.error(
`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`
)
}
```
### getBoolean<sup>9+</sup>
getBoolean(resId: number): boolean
...
...
zh-cn/application-dev/reference/errorcodes/errorcode-resource-manager.md
浏览文件 @
d758c082
...
...
@@ -114,4 +114,48 @@ the resource re-ref too much.
**处理步骤**
查看资源$引用的地方,去除循环引用的情况。
\ No newline at end of file
查看资源$引用的地方,去除循环引用的情况。
## 9001007 根据当前id获取的资源格式化失败
**错误信息**
The resource obtained by resId formatting error.
**错误描述**
resId获取的字符串资源格式化失败。
**可能原因**
1、参数类型不在支持范围内。
2、参数与占位符个数不等。
3、参数与占位符类型不匹配。
**处理步骤**
查看args参数类型与占位符的个数、类型是否一致。
## 9001008 根据当前名称获取的资源格式化失败
**错误信息**
The resource obtained by resName formatting error.
**错误描述**
resName获取的字符串资源格式化失败。
**可能原因**
1、参数类型不在支持范围内。
2、参数与占位符个数不等。
3、参数与占位符类型不匹配。
**处理步骤**
查看args参数类型与占位符的个数、类型是否一致。
\ No newline at end of file
zh-cn/release-notes/changelogs/OpenHarmony_4.0.6.2/changelogs-global.md
0 → 100755
浏览文件 @
d758c082
# 全球化子系统ChangeLog
## cl.resourceManager.1 getStringSync、getStringByNameSync新增接口
相较于之前的版本,在4.0.6.2 版本中,为扩展getStringSync、getStringByNameSync接口字符串匹配功能,新增了接口以及相应的错误码。
| 包名 | 新增接口 |
| --------------- | ---------------------------------------------------- |
| ohos.resourceManager.d.ts | getStringSync(resId: number, ...args: Array
<string
\|
number
>
): string; |
| ohos.resourceManager.d.ts | getStringSync(resource: Resource, ...args: Array
<string
\|
number
>
): string; |
| ohos.resourceManager.d.ts | getStringByNameSync(resName: string, ...args: Array
<string
\|
number
>
): string; |
**变更影响**
之前只能直接获取resources中的string资源的value值,在4.0.6.2 及以上版本中可用通过参数格式化string资源的value值,扩展了格式化字符串的查询能力。
新增错误码:
9001007 根据当前id获取的资源格式化失败
9001008 根据当前名称获取的资源格式化失败
**示例代码**
以调用接口getStringSync为例,变更前只支持示例1,变更后示例1、示例2都支持。
```
示例1:
try {
this.context.resourceManager.getStringSync($r('app.string.test').id);
} catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`)
}
示例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}.`)
}
```
**适配指导**
请参考接口说明:
[
新增接口参考
](
../../../application-dev/reference/apis/js-apis-resource-manager.md
)
[
新增错误码参考
](
../../../application-dev/reference/errorcodes/errorcode-resource-manager.md
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录