系统提供的静态资源, 包括图片, 文字, 基础 styleSheet css 等等
Example
import res, {Language} from "miot/resources"
res.logo
...
console.log(res.systemStrings.mijia)
console.log(res.getSystemString('mijia'))
res.registerStrings({
zh:{t1:"测试"},
en:{t1:"test"}
})
console.log(res.strings.t1)
console.log(res.getString('t1'))
res.setLanguage(Language.zh_hk)
console.log(res.getLanaguage())
Namespaces
Members
(static) logo
米家标志
(static) strings
获取用户自定义字符串
(static) systemStrings
获取系统字符串
Example
console.log(res.systemStrings.mijia)
Methods
(static) createI18n(langStrings, defaultLanguage)
创建本地化字符串
Parameters:
Name | Type | Description |
---|---|---|
langStrings |
json | 多语言字符串 |
defaultLanguage |
Language | 默认语言 |
Example
const i18n = res.createI18n({
zh:{test:"测试"},
en:{test:"test"}
}, Language.zh)
...
console.log(i18n.strings.test) //> 测试
i18n.language = Language.en;
console.log(i18n.strings.test) //> test
i18n.language = null;
console.log(i18n.strings.test) //> 测试
(static) getLanguage()
获取当前使用中的语言, 缺省为Host.locale.language
(static) getString(key, …params) → {string}
根据主键名获取用户自定义的国际化字符串
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string | 主键名 |
|
params |
any |
<repeatable> |
参数 |
Example
res.getString('t1.tx', 1)
res.getString('t2')
(static) getSystemString(key, …params) → {string}
根据主键名获取系统的国际化字符串
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string | 主键名 |
|
params |
any |
<repeatable> |
参数 |
Example
res.getSystemString('mijia')
(static) registerStrings(langStrings)
注册多语言
Parameters:
Name | Type | Description |
---|---|---|
langStrings |
json |
Example
import res from 'miot/resources'
res.registerStrings({
zh:{
t1:"测试字符串",
t2:"数值为{1}",
t3:["从{1}到{2}", [0, "非法数据"], [1, "错误数据"], [2, "从 二 到 {2}"], [(v1,v2)=>v1>100, "太多了"]],
t4:{
t5:()=>"好的",
t6:["最多{1}"],
t7:(a,b,c)=>`${a}|${b}|${c}`,
t8:"你好"
}
},
en:{
t1:"test strigns",
t2:"value is {1}",
t3:["from {1} to {2}", [0, "invalid data"], [1, "wrong value"], [3, "from three to {2}"], [v1=>v1>100, "too more"]],
t4:{
t5:[()=>"good"],
t6:"{1} at most",
t7:(a,b,c)=>`${a}/${b}/${c}`
}
}
});
//style recommend
console.log(res.strings.t1);
console.log(res.strings.t2(123));
console.log(res.strings.t3(0, 1));
console.log(res.strings.t3(1, 2));
console.log(res.strings.t3(2, 200));
console.log(res.strings.t3(100, 3000));
console.log(res.strings.t3(101, 500));
console.log(res.strings.t4.t5());
console.log(res.strings.t4.t6(20));
console.log(res.strings.t4.t7(5,6,7));
console.log(res.strings.t4.t8);
//style traditional
console.log(res.getString('t1');
console.log(res.getString('t2',123));
console.log(res.getString('t3', 0, 1));
console.log(res.getString('t3', 1, 2));
console.log(res.getString('t3', 2, 200));
console.log(res.getString('t3', 100, 3000));
console.log(res.getString('t3', 101, 500));
console.log(res.getString('t4.t5');
console.log(res.getString('t4.t6', 20));
console.log(res.getString('t4.t7', 5,6,7));
console.log(res.getString('t4.t8');
(static) setLanguage(lang)
设置当前语言, 如果 lang 为 false 或 null, 则恢复为Host.locale.language
Parameters:
Name | Type | Description |
---|---|---|
lang |
Language |