23#include <nlohmann/json.hpp>
27using json = nlohmann::json;
48Localization::Localization() : m_currentLanguage(
"en") {
58 if (m_translations.contains(languageCode)) {
59 m_currentLanguage = languageCode;
60 LOG_INFO(
"Language set to: {}", languageCode);
62 LOG_ERROR(
"Language not available: {}", languageCode);
67 return m_currentLanguage;
71 std::vector<std::string> languages;
72 languages.reserve(m_translations.size());
73 for (
const auto& pair : m_translations) {
74 languages.push_back(pair.first);
81 auto langIt = m_translations.find(m_currentLanguage);
82 if (langIt != m_translations.end()) {
83 auto keyIt = langIt->second.find(key);
84 if (keyIt != langIt->second.end()) {
90 if (m_currentLanguage !=
"en") {
91 auto enIt = m_translations.find(
"en");
92 if (enIt != m_translations.end()) {
93 auto keyIt = enIt->second.find(key);
94 if (keyIt != enIt->second.end()) {
105 m_translations[languageCode][key] = value;
110 std::ifstream file(filepath);
111 if (!file.is_open()) {
112 LOG_ERROR(
"Failed to open translations file: {}", filepath);
116 json j = json::parse(file);
118 for (
const auto& [languageCode, translations] : j.items()) {
119 for (
const auto& [key, value] : translations.items()) {
124 LOG_INFO(
"Loaded translations from: {}", filepath);
126 }
catch (
const std::exception& e) {
127 LOG_ERROR(
"Failed to load translations: {}", e.what());