WIP: frontend optimierungen & sprachkorrekturen
This commit is contained in:
@@ -16,6 +16,20 @@ library.add(faPrint, faMagicWandSparkles, faXmark);
|
||||
|
||||
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
|
||||
|
||||
const resolveTranslation = (source, path) => {
|
||||
if (!source || !path) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return path.split('.').reduce((acc, segment) => {
|
||||
if (acc && Object.prototype.hasOwnProperty.call(acc, segment)) {
|
||||
return acc[segment];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}, source);
|
||||
};
|
||||
|
||||
createInertiaApp({
|
||||
title: (title) => `${title} - ${appName}`,
|
||||
resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
|
||||
@@ -27,18 +41,29 @@ createInertiaApp({
|
||||
.component('font-awesome-icon', FontAwesomeIcon) // Register Font Awesome component
|
||||
.mixin({
|
||||
methods: {
|
||||
__: (key, replace = {}) => {
|
||||
let translation = props.initialPage.props.translations[key];
|
||||
__: function (key, replace = {}) {
|
||||
const sources = [
|
||||
this?.$page?.props?.translations,
|
||||
props.initialPage.props.translations,
|
||||
];
|
||||
|
||||
if (translation === undefined) {
|
||||
translation = key; // Fallback to key if translation not found
|
||||
let translation;
|
||||
|
||||
for (const source of sources) {
|
||||
const value = resolveTranslation(source, key);
|
||||
if (value !== undefined) {
|
||||
translation = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (let placeholder in replace) {
|
||||
translation = translation.replace(`:${placeholder}`, replace[placeholder]);
|
||||
}
|
||||
let output = translation ?? key;
|
||||
|
||||
return translation;
|
||||
Object.entries(replace).forEach(([placeholder, val]) => {
|
||||
output = output.replace(`:${placeholder}`, val);
|
||||
});
|
||||
|
||||
return output;
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -47,4 +72,4 @@ createInertiaApp({
|
||||
progress: {
|
||||
color: '#4B5563',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user