简体   繁体   English

Vue-i18n 和列表

[英]Vue-i18n and lists

I'm currently working with vue-i18n for internationalization and got a problem with lists in this topic.我目前正在使用 vue-i18n 进行国际化,并且在本主题中遇到列表问题。 The language can be changed using a dropdown menue on a permanent navigation bar.可以使用永久导航栏上的下拉菜单更改语言。 There is a Component A with a child Component B. Within this child component there are two lists, filled via:有一个组件 A 和一个子组件 B。在这个子组件中有两个列表,通过以下方式填充:

<select id="element1" class="ui dropdown" v-model="application.datatable">
    <option value="">... ... ...</option>     
    <option v-for="i in tableRows"  :value="i.id">
        <p>
            {{$t(i.element.name)}}
        </p>
    </option>
</select>

Here I'm experiencing the problem, that the {{$t(i.element.name)}} is translated correctly, but won't change after the first initialisation.在这里,我遇到了问题,即 {{$t(i.element.name)}} 被正确翻译,但在第一次初始化后不会改变。 So if I change the language from english to german, all other labels and strings are changed, but the lists are still in english (Wochentag: |Monday|Tuesday|…)因此,如果我将语言从英语更改为德语,所有其他标签和字符串都会更改,但列表仍为英语(Wochentag:|Monday|Tuesday|...)

For this, I would need a possibility to either rerender the lists (maybe via id, but found nothing in jQuery) or a way to get the lists rerendered every time the language changes.为此,我需要一种重新渲染列表的可能性(可能通过 id,但在 jQuery 中什么也没找到)或一种每次语言更改时重新渲染列表的方法。

Anyone having an idea about this?有人对此有想法吗? Huge thanks!非常感谢! AdV广告

  1. Bind your select to ( $i18n.locale ) in html将您的选择绑定到 ( $i18n.locale ) 在 html
<select name="lang" v-model="$i18n.locale">
    <option v-for="lang in langs" :value="lang">
        @{{ $t('general.' + lang) }}
    </option>
</select>

Note: @ symbole before curly brackets is because this code is in my .blade.php file.注意:大括号前的.blade.php是因为这段代码在我的.blade.php文件中。 If you are in the .vue file, it is note needed.如果您在.vue文件中,则需要注意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM