get rid of fallbackMgr in MultiLangMgr, fixes #4154
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
#include "multilangmgr.h"
|
#include "multilangmgr.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@@ -107,59 +106,52 @@ MultiLangMgr::MultiLangMgr ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiLangMgr::MultiLangMgr (const Glib::ustring& fname, MultiLangMgr* fallbackMgr)
|
void MultiLangMgr::load (const std::vector<Glib::ustring> &fnames)
|
||||||
{
|
{
|
||||||
load (fname, fallbackMgr);
|
translations.clear();
|
||||||
}
|
|
||||||
|
|
||||||
bool MultiLangMgr::load (const Glib::ustring& fname, MultiLangMgr* fallbackMgr)
|
for (const auto& fname : fnames) {
|
||||||
{
|
if(fname.empty()) {
|
||||||
this->fallbackMgr.reset(fallbackMgr);
|
|
||||||
|
|
||||||
std::ifstream file(fname.c_str());
|
|
||||||
if (!file.is_open()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, Glib::ustring> translations;
|
|
||||||
std::string entry;
|
|
||||||
|
|
||||||
while (std::getline(file, entry)) {
|
|
||||||
|
|
||||||
if (entry.empty() || entry.front() == '#' || entry.front() == '!') {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string key, value;
|
std::ifstream file(fname.c_str());
|
||||||
|
if (!file.is_open()) {
|
||||||
std::istringstream line(entry);
|
|
||||||
|
|
||||||
if (!std::getline(line, key, ';') || !std::getline(line, value)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::regex newline("\\\\n");
|
std::string entry;
|
||||||
value = std::regex_replace(value, newline, "\n");
|
auto hint = translations.begin();
|
||||||
|
while (std::getline(file, entry)) {
|
||||||
|
|
||||||
translations.emplace(key, value);
|
if (entry.empty() || entry.front() == '#' || entry.front() == '!') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string key, value;
|
||||||
|
|
||||||
|
std::istringstream line(entry);
|
||||||
|
|
||||||
|
if(std::getline(line, key, ';') && translations.find(key) == translations.end() && std::getline(line, value)) {
|
||||||
|
size_t pos = 0;
|
||||||
|
while((pos = value.find("\\n", pos)) != std::string::npos) {
|
||||||
|
value.replace(pos, 2, "\n");
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
hint = translations.emplace_hint(hint, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this->translations.swap(translations);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring MultiLangMgr::getStr (const std::string& key) const
|
Glib::ustring MultiLangMgr::getStr (const std::string& key) const
|
||||||
{
|
{
|
||||||
const auto iterator = translations.find (key);
|
const auto iterator = translations.find(key);
|
||||||
|
|
||||||
if (iterator != translations.end ()) {
|
if (iterator != translations.end()) {
|
||||||
return iterator->second;
|
return iterator->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fallbackMgr) {
|
|
||||||
return fallbackMgr->getStr (key);
|
|
||||||
}
|
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,8 +20,8 @@
|
|||||||
#define _MULTILANGMGR_
|
#define _MULTILANGMGR_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
|
|
||||||
@@ -29,22 +29,14 @@ class MultiLangMgr
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MultiLangMgr ();
|
MultiLangMgr ();
|
||||||
MultiLangMgr (const Glib::ustring& fname, MultiLangMgr* fallbackMgr = nullptr);
|
|
||||||
|
|
||||||
public:
|
void load(const std::vector<Glib::ustring> &fnames);
|
||||||
bool load (const Glib::ustring& fname, MultiLangMgr* fallbackMgr = nullptr);
|
Glib::ustring getStr(const std::string& key) const;
|
||||||
|
static bool isOSLanguageDetectSupported();
|
||||||
public:
|
static Glib::ustring getOSUserLanguage();
|
||||||
Glib::ustring getStr (const std::string& key) const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static bool isOSLanguageDetectSupported ();
|
|
||||||
static Glib::ustring getOSUserLanguage ();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Glib::ustring> translations;
|
std::map<std::string, Glib::ustring> translations;
|
||||||
std::unique_ptr<MultiLangMgr> fallbackMgr;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MultiLangMgr langMgr;
|
extern MultiLangMgr langMgr;
|
||||||
|
@@ -2327,7 +2327,7 @@ void Options::load (bool lightweight)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
langMgr.load (localeTranslation, new MultiLangMgr (languageTranslation, new MultiLangMgr (defaultTranslation)));
|
langMgr.load ({localeTranslation, languageTranslation, defaultTranslation});
|
||||||
|
|
||||||
rtengine::init (&options.rtSettings, argv0, rtdir, !lightweight);
|
rtengine::init (&options.rtSettings, argv0, rtdir, !lightweight);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user