Add OnLocalesInstalled signal to notify when new Locas are available
This commit is contained in:
parent
55eee90abe
commit
5359e35ded
|
|
@ -15,6 +15,8 @@ namespace Nz
|
||||||
using Dependencies = TypeList<Core>;
|
using Dependencies = TypeList<Core>;
|
||||||
struct Config {};
|
struct Config {};
|
||||||
|
|
||||||
|
NazaraStaticSignal(OnLocalesInstalled, const std::vector<std::string>&);
|
||||||
|
|
||||||
Localization(Config config);
|
Localization(Config config);
|
||||||
~Localization();
|
~Localization();
|
||||||
|
|
||||||
|
|
@ -23,6 +25,7 @@ namespace Nz
|
||||||
|
|
||||||
// Changes the locale
|
// Changes the locale
|
||||||
bool SetLocale(const std::string& locale);
|
bool SetLocale(const std::string& locale);
|
||||||
|
std::vector<std::string> GetInstalledLocales() const;
|
||||||
|
|
||||||
bool FindIndexForKey(std::string_view key, size_t& index) const;
|
bool FindIndexForKey(std::string_view key, size_t& index) const;
|
||||||
const std::string& GetStringAtIndex(size_t index) const;
|
const std::string& GetStringAtIndex(size_t index) const;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
Localization* Localization::s_instance = nullptr;
|
Localization* Localization::s_instance = nullptr;
|
||||||
|
NazaraStaticSignalImpl(Localization, OnLocalesInstalled);
|
||||||
|
|
||||||
Localization::Localization(Config /*config*/)
|
Localization::Localization(Config /*config*/)
|
||||||
: ModuleBase("Localization", this)
|
: ModuleBase("Localization", this)
|
||||||
|
|
@ -27,6 +28,8 @@ namespace Nz
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
|
|
||||||
|
size_t oldLocalesCount = m_locales.size();
|
||||||
|
|
||||||
std::vector<size_t> locales;
|
std::vector<size_t> locales;
|
||||||
SplitString(line, ";", [&](std::string_view str) {
|
SplitString(line, ";", [&](std::string_view str) {
|
||||||
if (!str.empty())
|
if (!str.empty())
|
||||||
|
|
@ -56,6 +59,17 @@ namespace Nz
|
||||||
// ensure all loaded locales have values (even if empty) for all lookup keys
|
// ensure all loaded locales have values (even if empty) for all lookup keys
|
||||||
for (auto&& locale : m_locales)
|
for (auto&& locale : m_locales)
|
||||||
locale.localizedStrings.resize(m_lookupTable.size());
|
locale.localizedStrings.resize(m_lookupTable.size());
|
||||||
|
|
||||||
|
size_t newLocalesCount = m_locales.size();
|
||||||
|
|
||||||
|
if (oldLocalesCount != newLocalesCount)
|
||||||
|
{
|
||||||
|
std::vector<std::string> v;
|
||||||
|
for (size_t i = oldLocalesCount - 1; i < newLocalesCount - 1; ++i)
|
||||||
|
v.push_back(m_locales[i].name);
|
||||||
|
|
||||||
|
OnLocalesInstalled(v);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,8 +88,13 @@ namespace Nz
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_currentLocale = &(*it);
|
std::vector<std::string> Localization::GetInstalledLocales() const
|
||||||
return true;
|
{
|
||||||
|
std::vector<std::string> v;
|
||||||
|
v.reserve(m_locales.size());
|
||||||
|
for (auto&& locale : m_locales)
|
||||||
|
v.push_back(locale.name);
|
||||||
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Localization::FindIndexForKey(std::string_view key, size_t& index) const
|
bool Localization::FindIndexForKey(std::string_view key, size_t& index) const
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue