summaryrefslogtreecommitdiff
path: root/core/src/Utils/I18n.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-11 13:35:35 -0700
committerrtk0c <[email protected]>2021-06-11 13:35:35 -0700
commit8f7daa9bd100345d7e23639604c9a3a50ce6448b (patch)
tree4b0c4934f29dfca933e1e955a8af2e61c2719ca1 /core/src/Utils/I18n.hpp
parent222cfec6ad882196d8927f73e30d905daae89556 (diff)
Convert runtime-loaded l10n to string literals chosen at compile time
Diffstat (limited to 'core/src/Utils/I18n.hpp')
-rw-r--r--core/src/Utils/I18n.hpp91
1 files changed, 7 insertions, 84 deletions
diff --git a/core/src/Utils/I18n.hpp b/core/src/Utils/I18n.hpp
index 6285d60..e9eaac9 100644
--- a/core/src/Utils/I18n.hpp
+++ b/core/src/Utils/I18n.hpp
@@ -1,87 +1,10 @@
#pragma once
-#include "Utils/Sigslot.hpp"
-#include "Utils/fwd.hpp"
+#include "Utils/Macros.hpp"
-#include <cstddef>
-#include <optional>
-#include <span>
-#include <string>
-#include <string_view>
-#include <variant>
-#include <vector>
-
-class I18n
-{
-public:
- static inline Signal<> OnLanguageChange{};
- static inline Signal<> OnUnload{};
-
- static void Init();
- static void Shutdown();
-
- /// Discard in-memory mapping from key to locale entries.
- /// When any of the entry accessors are invoked, unloaded entries will be reloaded.
- static void Unload();
-
- static std::string_view GetLanguage();
- static bool SetLanguage(std::string_view lang);
-
- /* Entry accessors */
- /// Find the localized entry with the given key, return \c std::nullopt if does not exist. Reloads locale entries if they are currently unloaded.
- static std::optional<std::string_view> Lookup(std::string_view key);
- /// Find the localized entry with the given key, throw an exception if does not exist. EnsureLoaded locale entries if they are currently unloaded.
- static std::string_view LookupUnwrap(std::string_view key);
-
- /// Query the localized name of a locale, e.g. "en_US" -> "English - United States".
- /// If the queried locale does not exist, an empty string will be returned (existing locales can never have an empty localized name).
- static std::string_view LookupLanguage(std::string_view lang);
-};
-
-struct StringArgument
-{
- std::string Value;
-};
-
-struct IntArgument
-{
- int Value;
-};
-
-struct FloatArgument
-{
- double Value;
-};
-
-class BasicTranslation
-{
-private:
- std::string mContent;
-
-public:
- BasicTranslation(std::string_view key);
- const std::string& GetString() const;
- const char* Get() const;
-};
-
-class FormattedTranslation
-{
-public:
- using Element = std::variant<std::string, int>;
- using Argument = std::string;
-
-private:
- std::vector<Element> mParsedElements;
- size_t mNumArguments;
- size_t mMinimumResultLen;
-
-public:
- FormattedTranslation(std::string_view key);
- std::string Format(std::span<Argument> args);
-};
-
-class NumericTranslation
-{
-public:
- // TODO
-};
+#if !defined(TARGET_LOCALE)
+# define I18N_TEXT(defaultText, name) defaultText
+#else
+# include TARGET_LOCALE_FILE
+# define I18N_TEXT(defaultText, name) name
+#endif