55f4b4d933
- Add pool struct for data pools
28 lines
954 B
C++
28 lines
954 B
C++
#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.
|
|
extern std::unordered_map<std::string, Key> localization_key_map;
|
|
|
|
using LanguageCode = uint32_t; // 32-bit integer to store the language code (e.g., "en", "fr", "es")
|
|
|
|
extern LanguageCode current_language; // The currently active language code
|
|
|
|
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<JoinedKey>(lang_code) << 16) | loc_key;
|
|
}
|
|
|
|
extern std::unordered_map<JoinedKey, std::string> localized_strings;
|
|
|
|
inline std::string get(Key key) {
|
|
auto it = localized_strings.find(join_keys(current_language, key));
|
|
if (it != localized_strings.end())
|
|
return it->second;
|
|
return "";
|
|
}
|
|
} // namespace Localization
|