feat(locale): canvi d'idioma al vol amb F7 i persistència

This commit is contained in:
2026-05-24 10:35:39 +02:00
parent 35d720bb77
commit c4c6881bd6
5 changed files with 48 additions and 4 deletions
+21
View File
@@ -10,6 +10,7 @@
#include "core/locale/locale.hpp"
#include "core/rendering/sdl_manager.hpp"
#include "core/system/notifier.hpp"
#include "game/config_yaml.hpp"
#include "scene_context.hpp"
// Using declarations per simplificar el codi
@@ -63,6 +64,26 @@ namespace GlobalEvents {
sdl.togglePostFx();
return true;
case SDL_SCANCODE_F7: {
// Toggle d'idioma en runtime entre català i anglès. Els
// strings ja capturats (toast actiu, banner stage start)
// sobreviuen fins al seu cicle; la resta (HUD, pantalles,
// pròxims toasts) es refresquen al següent frame perquè
// criden Locale::text() cada draw.
const std::string NEW_LANG = (ConfigYaml::engine_config.locale == "ca") ? "en" : "ca";
if (Locale::get().switchTo(NEW_LANG)) {
ConfigYaml::engine_config.locale = NEW_LANG;
ConfigYaml::saveToFile();
if (auto* notifier = System::Notifier::get(); notifier != nullptr) {
notifier->notifyInfo(localeSubstitute(
Locale::get().text("notification.locale_switched"),
"{lang}",
Locale::get().text("language." + NEW_LANG)));
}
}
return true;
}
case SDL_SCANCODE_ESCAPE: {
// Doble pulsació per confirmar sortida: la primera ESC
// dispara un toast d'avís; només si aquest toast concret