Skip to content

Instantly share code, notes, and snippets.

@aanation
Last active November 22, 2017 06:35
Show Gist options
  • Save aanation/a1ac4ec820116f6b45c63c595e5736a8 to your computer and use it in GitHub Desktop.
Save aanation/a1ac4ec820116f6b45c63c595e5736a8 to your computer and use it in GitHub Desktop.
trans.js
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