From 497975e3fc578f80f3cfeae9a00c9e5787157a19 Mon Sep 17 00:00:00 2001 From: Aotumuri Date: Sun, 11 Jan 2026 12:29:44 +0900 Subject: [PATCH] Fix debug translation rendering (#2848) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: Fixed a bug that prevented debug mode from working. Made it so that parameters are displayed. スクリーンショット 2026-01-10 14 24 51 translation-key::parameters ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri --- resources/lang/debug.json | 175 ------------------------------------- src/client/LangSelector.ts | 11 +++ src/client/Utils.ts | 18 +++- 3 files changed, 28 insertions(+), 176 deletions(-) delete mode 100644 resources/lang/debug.json diff --git a/resources/lang/debug.json b/resources/lang/debug.json deleted file mode 100644 index 1e7210a03..000000000 --- a/resources/lang/debug.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "lang": { - "en": "debug", - "native": "debug", - "svg": "xx", - "lang_code": "debug" - }, - "main": { - "join_discord": "main.join_discord", - "create_lobby": "main.create_lobby", - "join_lobby": "main.join_lobby", - "single_player": "main.single_player", - "instructions": "main.instructions", - "how_to_play": "main.how_to_play", - "wiki": "main.wiki" - }, - "help_modal": { - "hotkeys": "help_modal.hotkeys", - "table_key": "help_modal.table_key", - "table_action": "help_modal.table_action", - "action_alt_view": "help_modal.action_alt_view", - "action_attack_altclick": "help_modal.action_attack_altclick", - "action_build": "help_modal.action_build", - "action_center": "help_modal.action_center", - "action_zoom": "help_modal.action_zoom", - "action_move_camera": "help_modal.action_move_camera", - "action_ratio_change": "help_modal.action_ratio_change", - "action_reset_gfx": "help_modal.action_reset_gfx", - "ui_section": "help_modal.ui_section", - "ui_leaderboard": "help_modal.ui_leaderboard", - "ui_leaderboard_desc": "help_modal.ui_leaderboard_desc", - "ui_control": "help_modal.ui_control", - "ui_control_desc": "help_modal.ui_control_desc", - "ui_pop": "help_modal.ui_pop", - "ui_gold": "help_modal.ui_gold", - "ui_troops_workers": "help_modal.ui_troops_workers", - "ui_attack_ratio": "help_modal.ui_attack_ratio", - "ui_options": "help_modal.ui_options", - "ui_options_desc": "help_modal.ui_options_desc", - "option_pause": "help_modal.option_pause", - "option_timer": "help_modal.option_timer", - "option_exit": "help_modal.option_exit", - "option_settings": "help_modal.option_settings", - "radial_title": "help_modal.radial_title", - "radial_desc": "help_modal.radial_desc", - "radial_build": "help_modal.radial_build", - "radial_info": "help_modal.radial_info", - "radial_boat": "help_modal.radial_boat", - "radial_close": "help_modal.radial_close", - "info_title": "help_modal.info_title", - "info_enemy_desc": "help_modal.info_enemy_desc", - "info_target": "help_modal.info_target", - "info_alliance": "help_modal.info_alliance", - "info_emoji": "help_modal.info_emoji", - "info_ally_panel": "help_modal.info_ally_panel", - "info_ally_desc": "help_modal.info_ally_desc", - "ally_betray": "help_modal.ally_betray", - "ally_donate": "help_modal.ally_donate", - "build_menu_title": "help_modal.build_menu_title", - "build_name": "help_modal.build_name", - "build_icon": "help_modal.build_icon", - "build_desc": "help_modal.build_desc", - "build_city": "help_modal.build_city", - "build_city_desc": "help_modal.build_city_desc", - "build_defense": "help_modal.build_defense", - "build_defense_desc": "help_modal.build_defense_desc", - "build_port": "help_modal.build_port", - "build_port_desc": "help_modal.build_port_desc", - "build_warship": "help_modal.build_warship", - "build_warship_desc": "help_modal.build_warship_desc", - "build_silo": "help_modal.build_silo", - "build_silo_desc": "help_modal.build_silo_desc", - "build_sam": "help_modal.build_sam", - "build_sam_desc": "help_modal.build_sam_desc", - "build_atom": "help_modal.build_atom", - "build_atom_desc": "help_modal.build_atom_desc", - "build_hydrogen": "help_modal.build_hydrogen", - "build_hydrogen_desc": "help_modal.build_hydrogen_desc", - "build_mirv": "help_modal.build_mirv", - "build_mirv_desc": "help_modal.build_mirv_desc", - "player_icons": "help_modal.player_icons", - "icon_desc": "help_modal.icon_desc", - "icon_crown": "help_modal.icon_crown", - "icon_traitor": "help_modal.icon_traitor", - "icon_ally": "help_modal.icon_ally", - "info_enemy_panel": "help_modal.info_enemy_panel" - }, - "single_modal": { - "title": "single_modal.title", - "allow_alliances": "single_modal.allow_alliances", - "options_title": "single_modal.options_title", - "bots": "single_modal.bots", - "bots_disabled": "single_modal.bots_disabled", - "disable_nations": "single_modal.disable_nations", - "instant_build": "single_modal.instant_build", - "infinite_gold": "single_modal.infinite_gold", - "random_spawn": "single_modal.random_spawn", - "infinite_troops": "single_modal.infinite_troops", - "disable_nukes": "single_modal.disable_nukes", - "start": "single_modal.start" - }, - "map": { - "map": "map.map", - "world": "map.world", - "europe": "map.europe", - "mena": "map.mena", - "northamerica": "map.northamerica", - "oceania": "map.oceania", - "blacksea": "map.blacksea", - "africa": "map.africa", - "asia": "map.asia", - "mars": "map.mars", - "southamerica": "map.southamerica", - "britannia": "map.britannia", - "gatewaytotheatlantic": "map.gatewaytotheatlantic", - "australia": "map.australia", - "random": "map.random", - "iceland": "map.iceland", - "pangaea": "map.pangaea" - }, - "private_lobby": { - "title": "private_lobby.title", - "enter_id": "private_lobby.enter_id", - "player": "private_lobby.player", - "players": "private_lobby.players", - "join_lobby": "private_lobby.join_lobby", - "checking": "private_lobby.checking", - "not_found": "private_lobby.not_found", - "error": "private_lobby.error", - "joined_waiting": "private_lobby.joined_waiting" - }, - "public_lobby": { - "join": "public_lobby.join", - "waiting": "public_lobby.waiting" - }, - "username": { - "enter_username": "username.enter_username", - "not_string": "username.not_string", - "too_short": "username.too_short", - "too_long": "username.too_long", - "invalid_chars": "username.invalid_chars" - }, - "host_modal": { - "title": "host_modal.title", - "options_title": "host_modal.options_title", - "bots": "host_modal.bots", - "bots_disabled": "host_modal.bots_disabled", - "player_immunity_duration": "host_modal.player_immunity_duration", - "disable_nations": "host_modal.disable_nations", - "instant_build": "host_modal.instant_build", - "random_spawn": "host_modal.random_spawn", - "infinite_gold": "host_modal.infinite_gold", - "infinite_troops": "host_modal.infinite_troops", - "disable_nukes": "host_modal.disable_nukes", - "player": "host_modal.player", - "players": "host_modal.players", - "waiting": "host_modal.waiting", - "start": "host_modal.start" - }, - "game_starting_modal": { - "title": "game_starting_modal.title", - "desc": "game_starting_modal.desc" - }, - "difficulty": { - "difficulty": "difficulty.difficulty", - "Relaxed": "difficulty.Relaxed", - "Balanced": "difficulty.Balanced", - "Intense": "difficulty.Intense", - "Impossible": "difficulty.Impossible" - }, - "heads_up_message": { - "choose_spawn": "heads_up_message.choose_spawn", - "random_spawn": "heads_up_message.random_spawn" - } -} diff --git a/src/client/LangSelector.ts b/src/client/LangSelector.ts index 5056293db..3d446f348 100644 --- a/src/client/LangSelector.ts +++ b/src/client/LangSelector.ts @@ -2,6 +2,7 @@ import { LitElement, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import "./LanguageModal"; import { LanguageModal } from "./LanguageModal"; +import { formatDebugTranslation } from "./Utils"; import en from "../../resources/lang/en.json"; import metadata from "../../resources/lang/metadata.json"; @@ -104,6 +105,12 @@ export class LangSelector extends LitElement { const cached = this.languageCache.get(lang); if (cached) return cached; + if (lang === "debug") { + const empty: Record = {}; + this.languageCache.set(lang, empty); + return empty; + } + if (lang === "en") { const flat = flattenTranslations(en); this.languageCache.set(lang, flat); @@ -249,6 +256,10 @@ export class LangSelector extends LitElement { key: string, params: Record = {}, ): string { + if (this.currentLang === "debug") { + return formatDebugTranslation(key, params); + } + let text: string | undefined; if (this.translations && key in this.translations) { text = this.translations[key]; diff --git a/src/client/Utils.ts b/src/client/Utils.ts index 9bded69e2..93f51026b 100644 --- a/src/client/Utils.ts +++ b/src/client/Utils.ts @@ -1,6 +1,6 @@ import IntlMessageFormat from "intl-messageformat"; import { MessageType } from "../core/game/Game"; -import { LangSelector } from "./LangSelector"; +import type { LangSelector } from "./LangSelector"; export function renderDuration(totalSeconds: number): string { if (totalSeconds <= 0) return "0s"; @@ -150,6 +150,18 @@ export function generateCryptoRandomUUID(): string { ); } +export function formatDebugTranslation( + key: string, + params: Record, +): string { + const entries = Object.entries(params); + if (entries.length === 0) return key; + const serializedParams = entries + .map(([paramKey, value]) => `${paramKey}=${String(value)}`) + .join(","); + return `${key}::${serializedParams}`; +} + export const translateText = ( key: string, params: Record = {}, @@ -164,6 +176,10 @@ export const translateText = ( return key; } + if (langSelector.currentLang === "debug") { + return formatDebugTranslation(key, params); + } + if ( !langSelector.translations || Object.keys(langSelector.translations).length === 0