如果您想按页面或按组件定义翻译,可以利用 i18n 自定义块。
您现在可以在 Vue 文件中使用 i18n 自定义块定义翻译:
<script setup lang="ts">
const { t } = useI18n({
useScope: 'local'
})
</script>
<template>
<p>{{ t('hello') }}</p>
</template>
<i18n lang="json">
{
"en": {
"hello": "hello world!"
},
"ja": {
"hello": "こんにちは、世界!"
}
}
</i18n>
或者使用 Yaml 语法:
<i18n lang="yaml">
en:
hello: 'hello world!'
ja:
hello: 'こんにちは、世界!'
</i18n>