From fbded9c00514d4c24ca287b824446cded76901ef Mon Sep 17 00:00:00 2001 From: Javis Perez Date: Mon, 29 Aug 2016 10:20:20 -0400 Subject: [PATCH] Vue 1 is now supported --- README.md | 6 +----- dist/vue-translate.min.js | 5 +++-- package.json | 4 ++-- vue-translate.js | 8 +++++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 99bf6f8..882fb3c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## VueTranslate -A VueJS (2.0+) plugin for basic translations. +A VueJS (1.x, 2.0+) plugin for basic translations. ### What is this? @@ -14,10 +14,6 @@ Yes and no, Vue-i18n is a great plugin and is a lot more complete than this. Thi Just translations, it is that simple. -### Why VueJS v2.0 only? - -Because it's the current version i'm using, so i haven't test it on VueJS 1.x but i think it won't work because the "init()" method is called "beforeCreate()" on VueJS 2.x. - ## Example ```javascript import Vue from 'vue'; diff --git a/dist/vue-translate.min.js b/dist/vue-translate.min.js index bda112c..93c633f 100644 --- a/dist/vue-translate.min.js +++ b/dist/vue-translate.min.js @@ -1,3 +1,4 @@ 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 +VueTranslate.install=function(c){var f=c.version[0];vm||(vm=new c({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),d;for(d in a)b[d]||(b[d]={}),c.util.extend(b[d],a[d]);this.locales=Object.create(b)}},text:function(a){return this.locale&&this.locale[a]?this.locale[a]:a}}}),c.prototype.$translate=vm); +var e={};c.mixin((e["1"===f?"init":"beforeCreate"]=function(){this.$translate.setLocales(this.$options.locales)},e.methods={t:function(a){return this.$translate.text(a)}},e.directives={translate:function(a){a.$translateKey||(a.$translateKey=a.innerText);var b=this.$translate.text(a.$translateKey);a.innerText=b}.bind(vm)},e))}; +"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 index f5ba4e3..c25a2df 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-translate-plugin", - "version": "1.0.0", - "description": "Basic translations plugins for VueJS v2.0+", + "version": "1.0.3", + "description": "Basic translations plugins for VueJS (1.x, 2.0)", "main": "dist/vue-translate.min.js", "files": [ "dist/vue.common.js", diff --git a/vue-translate.js b/vue-translate.js index a42e76c..5bac436 100644 --- a/vue-translate.js +++ b/vue-translate.js @@ -1,7 +1,7 @@ /** * VueTranslate plugin * - * Handle basic translations in VueJS 2.0 + * Handle basic translations in VueJS * * This is a plugin to handle basic translations for a component in VueJS. * @@ -19,6 +19,8 @@ function VueTranslate() {} // Install the method VueTranslate.install = function (Vue) { + let version = Vue.version[0]; + if (!vm) { vm = new Vue({ data() { @@ -73,7 +75,7 @@ VueTranslate.install = function (Vue) { // Mixin to read locales and add the translation method and directive Vue.mixin({ - beforeCreate() { + [version === '1' ? 'init' : 'beforeCreate']() { this.$translate.setLocales(this.$options.locales); }, @@ -103,4 +105,4 @@ if (typeof exports === 'object') { } else if (window.Vue) { window.VueTranslate = VueTranslate; // Browser (not required options) Vue.use(VueTranslate); -} +} \ No newline at end of file