MetaImGUI 1.0.0
ImGui Application Template for C++20
Loading...
Searching...
No Matches
Localization.h
Go to the documentation of this file.
1/*
2 MetaImGUI
3 Copyright (C) 2026 A P Nicholson
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
17*/
18
19#pragma once
20
21#include <map>
22#include <string>
23#include <vector>
24
25namespace MetaImGUI {
26
37public:
41 static Localization& Instance();
42
43 // Delete copy and move
44 Localization(const Localization&) = delete;
48
53 void SetLanguage(const std::string& languageCode);
54
58 [[nodiscard]] std::string GetCurrentLanguage() const;
59
63 [[nodiscard]] std::vector<std::string> GetAvailableLanguages() const;
64
70 [[nodiscard]] std::string Tr(const std::string& key) const;
71
78 void AddTranslation(const std::string& languageCode, const std::string& key, const std::string& value);
79
85 bool LoadTranslations(const std::string& filepath);
86
87private:
89 ~Localization() = default;
90
91 std::string m_currentLanguage;
92 std::map<std::string, std::map<std::string, std::string>> m_translations; // [language][key] = value
93};
94
95} // namespace MetaImGUI
96
97// Convenience macro for translation
98#define TR(key) MetaImGUI::Localization::Instance().Tr(key)
Simple localization/internationalization system.
Localization(const Localization &)=delete
static Localization & Instance()
Get singleton instance.
Localization(Localization &&)=delete
void SetLanguage(const std::string &languageCode)
Set current language.
std::vector< std::string > GetAvailableLanguages() const
Get list of available languages.
std::string Tr(const std::string &key) const
Get translated string.
bool LoadTranslations(const std::string &filepath)
Load translations from JSON file.
std::string GetCurrentLanguage() const
Get current language code.
Localization & operator=(const Localization &)=delete
void AddTranslation(const std::string &languageCode, const std::string &key, const std::string &value)
Add translation for a language.
Localization & operator=(Localization &&)=delete