i18n 配置

使用方式

多语言的 key 值需要在 小程序开发者平台 中进行添加,选择对应的小程序后,点击侧边栏 多语言管理。

多语言的应用

通过 I18n.t 函数方法,多语言的字段可以应用到全局配置、React代码中。方式分别如下:

1. 全局、页面配置

你可以在global.config.ts 或 index.config.ts 中使用多语言变量配置。

注意: @I18n.t('xxx') 的格式必须使用单引号写法。

@ray-js/cli@1.7.63 版本后会支持 '@I18n.t("xxx")' 双引号格式。

global.config.ts
// global.config.ts
import { GlobalConfig } from '@ray-js/types'

export const tuya = {
  window: {
    backgroundColor: '#f2f4f6',
    navigationBarTitleText: '@I18n.t(\'miniprogram\')',
    navigationBarBackgroundColor: '#ff592a',
  },
}

const globalConfig: GlobalConfig = {
  basename: '',
}

export default globalConfig

// index.config.ts
export default {
  navigationBarTitleText: '@I18n.t(\'miniprogram\')',
}

2. React 代码中使用

import React from 'react'

import { View } from '@ray-js/ray'

export default function Demo() {
  return (
    <View
      style={{
        backgroundColor: 'orange',
        padding: '20rpx',
      }}
    >
      {I18n.t('projectName')}
    </View>
  )
}

面板多语言

面板小程序多语言相比智能小程序多语言额外增加了获取产品多语言的逻辑,用于满足不同产品使用的为同一个面板小程序时,需要配置不同的多语言。