# 插件多语言

插件接入多语言平台,支持资源热更新。步骤:

  1. 从多语言平台导出基础资源包,将其中json文件放入插件内;
  2. 插件集成SLanguage,调用SLanguage.getLanguageByCode,封装方法传入常量参数;
  3. 在业务代码中调用封装的方法,传入当前语言码,获取当前语种资源;

# 示例代码

import { SLanguage } from 'smarthome-weex-components';
import baseLangObj from './base';
// import JsBridge from '../service/nativeService';

/**
 * 获取当前语种资源
 * @param {string} langCode 语言码
 * @returns {Promise<object>} 当前语种资源 eg: {name: 'Tom', ...}
 */
export default async function getLanguageByCode(langCode) {
  const langObj = await SLanguage.getLanguageByCode(langCode, {
    baseLangObj,
    baseTimestamp: 123,
    deviceType: '',
    app: '',
    repositoryCode: 123,
    system: ''
  });

//   JsBridge.log('当前多语言', langObj);

  return langObj;
}

base.js示例

# 请求参数

Prop Type Required Default Description
langCode string Yes - 语言码
options.baseLangObj object Yes - 基础语言资源,例如:{en_US: {name: 'Tom', ...}, ...}
options.baseTimestamp number Yes - 基础资源时间戳
options.deviceType string Yes - 品类码,事业部接入必传
options.app string Yes - 业务类型,内部接入必传
options.repositoryCode number Yes - 词库编码
options.system string No SmartHome/TSmartLife 应用编码

# 返回参数

Prop Type Value
name string 例如:'Tom'
...