SYS_I18n.text() method
Output language text
Signature
typescript
function text(tag: string, namespace?: string, language?: string, ...args: Array<any>): string;1
Parameters
Parameter | Type | Description |
|---|---|---|
tag | string | Text tag, corresponding to the key in the multilingual file key-value pairs |
namespace | string | (Optional) Text namespace. In the extension runtime environment, it defaults to the extension UUID; otherwise, it is the system default namespace |
language | string | (Optional) Language. |
args | Array<any> | Arguments for replacing placeholders in the language text |
Returns
string
Language text
Remarks
Placeholders in the ${1} format can be used to represent parameters;
Language priority: current display language > system default language > the first language in the data set that contains the text tag > the text tag
Example
javascript
// 1. 先导入一份多语言数据作为取文本的数据源
eda.sys_I18n.importMultilingualNamespace('嘉立创示例_取文本', {
'zh-Hans': { 示例_问候: '你好,${1}!今天是${2}' },
'en': { 示例_问候: 'Hello, ${1}! Today is ${2}' },
});
// 2. 指定语言取文案,占位符按参数顺序替换
const greeting = eda.sys_I18n.text('示例_问候', '嘉立创示例_取文本', 'en', 'Tom', 'Monday');
// 3. 不传语言则用 EDA 当前显示语言;缺参的占位符原样保留
const current = await eda.sys_I18n.getCurrentLanguage();
const localized = eda.sys_I18n.text('示例_问候', '嘉立创示例_取文本', undefined, '嘉立创');
// 4. 标签不存在时回退为标签本身
const missing = eda.sys_I18n.text('示例_不存在的标签', '嘉立创示例_取文本');
console.log('当前语言:', current);
console.log('英文文案:', greeting);
console.log('当前语言文案:', localized);
console.log('缺失标签回退:', missing);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20