1
0
mirror of synced 2024-11-28 01:20:51 +01:00
ImHex/lib/libimhex/include/hex/api/localization.hpp
WerWolv 1991afb87b
sys: Get rid of SharedData struct and cleanup code structure (#411)
* sys: Initial refactoring of the SharedData class

* sys/pattern: More refactoring, make every provider have its own patterns

* sys: Finished up refactoring. No more SharedData!

* sys: Fixed compile on Unix

* tests: Fixed unit tests

* sys: Moved view and lang files

* pattern: Added assignment operator support to for loops

* tests: Fixed compile issue
2022-02-01 18:09:40 +01:00

59 lines
1.9 KiB
C++

#pragma once
#include <initializer_list>
#include <map>
#include <string>
#include <string_view>
namespace hex {
class LanguageDefinition {
public:
LanguageDefinition(std::initializer_list<std::pair<std::string, std::string>> entries);
const std::map<std::string, std::string> &getEntries() const;
private:
std::map<std::string, std::string> m_entries;
};
class LangEntry {
public:
explicit LangEntry(const char *unlocalizedString);
explicit LangEntry(const std::string &unlocalizedString);
explicit LangEntry(std::string_view unlocalizedString);
operator std::string() const;
operator std::string_view() const;
operator const char *() const;
[[nodiscard]] const std::string &get() const;
static void loadLanguage(const std::string &language);
static const std::map<std::string, std::string> &getSupportedLanguages();
static void setFallbackLanguage(const std::string &language);
static const std::string &getFallbackLanguage();
static void resetLanguageStrings();
private:
std::string m_unlocalizedString;
static std::string s_fallbackLanguage;
static std::map<std::string, std::string> s_currStrings;
};
std::string operator+(const std::string &&left, const LangEntry &&right);
std::string operator+(const LangEntry &&left, const std::string &&right);
std::string operator+(const std::string_view &&left, const LangEntry &&right);
std::string operator+(const LangEntry &&left, const std::string_view &&right);
std::string operator+(const char *left, const LangEntry &&right);
std::string operator+(const LangEntry &&left, const char *right);
std::string operator+(const LangEntry &&left, const LangEntry &&right);
inline LangEntry operator""_lang(const char *string, size_t) {
return LangEntry(string);
}
}