diff options
author | rtk0c <[email protected]> | 2021-03-31 20:19:18 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-03-31 20:19:18 -0700 |
commit | 44f5fa5c8f258e8fc1f7d7e2e45e0485bd6cc490 (patch) | |
tree | 3f09a1cce46d38f5a8c6266150e67af3802d4b95 /core/src/Utils/I18n.hpp | |
parent | 31950890c939862f79c817053c106bf711c63a64 (diff) |
Complete items tab (UI and serialization)
Diffstat (limited to 'core/src/Utils/I18n.hpp')
-rw-r--r-- | core/src/Utils/I18n.hpp | 149 |
1 files changed, 80 insertions, 69 deletions
diff --git a/core/src/Utils/I18n.hpp b/core/src/Utils/I18n.hpp index de32cf8..a4dd225 100644 --- a/core/src/Utils/I18n.hpp +++ b/core/src/Utils/I18n.hpp @@ -1,69 +1,80 @@ -#pragma once
-
-#include "Utils/Sigslot.hpp"
-#include "Utils/fwd.hpp"
-
-#include <cstddef>
-#include <optional>
-#include <span>
-#include <string>
-#include <string_view>
-#include <variant>
-#include <vector>
-
-class I18n {
-public:
- static void Init();
- static void Shutdown();
-
- static Signal<> OnReload;
- static void ReloadLocales();
-
- static std::string_view GetLanguage();
- static bool SetLanguage(std::string_view lang);
-
- static std::optional<std::string_view> Lookup(std::string_view key);
- static std::string_view LookupUnwrap(std::string_view key);
- 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:
- const char* mContent;
-
-public:
- BasicTranslation(std::string_view key);
- 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
-};
+#pragma once + +#include "Utils/Sigslot.hpp" +#include "Utils/fwd.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 +}; |