Skip to content

09 系统资源

zhangwenfeng edited this page Sep 1, 2020 · 1 revision

miot/resources

系统提供的静态资源, 包括图片, 文字, 基础 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.logo

米家标志

Kind: static property of miot/resources


miot/resources.systemStrings

获取系统字符串

Kind: static property of miot/resources
Example

console.log(res.systemStrings.mijia)

miot/resources.strings

获取用户自定义字符串

Kind: static property of miot/resources


miot/resources.registerStrings(langStrings)

注册多语言

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');

miot/resources.getLanguage()

获取当前使用中的语言, 缺省为Host.locale.language

Kind: static method of miot/resources


miot/resources.setLanguage(lang)

设置当前语言, 如果 lang 为 false 或 null, 则恢复为Host.locale.language

Kind: static method of miot/resources

Param Type
lang Language

miot/resources.getSystemString(key, ...params) ⇒ string

根据主键名获取系统的国际化字符串

Kind: static method of miot/resources

Param Type Description
key string 主键名
...params any 参数

Example

res.getSystemString('mijia')

miot/resources.getString(key, ...params) ⇒ string

根据主键名获取用户自定义的国际化字符串

Kind: static method of miot/resources

Param Type Description
key string 主键名
...params any 参数

Example

res.getString('t1.tx', 1)
   res.getString('t2')

miot/resources.createI18n(langStrings, defaultLanguage)

创建本地化字符串

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) //> 测试

miot/resources~Language : object

常用语言类型

Kind: inner namespace of miot/resources


Language.zh

中文

Kind: static constant of Language


Language.zh_tw

繁体中文(台湾)

Kind: static constant of Language


Language.zh_hk

繁体中文(香港)

Kind: static constant of Language


Language.zh_bo

藏语

Kind: static constant of Language


Language.en

英语

Kind: static constant of Language


Language.es

西班牙语

Kind: static constant of Language


Language.ko

朝鲜语

Kind: static constant of Language


Language.ru

俄语

Kind: static constant of Language


Language.it

意大利

Kind: static constant of Language


Language.fr

法语

Kind: static constant of Language


Language.de

德语

Kind: static constant of Language


Language.id

印尼

Kind: static constant of Language


Language.pl

波兰

Kind: static constant of Language


Language.vi

越南

Kind: static constant of Language


Language.ja

日语

Kind: static constant of Language


Language.th

傣语

Kind: static constant of Language


Language.pt

葡萄牙语

Kind: static constant of Language


Language.nl

荷兰语

Kind: static constant of Language


Language.ar

阿拉伯语

Kind: static constant of Language


Language.tr

土耳其语

Kind: static constant of Language


Clone this wiki locally