feat(locale): canvi d'idioma al vol amb F7 i persistència
This commit is contained in:
@@ -51,7 +51,7 @@ auto Locale::get() -> Locale& {
|
||||
return instance_;
|
||||
}
|
||||
|
||||
void Locale::load(const std::string& file_path) {
|
||||
auto Locale::load(const std::string& file_path) -> bool {
|
||||
// Normalitza traient prefix "data/" com fa StageLoader: el pack de
|
||||
// recursos indexa rutes relatives a `data/`.
|
||||
std::string normalized = file_path;
|
||||
@@ -62,7 +62,7 @@ void Locale::load(const std::string& file_path) {
|
||||
std::vector<uint8_t> bytes = Resource::Helper::loadFile(normalized);
|
||||
if (bytes.empty()) {
|
||||
std::cerr << "[Locale] no s'ha pogut load " << normalized << '\n';
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -72,11 +72,17 @@ void Locale::load(const std::string& file_path) {
|
||||
strings_.clear();
|
||||
flatten(yaml, "", strings_);
|
||||
std::cout << "[Locale] " << strings_.size() << " traduccions des de " << normalized << '\n';
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "[Locale] error parsejant " << normalized << ": " << e.what() << '\n';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto Locale::switchTo(const std::string& lang) -> bool {
|
||||
return load("locale/" + lang + ".yaml");
|
||||
}
|
||||
|
||||
auto Locale::text(const std::string& key) const -> std::string {
|
||||
auto it = strings_.find(key);
|
||||
if (it != strings_.end()) {
|
||||
|
||||
Reference in New Issue
Block a user