// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "json/json11.hpp" #include #include #include using Language = std::string; namespace utils { namespace files { constexpr auto jsonExtension = ".json"; constexpr auto breakSign = "_"; } // namespace files class LangLoader { public: virtual ~LangLoader() = default; std::vector getAvailableDisplayLanguages() const; std::vector getAvailableInputLanguages() const; json11::Json createJson(const std::string &filename); }; class i18n { private: json11::Json displayLanguage; json11::Json fallbackLanguage; // backup language if item not found LangLoader loader; Language fallbackLanguageName = DefaultLanguage; Language inputLanguage = fallbackLanguageName; Language inputLanguageFilename; Language currentDisplayLanguage; mutable cpp_freertos::MutexStandard mutex; void changeDisplayLanguage(const json11::Json &lang); void loadFallbackLanguage(); public: static constexpr auto DefaultLanguage = "English"; std::filesystem::path DisplayLanguageDirPath = "assets/lang"; std::filesystem::path InputLanguageDirPath = "assets/profiles"; void resetAssetsPath(const std::filesystem::path &); virtual ~i18n() = default; void setInputLanguage(const Language &lang); const std::string &getInputLanguage(const std::string &inputMode); const std::string &getInputLanguageFilename(const std::string &inputMode); const std::string &getInputLanguage(); const std::string &getDisplayLanguage(); const std::string &get(const std::string &str); bool setDisplayLanguage(const Language &lang); void resetDisplayLanguages(); }; // Global instance of i18 class extern i18n localize; inline auto translateI18(const std::string &text) { return utils::localize.get(text); }; } // namespace utils