V7

每个组件的翻译

如果你希望定义每个页面或每个组件的翻译,可以利用 vue-i18n-loader。只需将 vueI18nLoader 选项设置为 true@nuxtjs/i18n 将为你配置和启用加载器,包括对 i18n 块中 Yaml 语法的支持。

nuxt.config.ts
i18n: {
  vueI18nLoader: true
}

现在你可以在 Vue 文件中使用自定义块定义翻译:

<i18n>
{
  "en": {
    "hello": "hello world!"
  },
  "ja": {
    "hello": "こんにちは、世界!"
  }
}
</i18n>

<template>
  <p>{{ $t('hello') }}</p>
</template>

或者使用 Yaml 语法:

<i18n lang="yaml">
en:
  hello: 'hello world!'
ja:
  hello: 'こんにちは、世界!'
</i18n>

<template>
  <p>{{ $t('hello') }}</p>
</template>
阅读更多关于 i18n 块的信息,请访问 https://kazupon.github.io/vue-i18n/guide/sfc.html.