#ifndef LOCALIZATION_H #define LOCALIZATION_H #include "pch.h" #include "utils.h" namespace Localization { using Key = uint16_t; // Maps localization keys to their string identifiers. This is used for text elements to look up the correct localized string. inline std::unordered_map localization_key_map; using LanguageCode = uint32_t; // 32-bit integer to store the language code (e.g., "en", "fr", "es") inline LanguageCode current_language = 'e' << 24 | 'n' << 16; using JoinedKey = uint64_t; // 64-bit integer to store the joined language code and key inline JoinedKey join_keys(LanguageCode lang_code, Key loc_key) { return (static_cast(lang_code) << 16) | loc_key; } struct Segment { bool is_var; std::string text; }; inline std::unordered_map> localized_strings; inline std::unordered_map var_sym_cache; std::vector parse_localized(const std::string &input); inline void set(LanguageCode lang_code, Key key, const std::string &text) { localized_strings[join_keys(lang_code, key)] = parse_localized(text); } mrb_sym get_var_sym(mrb_state *mrb, const std::string &name); std::string get(Key key, const std::unordered_map ¶ms); LanguageCode lang_from_sym(mrb_state *mrb, mrb_sym sym); mrb_sym lang_to_sym(mrb_state *mrb, LanguageCode code); std::string get_key_name(Key key); } // namespace Localization #endif