-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc735fc
commit 3dff416
Showing
3 changed files
with
114 additions
and
80 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/javisperez/vuetranslate/issues" | ||
}, | ||
"homepage": "https://github.com/javisperez/vuetranslate#readme" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,102 +8,99 @@ | |
* @author Javis Perez <[email protected]> | ||
* 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); | ||
} |