Last active
November 22, 2017 06:35
-
-
Save aanation/a1ac4ec820116f6b45c63c595e5736a8 to your computer and use it in GitHub Desktop.
trans.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
install() { | |
Vue.mixin({ | |
beforeCreate: function() { | |
this.$trans = this.$options.trans; | |
}, | |
computed: { | |
lang() { | |
return this.$trans.lang; | |
} | |
}, | |
methods: { | |
getLang() { | |
return this.$trans.lang; | |
} | |
} | |
}); | |
}, | |
Trans: class Translator { | |
constructor(lang = '') { | |
this.currentLang = lang || 'ru'; | |
this.langs = { | |
en: { | |
"hello": "Hello!" | |
}, | |
ru: { | |
"hello": "Привет!" | |
} | |
}; | |
} | |
toggleLang() { | |
if (this.currentLang === "ru") { | |
this.currentLang = "en"; | |
} else { | |
this.currentLang = "ru"; | |
} | |
} | |
get lang() { | |
return this.langs[this.currentLang]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment