Änderung: Verbesserung der MessageDialog-Komponente und Integration von Übersetzungen

Änderungen:
- Anpassung des MessageDialog zur Unterstützung von dynamischen Titeln und Schaltflächen mit Übersetzungen.
- Implementierung einer Methode zur Interpolation von Platzhaltern in Nachrichten.
- Erweiterung der i18n-Übersetzungen für Crash-Nachrichten im Minispiel.
- Aktualisierung der TaxiGame.vue zur Anzeige von Unfallmeldungen über den MessageDialog.

Diese Anpassungen verbessern die Benutzererfahrung durch mehrsprachige Unterstützung und dynamische Nachrichten im Taxi-Minispiel.
This commit is contained in:
Torsten Schulz (local)
2025-09-15 23:05:18 +02:00
parent 643c152194
commit 3f33da06e5
7 changed files with 372 additions and 55 deletions

View File

@@ -1,6 +1,6 @@
<template>
<DialogWidget ref="dialog" title="message.title" :show-close="true" :buttons="buttons" :modal="true" width="25em"
height="15em" name="MessageDialog" :isTitleTranslated=true>
<DialogWidget ref="dialog" :title="translatedTitle" :show-close="true" :buttons="translatedButtons" :modal="true" width="25em"
height="15em" name="MessageDialog" :isTitleTranslated=false>
<div class="message-content">
<p>{{ translatedMessage }}</p>
</div>
@@ -18,26 +18,80 @@ export default {
data() {
return {
message: '',
title: '',
parameters: {},
onClose: null,
buttons: [
{ text: 'message.close', action: 'close' }
{ text: 'tr:message.close', action: 'close' }
]
};
},
computed: {
translatedTitle() {
if (this.title.startsWith('tr:')) {
return this.$t(this.title.substring(3));
}
if (this.title) {
return this.title;
}
// Standard-Titel je nach Sprache
return this.$t('message.title');
},
translatedMessage() {
if (this.message.startsWith('tr:')) {
return this.$t(this.message.substring(3));
const i18nKey = this.message.substring(3);
const translation = this.$t(i18nKey);
console.log('translatedMessage:', {
i18nKey: i18nKey,
translation: translation,
parameters: this.parameters,
allMinigames: this.$t('minigames'),
crashSection: this.$t('minigames.taxi.crash')
});
// Ersetze Parameter in der Übersetzung
return this.interpolateParameters(translation);
}
return this.message;
},
translatedButtons() {
return this.buttons.map(button => ({
...button,
text: button.text.startsWith('tr:') ? this.$t(button.text.substring(3)) : button.text
}));
}
},
methods: {
open(message) {
open(message, title = '', parameters = {}, onClose = null) {
this.message = message;
this.title = title;
this.parameters = parameters;
this.onClose = onClose;
this.$refs.dialog.open();
},
close() {
this.$refs.dialog.close();
// Rufe Callback auf, wenn vorhanden
if (this.onClose && typeof this.onClose === 'function') {
this.onClose();
}
},
interpolateParameters(text) {
// Ersetze {key} Platzhalter mit den entsprechenden Werten
let result = text;
console.log('interpolateParameters:', {
originalText: text,
parameters: this.parameters
});
for (const [key, value] of Object.entries(this.parameters)) {
const placeholder = `{${key}}`;
const regex = new RegExp(placeholder.replace(/[{}]/g, '\\$&'), 'g');
result = result.replace(regex, value);
console.log(`Replaced ${placeholder} with ${value}:`, result);
}
console.log('Final result:', result);
return result;
}
}
};