fln-vue-language
v0.1.1
Published
Simple vue plugin for language support
Downloads
11
Maintainers
Readme
fln-vue-language v0.1.1
Simple vue plugin for language support
Installation
fln-vue-language
requires Vue to run.
$ npm install fln-vue-language --save
Usage
// main.js
import language from 'fln-vue-language'
let langs = {
en: {
welcome: 'welcome'
},
ptBR: {
welcome: 'bem vindo'
}
}
Vue.use(language, {langs})
// App.vue
<template>
<h1>{{LANG.welcome}}</h1>
<h2>active language is {{LANG.$name}}</h2>
</template>
<script>
export default {
name: 'App',
data () {
return {
LANG:{} // required, will be injected the key "$name"
}
},
mathods:{
// optional, called when the language is changed
$changeLang(data){
console.log(data) // data from active language
}
}
}
</script>
Methods
import language from 'fln-vue-language'
language.set('en') // set 'en' active language
language.get() // returns data from active language
language.name() // returns name of active language
language.register('fr', {welcome: 'bienvenu'}) // register language package