简体   繁体   中英

Internationalization with vue-i18n plugin

I have app which I have added translation , I would like to add button event to change the language on my home page .

I have used this tutorial localization with vue

and Localization with vue tutorial

here is what I have :

      <div class="lang-choice">
    <span class="lang">PL</span>
    <img class="angle-down" src="http://localhost:8080/assets/img/yellow_angle_down.png" alt="">
    <div class="lang-dropdown" style="display: block; opacity: 1;">
        <ul class="lang-list">
            <li><a href="">RU</a>
            </li>
            <li><a href="">UA</a></li>
            <li><a href="">EN</a>
            </li>
        </ul>
    </div>
</div>

Here is app.js

import store from './store/store.js'

// Translation plugin for static text
import vuexI18n from 'vuex-i18n';
import Locales from './vue-i18n-locales.generated.js';
window.Vue = require('vue');

// language settings
Vue.use(vuexI18n.plugin, store);
Vue.i18n.add('en', Locales.en);
Vue.i18n.add('pl', Locales.pl); 
Vue.i18n.add('uk', Locales.uk); 

// set the start locale to use
Vue.i18n.set('pl');

const app = new Vue({
    el: '#app',
    store,
});

I am using this generator https://github.com/martinlindhe/laravel-vue-i18n-generator .

Here is how I transalte text in vue js

v-bind:placeholder="$t('Szukaj umiejętności... ')"

When i run generator everything works as expected and I can transalte text

How can I add buttons to transalate my page ? eg clicking on ENG button transalte the page to english and clicking eg RU translate page to RU ,

vuex-i18n公开了$i18n.set() ,因此您应该能够执行以下操作:在模板中<button @click="$i18n.set('en')">en</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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