A simple vuejs plugin for multi language translation.
$ npm install easy-translator-vue --save
$ yarn add easy-translator-vue
import Vue from 'vue' import Lang from "easy-translator-vue";
import en from "path/to/locales/en.js"; import hi from "path/to/locales/hi.js";
Vue.use(Lang, { locale: "hi", fallbackLocale: "en", locales: { en, hi }, });
en.js
export default { "HELLO": "Hello World.", "WELCOME" : "Hello %s, Welcome to %s page" }
hi.js
export default { "HELLO": "नमस्कार.", "WELCOME" : "हेल्लो %s, %s पेज में आपका स्वागत है" }
In component template:
<h1>{{ $lang('HELLO') }}</h1> <h2>{{ $lang('WELCOME', ["Amit", "Forum"]) }}</h2>
In component script:
this.$lang('HELLO'); this.$lang('WELCOME', ["अमित", "फोरम"])
<h1>Hello World</h1> <h2>Hello Amit, Welcome to Forum page.</h2>
<h1>नमस्कार</h1> <h2>हेल्लो अमित, फोरम पेज में आपका स्वागत है</h2>