mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-10 09:47:43 +00:00
Submodule updates and initial locale files
This commit is contained in:
58
Editor/locale/locale.cpp
Normal file
58
Editor/locale/locale.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "locale.hpp"
|
||||
#include <cstring>
|
||||
|
||||
extern "C" const uint8_t L_en_US[];
|
||||
extern "C" size_t L_en_US_SZ;
|
||||
|
||||
extern "C" const uint8_t L_en_GB[];
|
||||
extern "C" size_t L_en_GB_SZ;
|
||||
|
||||
namespace RUDE
|
||||
{
|
||||
|
||||
static const Specter::Locale Locales[] =
|
||||
{
|
||||
{"en_US", "US English", L_en_US, L_en_US_SZ},
|
||||
{"en_GB", "British English", L_en_GB, L_en_GB_SZ}
|
||||
};
|
||||
|
||||
std::vector<std::pair<const std::string*, const std::string*>> ListLocales()
|
||||
{
|
||||
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
|
||||
std::vector<std::pair<const std::string*, const std::string*>> ret;
|
||||
ret.reserve(localeCount);
|
||||
for (size_t i=0 ; i<localeCount ; ++i)
|
||||
{
|
||||
const Specter::Locale& l = Locales[i];
|
||||
ret.emplace_back(&l.name(), &l.fullName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const Specter::Locale* LookupLocale(const std::string& name)
|
||||
{
|
||||
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
|
||||
for (size_t i=0 ; i<localeCount ; ++i)
|
||||
{
|
||||
const Specter::Locale& l = Locales[i];
|
||||
if (!name.compare(l.name()))
|
||||
return &l;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Specter::Locale* SystemLocaleOrEnglish()
|
||||
{
|
||||
const char* sysLocale = std::setlocale(LC_ALL, nullptr);
|
||||
size_t sysLocaleLen = std::strlen(sysLocale);
|
||||
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
|
||||
for (size_t i=0 ; i<localeCount ; ++i)
|
||||
{
|
||||
const Specter::Locale& l = Locales[i];
|
||||
if (!l.name().compare(0, std::min(l.name().size(), sysLocaleLen), sysLocale))
|
||||
return &l;
|
||||
}
|
||||
return Locales;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user