WIP: frontend optimierungen & sprachkorrekturen

This commit is contained in:
soeren
2025-11-13 19:55:50 +01:00
parent cf41055cbd
commit 3f52f124ef
11 changed files with 136 additions and 107 deletions

View File

@@ -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',
},
});
});