在从Vue.js/ next数组中选择项目之前尝试翻译字符串



所以,谢谢你谁会试图帮助我,我从几个月的laravel开始学习下一个,我需要做一个特定类型的翻译,很难找到关于

的信息我试图把一些对象在数组中,每个对象有3个属性:同一字符串的3种不同的语言。我有一个函数,返回正确的对象字符串,但我不熟悉如何才能得到我的函数的本地。这是我正在做的学习,我真的找不到很多信息在互联网上搜索。我已经知道并可以使用locale文件进行翻译,但我想使此结构在将来从API获取信息。

直到现在发生的事情是,一切都运行正常,我的计算函数从数组返回一个随机项到我的屏幕,但我试图在math.random.

之前获得本地和翻译函数的结果。我代码:

LoadingBar.vue

<template lang="html">
<div class="loading-page" v-if="loading">
<h1 class="title">Estamos preparando o terreno para você</h1>
<img src="~/assets/media/photos/agronomy.png" />
<p class="text">{{tiprandom}}</p>
</div>
</template>
<script>
import randomtip from '~/components/randomtip.vue'
export default {
layout: 'blank',
components: {
randomtip
},
data: () => ({
loading: true,
tipolocal_id: 1,
dicas: [
{id:1, nome: 'Dica 1: Considere uma atenção maior às mudas, pois são bem sensíveis. É importante deixar o vaso em um local sombreado e de olho sempre na irrigação',
nome_en: 'Dica 1: Consider paying more attention to the seedlings, as they are very sensitive. It is important to leave the pot in a shaded place and always keep an eye on irrigation',
nome_es: 'Dica 1: Considere prestar más atención a las plántulas, ya que son muy sensibles. Es importante dejar la maceta en un lugar sombreado y vigilar siempre el riego.'
},
{id:2, nome: 'Dica 2: Considere uma atenção maior às mudas, pois são bem sensíveis. É importante deixar o vaso em um local sombreado e de olho sempre na irrigação',
nome_en: 'Dica 2: Consider paying more attention to the seedlings, as they are very sensitive. It is important to leave the pot in a shaded place and always keep an eye on irrigation',
nome_es: 'Dica 2: Considere prestar más atención a las plántulas, ya que son muy sensibles. Es importante dejar la maceta en un lugar sombreado y vigilar siempre el riego.'
},
{id:3, nome: 'Dica 3: Considere uma atenção maior às mudas, pois são bem sensíveis. É importante deixar o vaso em um local sombreado e de olho sempre na irrigação',
nome_en: 'Dica 3: Consider paying more attention to the seedlings, as they are very sensitive. It is important to leave the pot in a shaded place and always keep an eye on irrigation',
nome_es: 'Dica 3: Considere prestar más atención a las plántulas, ya que son muy sensibles. Es importante dejar la maceta en un lugar sombreado y vigilar siempre el riego.'
},
],
}),
computed: {
tiprandom () {
return this.dicas[Math.floor(Math.random()*this.dicas.length)]
},
locale() {
if (this.$i18n.locale == 'pt-br') {
return 'pt_br'
} else {
return this.$i18n.locale
}
}
},
methods: {
functionDicas(dicas) {
if (this.$i18n.locale == 'pt-br') {
return dicas.nome
} else if (this.$i18n.locale == 'en') {
return dicas.nome_en
} else if (this.$i18n.locale == 'es') {
return dicas.nome_es
}
},

start () {
this.loading = true
},
finish () {
this.loading = false
},                    
}     
}
</script>

你把它弄得太复杂了,试图通过使用下面的方法来做一些更容易的事情:

本质上,您创建了一个包含翻译的jsonjavascript文件。这些翻译由key标记,然后该键是您在组件中调用的。

阅读链接,它应该更有意义!