translation params
This commit is contained in:
parent
f9fe754655
commit
642c69ceec
|
@ -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 || {}),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Reference in New Issue