diff --git a/frontend/src/dialogues/standard/MessageDialog.vue b/frontend/src/dialogues/standard/MessageDialog.vue index ff9457c..f78be92 100644 --- a/frontend/src/dialogues/standard/MessageDialog.vue +++ b/frontend/src/dialogues/standard/MessageDialog.vue @@ -1,6 +1,6 @@ - + {{ translatedMessage }} @@ -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; } } }; diff --git a/frontend/src/i18n/index.js b/frontend/src/i18n/index.js index 9f7e8d2..224a8a8 100644 --- a/frontend/src/i18n/index.js +++ b/frontend/src/i18n/index.js @@ -17,6 +17,7 @@ import enFalukant from './locales/en/falukant.json'; import enPasswordReset from './locales/en/passwordReset.json'; import enBlog from './locales/en/blog.json'; import enMinigames from './locales/en/minigames.json'; +import enMessage from './locales/en/message.json'; import deGeneral from './locales/de/general.json'; import deHeader from './locales/de/header.json'; @@ -34,6 +35,7 @@ import deFalukant from './locales/de/falukant.json'; import dePasswordReset from './locales/de/passwordReset.json'; import deBlog from './locales/de/blog.json'; import deMinigames from './locales/de/minigames.json'; +import deMessage from './locales/de/message.json'; const messages = { en: { @@ -53,6 +55,7 @@ const messages = { ...enFalukant, ...enBlog, ...enMinigames, + ...enMessage, }, de: { 'Ok': 'Ok', @@ -72,6 +75,7 @@ const messages = { ...deFalukant, ...deBlog, ...deMinigames, + ...deMessage, } }; diff --git a/frontend/src/i18n/locales/de/message.json b/frontend/src/i18n/locales/de/message.json new file mode 100644 index 0000000..993f528 --- /dev/null +++ b/frontend/src/i18n/locales/de/message.json @@ -0,0 +1,7 @@ +{ + "message": { + "title": "Mitteilung", + "close": "Schließen", + "test": "Test funktioniert" + } +} diff --git a/frontend/src/i18n/locales/de/minigames.json b/frontend/src/i18n/locales/de/minigames.json index 75c2876..d95b344 100644 --- a/frontend/src/i18n/locales/de/minigames.json +++ b/frontend/src/i18n/locales/de/minigames.json @@ -63,7 +63,11 @@ "deliverPassenger": "Passagier abliefern", "refuel": "Tanken", "startEngine": "Motor starten", - "stopEngine": "Motor stoppen" + "stopEngine": "Motor stoppen", + "crash": { + "title": "Unfall!", + "message": "Du hattest einen Unfall! Crashes: {crashes}" + } } } } diff --git a/frontend/src/i18n/locales/en/message.json b/frontend/src/i18n/locales/en/message.json new file mode 100644 index 0000000..8df2c14 --- /dev/null +++ b/frontend/src/i18n/locales/en/message.json @@ -0,0 +1,6 @@ +{ + "message": { + "title": "Notice", + "close": "Close" + } +} diff --git a/frontend/src/i18n/locales/en/minigames.json b/frontend/src/i18n/locales/en/minigames.json index 3bf11ad..1ea3598 100644 --- a/frontend/src/i18n/locales/en/minigames.json +++ b/frontend/src/i18n/locales/en/minigames.json @@ -63,7 +63,11 @@ "deliverPassenger": "Deliver Passenger", "refuel": "Refuel", "startEngine": "Start Engine", - "stopEngine": "Stop Engine" + "stopEngine": "Stop Engine", + "crash": { + "title": "Crash!", + "message": "You had an accident! Crashes: {crashes}" + } } } } diff --git a/frontend/src/views/minigames/TaxiGame.vue b/frontend/src/views/minigames/TaxiGame.vue index 2caff85..87a88d5 100644 --- a/frontend/src/views/minigames/TaxiGame.vue +++ b/frontend/src/views/minigames/TaxiGame.vue @@ -13,7 +13,7 @@ - + {{ $t('minigames.taxi.paused') }} @@ -126,6 +126,11 @@ {{ $t('minigames.taxi.passengers') }} + + {{ crashes }} + Unfälle + + {{ fuel }}% {{ $t('minigames.taxi.fuel') }} @@ -162,24 +167,31 @@ +
{{ translatedMessage }}