cleanup ContentControl

This commit is contained in:
MihailRis
2025-04-02 15:01:24 +03:00
parent f99d909f34
commit 3486cbd4c9
10 changed files with 59 additions and 114 deletions
+10 -13
View File
@@ -63,8 +63,8 @@ namespace {
};
}
static void load_locales_info(const io::path& resdir, std::string& fallback) {
auto file = resdir / langs::TEXTS_FOLDER / "langs.json";
static void load_locales_info(std::string& fallback) {
auto file = io::path("res:") / langs::TEXTS_FOLDER / "langs.json";
auto root = io::read_json(file);
::locales_info.clear();
@@ -89,13 +89,12 @@ static void load_locales_info(const io::path& resdir, std::string& fallback) {
}
static void load(
const io::path& resdir,
const std::string& locale,
const std::vector<io::path>& roots,
Lang& lang
) {
io::path filename = io::path(TEXTS_FOLDER) / (locale + LANG_FILE_EXT);
io::path core_file = resdir / filename;
io::path core_file = io::path("res:") / filename;
if (io::is_regular_file(core_file)) {
std::string text = io::read_string(core_file);
@@ -112,15 +111,14 @@ static void load(
}
}
static void load(
const io::path& resdir,
const std::string& locale,
const std::string& fallback,
const std::vector<io::path>& roots
) {
auto lang = std::make_unique<Lang>(locale);
load(resdir, fallback, roots, *lang.get());
load(fallback, roots, *lang.get());
if (locale != fallback) {
load(resdir, locale, roots, *lang.get());
load(locale, roots, *lang.get());
}
current = std::move(lang);
}
@@ -136,10 +134,10 @@ const std::unordered_map<std::string, LocaleInfo>& langs::get_locales_info() {
return ::locales_info;
}
std::string langs::locale_by_envlocale(const std::string& envlocale, const io::path& resdir){
std::string langs::locale_by_envlocale(const std::string& envlocale){
std::string fallback = FALLBACK_DEFAULT;
if (locales_info.size() == 0) {
load_locales_info(resdir, fallback);
load_locales_info(fallback);
}
if (locales_info.find(envlocale) != locales_info.end()) {
logger.info() << "locale " << envlocale << " is automatically selected";
@@ -158,16 +156,15 @@ std::string langs::locale_by_envlocale(const std::string& envlocale, const io::p
}
void langs::setup(
const io::path& resdir,
std::string locale,
const std::vector<io::path>& roots
) {
std::string fallback = langs::FALLBACK_DEFAULT;
load_locales_info(resdir, fallback);
if (::locales_info.find(locale) == ::locales_info.end()) {
load_locales_info(fallback);
if (locales_info.find(locale) == locales_info.end()) {
locale = fallback;
}
load(resdir, locale, fallback, roots);
load(locale, fallback, roots);
}
const std::wstring& langs::get(const std::wstring& key) {