2021-02-10 17:17:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-02-10 23:35:30 +00:00
|
|
|
#include <initializer_list>
|
2021-02-10 17:17:09 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <string_view>
|
|
|
|
|
2023-05-06 08:07:22 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2021-02-10 17:17:09 +00:00
|
|
|
namespace hex {
|
|
|
|
|
2021-02-10 23:35:30 +00:00
|
|
|
class LanguageDefinition {
|
|
|
|
public:
|
2022-12-02 11:00:04 +00:00
|
|
|
explicit LanguageDefinition(std::map<std::string, std::string> &&entries);
|
2021-02-10 23:35:30 +00:00
|
|
|
|
2022-03-04 19:52:39 +00:00
|
|
|
[[nodiscard]] const std::map<std::string, std::string> &getEntries() const;
|
2021-02-10 23:35:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, std::string> m_entries;
|
|
|
|
};
|
|
|
|
|
2021-02-10 17:17:09 +00:00
|
|
|
class LangEntry {
|
|
|
|
public:
|
2021-02-13 14:15:32 +00:00
|
|
|
explicit LangEntry(const char *unlocalizedString);
|
2022-03-04 19:52:39 +00:00
|
|
|
explicit LangEntry(std::string unlocalizedString);
|
2021-02-13 14:15:32 +00:00
|
|
|
explicit LangEntry(std::string_view unlocalizedString);
|
2021-02-10 17:17:09 +00:00
|
|
|
|
|
|
|
operator std::string() const;
|
|
|
|
operator std::string_view() const;
|
2022-01-24 19:53:17 +00:00
|
|
|
operator const char *() const;
|
2021-02-10 17:17:09 +00:00
|
|
|
|
2022-01-24 19:53:17 +00:00
|
|
|
[[nodiscard]] const std::string &get() const;
|
2021-02-10 17:17:09 +00:00
|
|
|
|
2022-01-23 21:08:19 +00:00
|
|
|
static void loadLanguage(const std::string &language);
|
2022-01-24 19:53:17 +00:00
|
|
|
static const std::map<std::string, std::string> &getSupportedLanguages();
|
2021-02-10 17:17:09 +00:00
|
|
|
|
2022-01-23 21:08:19 +00:00
|
|
|
static void setFallbackLanguage(const std::string &language);
|
2022-01-24 19:53:17 +00:00
|
|
|
static const std::string &getFallbackLanguage();
|
2022-01-23 21:08:19 +00:00
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
static void resetLanguageStrings();
|
|
|
|
|
2021-02-10 17:17:09 +00:00
|
|
|
private:
|
|
|
|
std::string m_unlocalizedString;
|
2022-01-23 21:08:19 +00:00
|
|
|
|
|
|
|
static std::string s_fallbackLanguage;
|
2022-02-01 17:09:40 +00:00
|
|
|
static std::map<std::string, std::string> s_currStrings;
|
2021-02-10 17:17:09 +00:00
|
|
|
};
|
|
|
|
|
2021-02-11 22:09:45 +00:00
|
|
|
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);
|
|
|
|
|
2022-02-01 17:09:40 +00:00
|
|
|
inline LangEntry operator""_lang(const char *string, size_t) {
|
|
|
|
return LangEntry(string);
|
2021-02-10 17:17:09 +00:00
|
|
|
}
|
|
|
|
|
2023-05-06 08:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct fmt::formatter<hex::LangEntry> : fmt::formatter<std::string_view> {
|
|
|
|
template<typename FormatContext>
|
|
|
|
auto format(const hex::LangEntry &entry, FormatContext &ctx) {
|
|
|
|
return fmt::formatter<std::string_view>::format(entry, ctx);
|
|
|
|
}
|
|
|
|
};
|