Files
laravel-stubs/src/resources/js/base.js

31 lines
819 B
JavaScript

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;
},
},
};