diff --git a/dist/vue-translate.min.js b/dist/vue-translate.min.js new file mode 100644 index 0000000..bda112c --- /dev/null +++ b/dist/vue-translate.min.js @@ -0,0 +1,3 @@ +var vm=null;function VueTranslate(){} +VueTranslate.install=function(d){vm||(vm=new d({data:function(){return{current:"",locales:{}}},computed:{locale:function(){return this.locales[this.current]?this.locales[this.current]:null}},methods:{setLang:function(a){this.current=a},setLocales:function(a){if(a){var b=Object.create(this.locales),c;for(c in a)b[c]||(b[c]={}),d.util.extend(b[c],a[c]);this.locales=Object.create(b)}},text:function(a){return this.locale&&this.locale[a]?this.locale[a]:a}}}),d.prototype.$translate=vm);d.mixin({beforeCreate:function(){this.$translate.setLocales(this.$options.locales)}, +methods:{t:function(a){return this.$translate.text(a)}},directives:{translate:function(a){a.$translateKey||(a.$translateKey=a.innerText);var b=this.$translate.text(a.$translateKey);a.innerText=b}.bind(vm)}})};"object"===typeof exports?module.exports=VueTranslate:"function"===typeof define&&define.amd?define([],function(){return VueTranslate}):window.Vue&&(window.VueTranslate=VueTranslate,Vue.use(VueTranslate)); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..461e2f2 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "vue-translate", + "version": "1.0.0", + "description": "Basic translations plugins for VueJS v2.0+", + "main": "dist/vue-translate.min.js", + "files": [ + "dist/vue.common.js", + "dist/vue.js", + "dist/vue.min.js", + "src" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/javisperez/vuetranslate.git" + }, + "keywords": [ + "vue", + "vuejs", + "translate", + "vue-translate", + "vuetranslate", + "locales", + "plugin" + ], + "author": { + "name": "Javis Perez", + "email": "javisperez@gmail.com" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/javisperez/vuetranslate/issues" + }, + "homepage": "https://github.com/javisperez/vuetranslate#readme" +} \ No newline at end of file diff --git a/vue-translate.js b/vue-translate.js index 92a60a1..a42e76c 100644 --- a/vue-translate.js +++ b/vue-translate.js @@ -8,102 +8,99 @@ * @author Javis Perez * https://github.com/javisperez/vuetranslate */ -;(function () { - - // We need a vue instance to handle rectivity - var vm = null; - - /** - * Constructor - */ - function VueTranslate() {} - - // Install the method - VueTranslate.install = function (Vue) { - if (!vm) { - vm = new Vue({ - data() { - return { - current: '', - locales: {} - }; - }, - - computed: { - locale() { - if (!this.locales[this.current]) - return null; - return this.locales[this.current]; - } - }, +// We need a vue instance to handle rectivity +var vm = null; - methods: { - setLang(val) { - this.current = val; - }, +/** + * Constructor + */ +function VueTranslate() {} + +// Install the method +VueTranslate.install = function (Vue) { + if (!vm) { + vm = new Vue({ + data() { + return { + current: '', + locales: {} + }; + }, - setLocales(locales) { - if (!locales) - return; + computed: { + locale() { + if (!this.locales[this.current]) + return null; - let newLocale = Object.create(this.locales); + return this.locales[this.current]; + } + }, - for (let key in locales) { - if (!newLocale[key]) - newLocale[key] = {}; + methods: { + setLang(val) { + this.current = val; + }, - Vue.util.extend(newLocale[key], locales[key]); - } + setLocales(locales) { + if (!locales) + return; - this.locales = Object.create(newLocale); - }, + let newLocale = Object.create(this.locales); - text(t) { - if (!this.locale || !this.locale[t]) { - return t; - } + for (let key in locales) { + if (!newLocale[key]) + newLocale[key] = {}; - return this.locale[t]; + Vue.util.extend(newLocale[key], locales[key]); } - } - }); - Vue.prototype.$translate = vm; - } + this.locales = Object.create(newLocale); + }, - // Mixin to read locales and add the translation method and directive - Vue.mixin({ - beforeCreate() { - this.$translate.setLocales(this.$options.locales); - }, + text(t) { + if (!this.locale || !this.locale[t]) { + return t; + } - methods: { - t(t) { - return this.$translate.text(t); + return this.locale[t]; } - }, + } + }); - directives: { - translate: function (el) { - if (!el.$translateKey) - el.$translateKey = el.innerText; + Vue.prototype.$translate = vm; + } - let text = this.$translate.text(el.$translateKey); + // Mixin to read locales and add the translation method and directive + Vue.mixin({ + beforeCreate() { + this.$translate.setLocales(this.$options.locales); + }, - el.innerText = text; - }.bind(vm) + methods: { + t(t) { + return this.$translate.text(t); } - }); - }; - - if (typeof exports === 'object') { - module.exports = VueTranslate; // CommonJS - } else if (typeof define === 'function' && define.amd) { - define([], function () { return VueTranslate; }); // AMD - } else if (window.Vue) { - window.VueTranslate = VueTranslate; // Browser (not required options) - Vue.use(VueTranslate); - } + }, -})(); + directives: { + translate: function (el) { + if (!el.$translateKey) + el.$translateKey = el.innerText; + + let text = this.$translate.text(el.$translateKey); + + el.innerText = text; + }.bind(vm) + } + }); +}; + +if (typeof exports === 'object') { + module.exports = VueTranslate; // CommonJS +} else if (typeof define === 'function' && define.amd) { + define([], function () { return VueTranslate; }); // AMD +} else if (window.Vue) { + window.VueTranslate = VueTranslate; // Browser (not required options) + Vue.use(VueTranslate); +}