Skip to content
目录

国际化

通常我们创建一个 lang.ts 文件来存放两种语言的文本。使用 i18n 函数来创建一个国际化对象,会自动根据 MN 的语言得到对应的文字。

ts
import { i18n } from "marginnote"

export default i18n({
  zh: {
    intro: `当前版本:${Addon.version}`,
    double_link: "双击打开链接",
    profile: {
      $option5: [
        "配置 1",
        "配置 2",
        "配置 3",
        "配置 4",
        "初始化"
      ] as StringTuple<5>,
      label: "选择全局配置",
      help: "【仅当前笔记本】不同场景,不同配置。"
    }
  },

  en: {
    intro: `Current Version: ${Addon.version}`,
    double_link: "Double Click to Open Link",
    profile: {
      $option5: [
        "Profile 1",
        "Profile 2",
        "Profile 3",
        "Profile 4",
        "Initialize"
      ],
      label: "Select Global Profile",
      help: "[Only Current Notebook] Different Scenes, Different Profile."
    }
})
import { i18n } from "marginnote"

export default i18n({
  zh: {
    intro: `当前版本:${Addon.version}`,
    double_link: "双击打开链接",
    profile: {
      $option5: [
        "配置 1",
        "配置 2",
        "配置 3",
        "配置 4",
        "初始化"
      ] as StringTuple<5>,
      label: "选择全局配置",
      help: "【仅当前笔记本】不同场景,不同配置。"
    }
  },

  en: {
    intro: `Current Version: ${Addon.version}`,
    double_link: "Double Click to Open Link",
    profile: {
      $option5: [
        "Profile 1",
        "Profile 2",
        "Profile 3",
        "Profile 4",
        "Initialize"
      ],
      label: "Select Global Profile",
      help: "[Only Current Notebook] Different Scenes, Different Profile."
    }
})

需要做一些约定:

OhMyMN 里菜单选项都是直接传入的字符串数组,虽然这样做非常简单,但是会直接影响到代码的逻辑,比如数组的长度不一样,所以我们需要使用 StringTuple 来约束数组长度。并且 key 必须以 $ 开头,后面跟着数字,表示数组长度。

Released under the MIT License.