09 系统资源 - MiEcosystem/miot-plugin-sdk GitHub Wiki
系统提供的静态资源, 包括图片, 文字, 基础 styleSheet css 等等
Export: public
Doc_name: 系统资源
Doc_index: 9
Doc_directory: sdk
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())
function createI18n(langStrings, defaultLanguage){}
-
miot/resources
- static
- inner
米家标志
Kind: static property of miot/resources
获取系统字符串
Kind: static property of miot/resources
Example
console.log(res.systemStrings.mijia)
获取用户自定义字符串
Kind: static property of miot/resources
注册多语言
Kind: static method of miot/resources
Param | Type |
---|---|
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');
获取当前使用中的语言, 缺省为Host.locale.language
Kind: static method of miot/resources
设置当前语言, 如果 lang 为 false 或 null, 则恢复为Host.locale.language
Kind: static method of miot/resources
Param | Type |
---|---|
lang | Language |
根据主键名获取系统的国际化字符串
Kind: static method of miot/resources
Param | Type | Description |
---|---|---|
key | string |
主键名 |
...params | any |
参数 |
Example
res.getSystemString('mijia')
根据主键名获取用户自定义的国际化字符串
Kind: static method of miot/resources
Param | Type | Description |
---|---|---|
key | string |
主键名 |
...params | any |
参数 |
Example
res.getString('t1.tx', 1)
res.getString('t2')
创建本地化字符串
Kind: static method of miot/resources
Param | 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) //> 测试
常用语言类型
Kind: inner namespace of miot/resources
-
~Language :
object
中文
Kind: static constant of Language
繁体中文(台湾)
Kind: static constant of Language
繁体中文(香港)
Kind: static constant of Language
藏语
Kind: static constant of Language
英语
Kind: static constant of Language
西班牙语
Kind: static constant of Language
朝鲜语
Kind: static constant of Language
俄语
Kind: static constant of Language
意大利
Kind: static constant of Language
法语
Kind: static constant of Language
德语
Kind: static constant of Language
印尼
Kind: static constant of Language
波兰
Kind: static constant of Language
越南
Kind: static constant of Language
日语
Kind: static constant of Language
傣语
Kind: static constant of Language
葡萄牙语
Kind: static constant of Language
荷兰语
Kind: static constant of Language
阿拉伯语
Kind: static constant of Language
土耳其语
Kind: static constant of Language