adding a bunch of wip: i18n stuff

This commit is contained in:
2022-11-28 12:32:48 -07:00
parent 995cc32578
commit 3f340d57fc
10 changed files with 301 additions and 53 deletions

30
src/resources/js/base.js Normal file
View File

@@ -0,0 +1,30 @@
export default {
methods: {
__(key, replace = {}) {
let translation = ''
// check for dot notation
if (key.includes('.')) {
translation = this.$page.props.language
key.split('.').forEach(subKey => {
translation = translation[subKey]
}, key)
} else {
// check if it exists on the translated strings we got
if (this.$page.props.language.hasOwnProperty(key)) {
translation = this.$page.props.language[key]
} else {
// otherwise just take it raw
translation = key
}
}
// used to fill in variables for translation string
Object.keys(replace).forEach(key => {
translation = translation.replace(':' + key, replace[key])
});
return translation;
},
},
};