From 30ed2015bca612560d2c408b8946da7a33c472ba Mon Sep 17 00:00:00 2001 From: poly000 <1348292515@qq.com> Date: Mon, 25 Mar 2024 19:11:38 +0800 Subject: [PATCH] feat: do not fallback locale key --- src/menu/mod.rs | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/src/menu/mod.rs b/src/menu/mod.rs index 26ec021..ec8a460 100644 --- a/src/menu/mod.rs +++ b/src/menu/mod.rs @@ -676,40 +676,18 @@ impl Menu { ); batch.draw(ctx)?; } else { - fn translate_fallback<'a>(result: &'a str, key: &'_ str, fallback: &'a str) -> &'a str { - if result == key { - return fallback; - } - result - } - let loc = &state.loc; let difficulty = match save.difficulty { - 0 => { - let key = "menus.difficulty_menu.normal"; - translate_fallback(loc.t(key), key, "Normal") - } - 2 => { - let key = "menus.difficulty_menu.easy"; - translate_fallback(loc.t(key), key, "Easy") - } - 4 => { - let key = "menus.difficulty_menu.hard"; - translate_fallback(loc.t(key), key, "Hard") - } - _ => { - let key = "menus.difficulty_menu.unknown"; - translate_fallback(loc.t(key), key, "(unknown)") - } + 0 => loc.t("menus.difficulty_menu.normal"), + 2 => loc.t("menus.difficulty_menu.easy"), + 4 => loc.t("menus.difficulty_menu.hard"), + _ => loc.t("menus.difficulty_menu.unknown"), }; - let diff_key = "menus.difficulty_menu.difficulty_name"; - let result = loc.tt(diff_key, &[("difficulty", &difficulty)]); - let fallback = "Difficulty: ".to_owned() + &difficulty; let difficulty_name = - translate_fallback(&result, diff_key, &fallback); + loc.tt("menus.difficulty_menu.difficulty_name", &[("difficulty", &difficulty)]); state.font.builder().position(self.x as f32 + 20.0, y + 10.0).draw( - difficulty_name, + &difficulty_name, ctx, &state.constants, &mut state.texture_set,