4#include <foundation/Common.h>
5#include <nlohmann/json.hpp>
6#include <unordered_map>
7#include "vfspp/IFileSystem.h"
9#define _TW(key) Phosphorus::Languages::TranslateWide(key)
10#define _T(key) Phosphorus::Languages::Translate(key)
23 nlohmann::json Dictionary;
26 inline static int32 m_CurrentLanguage = 0;
31 inline static std::unordered_map<int32, Language> m_Dictionaries;
37 template<
typename TELang>
40 m_CurrentLanguage =
static_cast<int32
>(lang);
46 template<
typename TELang>
49 const vfspp::IFilePtr ptr = system->OpenFile(vfspp::FileInfo(path.
Get()), vfspp::IFile::FileMode::Read);
51 std::vector<uint8> fileData;
52 fileData.resize(ptr->Size());
53 ptr->Read(fileData.data(), ptr->Size());
55 std::string s = std::string{
reinterpret_cast<int8 *
>(fileData.data()), fileData.size()};
57 const auto &json = nlohmann::json::parse(s);
60 language.Dictionary = json;
61 language.Code = json[
"generic.code"].get<std::string>();
63 m_Dictionaries.emplace(
static_cast<int32
>(lang), language);
64 INFO(
"[Languages] Loaded '{}' language ('{}')", json[
"generic.name"].get<std::string>(),
65 json[
"generic.name"].get<std::string>());
Manages language dictionaries for localization.
Definition Languages.h:18
static void LoadDictionary(vfspp::IFileSystemPtr system, const String &path, TELang lang)
Loads a language dictionary from the specified file path.
Definition Languages.h:47
static void SetLanguage(TELang lang)
Sets current language.
Definition Languages.h:38
Represents a mutable sequence of characters, providing various member functions for string manipulati...
Definition String.h:16
FORCE_INLINE char * Get() const
Gets a raw char sequence.
Definition String.h:163
Represents a mutable sequence of utf-16 characters, providing various member functions for string man...
Definition WideString.h:14