adding a bunch of wip: i18n stuff
This commit is contained in:
30
src/resources/js/base.js
Normal file
30
src/resources/js/base.js
Normal 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;
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user