首页 > 解决方案 > 如何将参数传递给翻译

问题描述

我正在使用带有 TS 的 vuejs 3。

我在 TS 中创建了这样的翻译文件:

索引.ts:

export default {
 'example': 'example',
}

然后以这种方式使用它:

{{ $t('example') }}

现在我想将参数传递给翻译,例如:

索引.ts:

export default {
 'hi_man': 'Hi {name}',    //where the name is the parameter
}

我怎样才能做到这一点?

标签: typescriptvue.jsinternationalizationvuejs3vue-i18n

解决方案


也许您应该考虑阅读文档:https ://kazupon.github.io/vue-i18n/guide/formatting.html#named-formatting

<p>{{ $t('hi_man', { name: 'Monkey' }) }}</p>

推荐阅读