javascript - VueJS 翻译插件
问题描述
我正在使用一个名为 VueTranslated 的插件,由 javisperez 制作,我在获取翻译文本时遇到了一些困难。
我正在使用全局用法。我有一个包含所有单词及其翻译的文件,例如:
import Vue from 'vue'
import VueTranslate from 'vue-translate-plugin'
Vue.use(VueTranslate)
Vue.locales({
'pt_BR': {
'hello-world': 'Olá mundo'
},
'en_US': {
'hello-world': 'Hello world'
}
})
导出默认值()
因此,当我在任何组件中时,我可以使用以下内容来获取单词:
<template>
<div>
<p> {{t('hello-world)}} </p>
</div>
</template>
然后,p
标签显示字符串Hello world
或Olá mundo
取决于我的语言集。但是如果我在这个组件中有类似的东西
<template>
<div>
<p> {{message}}
</div>
</template>
<script>
export default {
data: () => ({
message: this.$translate.text('hello-world)
})
}
</script>
它只是出现hello-world
在我的p
标签中。当它来自我的组件的脚本标签时,如何获得翻译的字符串?或者,除了这个插件,我还有什么可以尝试的吗?谢谢
解决方案
我只需要this.t('message')
像这样使用:
<script>
export default {
data {
return {
message: this.t('message')
}
}
}
</script>
推荐阅读
- google-chrome - Firefox 和 Chrome 上的图像和字体不清晰
- php - 连接时浏览器无法正确显示变音符号
- java - Flink:java.lang.NoSuchMethodError:AvroSchemaConverter
- json - 使用来自另一个键的新键和值更新嵌套 JSON 数组
- c# - 使用 groubBy 的 LINQ 过滤器查询
- vba - PowerPoint:快速文本操作
- windows - Windows 上的 AWS CLI 无法使用双引号和转义符
- python-3.x - 有没有可以帮助我轻松拟合数据的库?我找到了更合适的人,我将提供代码,但它显示了一些错误
- java - 正确使用@CompoundIndex 和 MongoRepository
- file - Apache 骆驼与 fileExist 使用 TryRename