// We need a vue instance to handle reactivity
var vm = null;

// The plugin
const VueTranslate = {

    // Install the method
    install(Vue) {
        const version = Vue.version[0];

        if (!vm) {
            vm = new Vue({
                data() {
                    return {
                        current: '',
                        locales: {}
                    };
                },

                computed: {
                    // Current selected language
                    lang() {
                        return this.current;
                    },

                    // Current locale values
                    locale() {
                        if (!this.locales[this.current])
                            return null;

                        return this.locales[this.current];
                    }
                },

                methods: {
                    // Set a language as current
                    setLang(val) {
                        if (this.current !== val) {
                            if (this.current === '') {
                                this.$emit('language:init', val);
                            } else {
                                this.$emit('language:changed', val);
                            }
                        }

                        this.current = val;

                        this.$emit('language:modified', val);
                    },

                    // Set a locale tu use
                    setLocales(locales) {
                        if (!locales)
                            return;

                        let newLocale = Object.create(this.locales);

                        for (let key in locales) {
                            if (!newLocale[key])
                                newLocale[key] = {};

                            Vue.util.extend(newLocale[key], locales[key]);
                        }

                        this.locales = Object.create(newLocale);

                        this.$emit('locales:loaded', locales);
                    },

                    text(t) {
                        if (!this.locale || !this.locale[t]) {
                            return t;
                        }

                        return this.locale[t];
                    },

                    textWithParams(t, params = null) {
                        if (!this.locale || !this.locale[t]) {
                            return t;
                        }

                        if (!this.params || this.params === null || typeof this.params === 'undefined') {
                            return t;
                        }

                        Object.keys(params).forEach((key) => {
                            t = t.replace(`%${key}%`, params[key]);
                        });

                        return t;
                    }
                }
            });

            Vue.prototype.$translate = vm;
        }

        // Mixin to read locales and add the translation method and directive
        Vue.mixin({
            [version === '1' ? 'init' : 'beforeCreate']() {
                this.$translate.setLocales(this.$options.locales);
            },

            methods: {
                // An alias for the .$translate.text method
                t(t) {
                    return this.$translate.text(t);
                },

                tWithParams(t, params) {
                    return this.$translate.text(t, params);
                }
            },

            directives: {
                translate: function (el) {
                    if (!el.$translateKey)
                        el.$translateKey = el.innerText;

                    let text = this.$translate.text(el.$translateKey);

                    el.innerText = text;
                }.bind(vm)
            }
        });

        // Global method for loading locales
        Vue.locales = (locales) => {
            vm.$translate.setLocales(locales);
        };

        // Global method for setting languages
        Vue.lang = (lang) => {
            vm.$translate.setLang(lang);
        };
    }
};

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);
}

@@ -2122,33 +2122,21 @@
     if (
-!this.locale %7C%7C !
+t in 
 this.loc
@@ -2130,35 +2130,32 @@
 t in this.locale
-%5Bt%5D
 ) %7B%0A            
@@ -2166,32 +2166,42 @@
             
-return t
+t = this.locale%5Bt%5D
 ;%0A          
@@ -2249,29 +2249,16 @@
 return t
-his.locale%5Bt%5D
 ;%0A      
@@ -2362,25 +2362,13 @@
 if (
-!this.locale %7C%7C !
+t in 
 this
@@ -2374,19 +2374,16 @@
 s.locale
-%5Bt%5D
 ) %7B%0A    
@@ -2402,32 +2402,42 @@
             
-return t
+t = this.locale%5Bt%5D
 ;%0A          
@@ -2482,21 +2482,16 @@
    if (!
-this.
 params %7C
@@ -2492,21 +2492,16 @@
 rams %7C%7C 
-this.
 params =
@@ -2518,21 +2518,16 @@
  typeof 
-this.
 params =
@@ -3257,16 +3257,24 @@
      t(t
+, params
 ) %7B%0A    
@@ -3316,18 +3316,36 @@
 ate.text
-(t
+WithParams(t, params
 );%0A     
@@ -3351,32 +3351,75 @@
             %7D,%0A%0A
+                // backwards compatibility%0A
                 
@@ -3490,16 +3490,26 @@
 ate.text
+WithParams
 (t, para

fix multiple textWithParams issues