translation params

This commit is contained in:
Avris 2020-10-14 21:46:39 +02:00
parent f9fe754655
commit 642c69ceec
2 changed files with 11 additions and 2 deletions

View File

@ -13,9 +13,12 @@
import t from '../src/translator';
export default {
props: {
params: {},
},
data() {
return {
txt: t(this.$slots.default[0].text),
txt: t(this.$slots.default[0].text, this.params || {}),
}
},
}

View File

@ -1,6 +1,6 @@
import translations from '../data/translations.suml';
export default key => {
export default (key, params = {}) => {
let value = translations;
for (let part of key.split('.')) {
value = value[part];
@ -10,5 +10,11 @@ export default key => {
}
}
for (let k in params) {
if (params.hasOwnProperty(k)) {
value = value.replace(new RegExp('%' + k + '%', 'g'), params[k])
}
}
return value;
}