forked from jaildesigner-jailgames/jaildoctors_dilemma
fix: no es llegien els fitxers de Locale desde resources.pack
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||||
@@ -15,6 +16,12 @@ void Locale::init(const std::string& file_path) { // NOLINT(readability-convert
|
|||||||
Locale::instance->loadFromFile(file_path);
|
Locale::instance->loadFromFile(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Crea el objeto desde contenido en memoria (para release con pack)
|
||||||
|
void Locale::initFromContent(const std::string& content) { // NOLINT(readability-convert-member-functions-to-static)
|
||||||
|
Locale::instance = new Locale();
|
||||||
|
Locale::instance->loadFromContent(content);
|
||||||
|
}
|
||||||
|
|
||||||
// [SINGLETON] Destruye el objeto con esta función estática
|
// [SINGLETON] Destruye el objeto con esta función estática
|
||||||
void Locale::destroy() {
|
void Locale::destroy() {
|
||||||
delete Locale::instance;
|
delete Locale::instance;
|
||||||
@@ -55,6 +62,24 @@ void Locale::flatten(const void* node_ptr, const std::string& prefix) { // NOLI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Carga las traducciones desde contenido YAML en memoria
|
||||||
|
void Locale::loadFromContent(const std::string& content) { // NOLINT(readability-convert-member-functions-to-static)
|
||||||
|
if (content.empty()) {
|
||||||
|
std::cerr << "Locale: contenido vacío, sin traducciones cargadas\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::istringstream stream(content);
|
||||||
|
auto yaml = fkyaml::node::deserialize(stream);
|
||||||
|
flatten(&yaml, "");
|
||||||
|
|
||||||
|
std::cout << "Locale: " << strings_.size() << " traducciones cargadas desde pack\n";
|
||||||
|
} catch (const fkyaml::exception& e) {
|
||||||
|
std::cerr << "Locale: error al parsear YAML: " << e.what() << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Carga las traducciones desde el fichero YAML indicado
|
// Carga las traducciones desde el fichero YAML indicado
|
||||||
void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability-convert-member-functions-to-static)
|
void Locale::loadFromFile(const std::string& file_path) { // NOLINT(readability-convert-member-functions-to-static)
|
||||||
if (file_path.empty()) {
|
if (file_path.empty()) {
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
// No se permite cambio de idioma en caliente.
|
// No se permite cambio de idioma en caliente.
|
||||||
class Locale {
|
class Locale {
|
||||||
public:
|
public:
|
||||||
static void init(const std::string& file_path); // Crea e inicializa el singleton
|
static void init(const std::string& file_path); // Crea e inicializa el singleton
|
||||||
static void destroy(); // Destruye el singleton
|
static void initFromContent(const std::string& content); // Crea e inicializa desde contenido en memoria (pack)
|
||||||
static auto get() -> Locale*; // Devuelve el singleton
|
static void destroy(); // Destruye el singleton
|
||||||
|
static auto get() -> Locale*; // Devuelve el singleton
|
||||||
|
|
||||||
// Devuelve la traducción de la clave dada.
|
// Devuelve la traducción de la clave dada.
|
||||||
// Si la clave no existe, devuelve la propia clave como fallback.
|
// Si la clave no existe, devuelve la propia clave como fallback.
|
||||||
@@ -19,6 +20,7 @@ class Locale {
|
|||||||
private:
|
private:
|
||||||
Locale() = default;
|
Locale() = default;
|
||||||
void loadFromFile(const std::string& file_path);
|
void loadFromFile(const std::string& file_path);
|
||||||
|
void loadFromContent(const std::string& content);
|
||||||
void flatten(const void* node_ptr, const std::string& prefix); // Aplana nodos YAML anidados
|
void flatten(const void* node_ptr, const std::string& prefix); // Aplana nodos YAML anidados
|
||||||
|
|
||||||
static Locale* instance;
|
static Locale* instance;
|
||||||
|
|||||||
@@ -189,8 +189,13 @@ Director::Director() {
|
|||||||
|
|
||||||
// Inicializa el sistema de localización (antes de Cheevos que usa textos traducidos)
|
// Inicializa el sistema de localización (antes de Cheevos que usa textos traducidos)
|
||||||
#ifdef RELEASE_BUILD
|
#ifdef RELEASE_BUILD
|
||||||
std::string locale_path = executable_path_ + PREFIX + "/data/locale/" + Options::language + ".yaml";
|
{
|
||||||
Locale::init(locale_path);
|
// En release el locale está en el pack, no en el filesystem
|
||||||
|
std::string locale_key = Resource::List::get()->get(Options::language + ".yaml"); // NOLINT(readability-static-accessed-through-instance)
|
||||||
|
auto locale_bytes = Resource::Helper::loadFile(locale_key);
|
||||||
|
std::string locale_content(locale_bytes.begin(), locale_bytes.end());
|
||||||
|
Locale::initFromContent(locale_content);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
Locale::init(Resource::List::get()->get(Options::language + ".yaml")); // NOLINT(readability-static-accessed-through-instance)
|
Locale::init(Resource::List::get()->get(Options::language + ".yaml")); // NOLINT(readability-static-accessed-through-instance)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user