2015-12-06 01:27:02 +00:00
|
|
|
#include "locale.hpp"
|
|
|
|
#include <cstring>
|
2015-12-08 05:43:28 +00:00
|
|
|
#include <clocale>
|
2015-12-09 01:04:50 +00:00
|
|
|
#include <algorithm>
|
2015-12-06 01:27:02 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-12-31 03:20:52 +00:00
|
|
|
extern "C" const uint8_t L_ja_JP[];
|
|
|
|
extern "C" size_t L_ja_JP_SZ;
|
|
|
|
|
2016-01-05 09:53:16 +00:00
|
|
|
namespace URDE
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
static const specter::Locale Locales[] =
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
{"en_US", "US English", L_en_US, L_en_US_SZ},
|
2015-12-31 03:20:52 +00:00
|
|
|
{"en_GB", "British English", L_en_GB, L_en_GB_SZ},
|
|
|
|
{"ja_JP", "Japanese", L_ja_JP, L_ja_JP_SZ}
|
2015-12-06 01:27:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
const specter::Locale& l = Locales[i];
|
2015-12-06 01:27:02 +00:00
|
|
|
ret.emplace_back(&l.name(), &l.fullName());
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
const specter::Locale* LookupLocale(const std::string& name)
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
constexpr size_t localeCount = std::extent<decltype(Locales)>::value;
|
|
|
|
for (size_t i=0 ; i<localeCount ; ++i)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
const specter::Locale& l = Locales[i];
|
2015-12-06 01:27:02 +00:00
|
|
|
if (!name.compare(l.name()))
|
|
|
|
return &l;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
const specter::Locale* SystemLocaleOrEnglish()
|
2015-12-06 01:27:02 +00:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2016-03-04 23:04:53 +00:00
|
|
|
const specter::Locale& l = Locales[i];
|
2015-12-06 01:27:02 +00:00
|
|
|
if (!l.name().compare(0, std::min(l.name().size(), sysLocaleLen), sysLocale))
|
|
|
|
return &l;
|
|
|
|
}
|
|
|
|
return Locales;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|