Level 15
I've used the following strategy:
I've shared the following translation data:
class HandleInertiaRequests extends Middleware
...
public function share(Request $request)
{
...
'trans' => [
'common' => LanguageLine::getTranslationsForGroup(app()->currentLocale(),'common')
],
...
}
...
Created trans() function and global mixin
export default function(group, key) {
let value = _.get(this.$page.props.trans[group], key);
if (value) {
return value;
} else {
return key;
}
}
import trans from '@/utils/trans';
Vue.prototype.$trans = trans;
Vue.mixin({
methods: {
trans: trans
},
});
used trans() in vue component as:
<template>
...
<h1> trans('common', 'dashboard') </h1>
...
</template>