adding a bunch of wip: i18n stuff
This commit is contained in:
@@ -5,6 +5,7 @@ import { createInertiaApp } from '@inertiajs/inertia-vue3';
|
||||
import { InertiaProgress } from '@inertiajs/progress';
|
||||
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
|
||||
import { ZiggyVue } from '../../vendor/tightenco/ziggy/dist/vue.m';
|
||||
import translationHelper from './base.js';
|
||||
import Notifications from 'notiwind';
|
||||
import AppLayout from './Layouts/AppLayout.vue';
|
||||
import AuthLayout from './Layouts/AuthLayout.vue';
|
||||
@@ -43,6 +44,7 @@ createInertiaApp({
|
||||
.use(plugin)
|
||||
.use(Notifications)
|
||||
.use(ZiggyVue, Ziggy)
|
||||
.mixin(translationHelper)
|
||||
.mixin({ methods: { route } })
|
||||
.mount(el);
|
||||
},
|
||||
|
||||
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