Prefix client-side lang_code-s with #.

This commit is contained in:
John Preston 2018-10-26 13:08:21 +04:00
parent 711b8cfa36
commit 3447aac940
6 changed files with 21 additions and 14 deletions

View file

@ -76,7 +76,7 @@ void LanguageBox::Inner::languageChanged(int languageIndex) {
activateCurrent(); activateCurrent();
auto languageId = (*_languages)[languageIndex].id; auto languageId = (*_languages)[languageIndex].id;
if (Lang::Current().id() != languageId) { if (Lang::Current().id() != languageId) {
// "custom" is applied each time it is passed to switchToLanguage(). // "#custom" is applied each time it's passed to switchToLanguage().
// So we check that the language really has changed. // So we check that the language really has changed.
Lang::CurrentCloudManager().switchToLanguage(languageId); Lang::CurrentCloudManager().switchToLanguage(languageId);
} }
@ -142,7 +142,7 @@ void LanguageBox::refreshLanguages() {
currentIndex = 0; currentIndex = 0;
} }
} }
if (currentId == qstr("custom")) { if (currentId == qstr("#custom")) {
_languages.insert(_languages.begin(), { currentId, qsl("Custom LangPack"), qsl("Custom LangPack") }); _languages.insert(_languages.begin(), { currentId, qsl("Custom LangPack"), qsl("Custom LangPack") });
currentIndex = 0; currentIndex = 0;
} else if (currentIndex < 0) { } else if (currentIndex < 0) {

View file

@ -185,13 +185,15 @@ void CloudManager::applyLangPackData(const MTPDlangPackDifference &data) {
} else if (!data.vstrings.v.isEmpty()) { } else if (!data.vstrings.v.isEmpty()) {
_langpack.applyDifference(data); _langpack.applyDifference(data);
Local::writeLangPack(); Local::writeLangPack();
} else if (_restartAfterSwitch) {
Local::writeLangPack();
} else { } else {
LOG(("Lang Info: Up to date.")); LOG(("Lang Info: Up to date."));
} }
} }
bool CloudManager::canApplyWithoutRestart(const QString &id) const { bool CloudManager::canApplyWithoutRestart(const QString &id) const {
if (id == qstr("TEST_X") || id == qstr("TEST_0")) { if (id == qstr("#TEST_X") || id == qstr("#TEST_0")) {
return true; return true;
} }
@ -207,12 +209,12 @@ void CloudManager::switchToLanguage(QString id) {
if (id.isEmpty()) { if (id.isEmpty()) {
id = DefaultLanguageId(); id = DefaultLanguageId();
} }
if (_langpack.id() == id && id != qstr("custom")) { if (_langpack.id() == id && id != qstr("#custom")) {
return; return;
} }
request(_switchingToLanguageRequest).cancel(); request(_switchingToLanguageRequest).cancel();
if (id == qstr("custom")) { if (id == qstr("#custom")) {
performSwitchToCustom(); performSwitchToCustom();
} else if (canApplyWithoutRestart(id)) { } else if (canApplyWithoutRestart(id)) {
performSwitch(id); performSwitch(id);
@ -258,7 +260,7 @@ void CloudManager::performSwitchToCustom() {
Lang::FileParser loader(filePath, { lng_sure_save_language }); Lang::FileParser loader(filePath, { lng_sure_save_language });
if (loader.errors().isEmpty()) { if (loader.errors().isEmpty()) {
weak->request(weak->_switchingToLanguageRequest).cancel(); weak->request(weak->_switchingToLanguageRequest).cancel();
if (weak->canApplyWithoutRestart(qsl("custom"))) { if (weak->canApplyWithoutRestart(qsl("#custom"))) {
weak->_langpack.switchToCustomFile(filePath); weak->_langpack.switchToCustomFile(filePath);
} else { } else {
const auto values = loader.found(); const auto values = loader.found();
@ -292,7 +294,9 @@ void CloudManager::performSwitchToCustom() {
} }
void CloudManager::switchToTestLanguage() { void CloudManager::switchToTestLanguage() {
auto testLanguageId = (_langpack.id() == qstr("TEST_X")) ? qsl("TEST_0") : qsl("TEST_X"); const auto testLanguageId = (_langpack.id() == qstr("#TEST_X"))
? qsl("#TEST_0")
: qsl("#TEST_X");
performSwitch(testLanguageId); performSwitch(testLanguageId);
} }

View file

@ -176,7 +176,7 @@ QString CloudLangPackName() {
void Instance::switchToId(const QString &id) { void Instance::switchToId(const QString &id) {
reset(); reset();
_id = id; _id = id;
if (_id == qstr("TEST_X") || _id == qstr("TEST_0")) { if (_id == qstr("#TEST_X") || _id == qstr("#TEST_0")) {
for (auto &value : _values) { for (auto &value : _values) {
value = PrepareTestValue(value, _id[5]); value = PrepareTestValue(value, _id[5]);
} }
@ -287,6 +287,9 @@ void Instance::fillFromSerialized(const QByteArray &data) {
} }
if (!customFilePathAbsolute.isEmpty()) { if (!customFilePathAbsolute.isEmpty()) {
if (id == qstr("custom")) {
id = '#' + id;
}
auto currentCustomFileContent = Lang::FileParser::ReadFile(customFilePathAbsolute, customFilePathRelative); auto currentCustomFileContent = Lang::FileParser::ReadFile(customFilePathAbsolute, customFilePathRelative);
if (!currentCustomFileContent.isEmpty() && currentCustomFileContent != customFileContent) { if (!currentCustomFileContent.isEmpty() && currentCustomFileContent != customFileContent) {
loadFromCustomContent(customFilePathAbsolute, customFilePathRelative, currentCustomFileContent); loadFromCustomContent(customFilePathAbsolute, customFilePathRelative, currentCustomFileContent);
@ -333,7 +336,7 @@ void Instance::loadFromContent(const QByteArray &content) {
} }
void Instance::loadFromCustomContent(const QString &absolutePath, const QString &relativePath, const QByteArray &content) { void Instance::loadFromCustomContent(const QString &absolutePath, const QString &relativePath, const QByteArray &content) {
_id = qsl("custom"); _id = qsl("#custom");
_version = 0; _version = 0;
_customFilePathAbsolute = absolutePath; _customFilePathAbsolute = absolutePath;
_customFilePathRelative = relativePath; _customFilePathRelative = relativePath;

View file

@ -60,9 +60,9 @@ public:
return _id; return _id;
} }
bool isCustom() const { bool isCustom() const {
return (_id == qstr("custom") return (_id == qstr("#custom"))
|| _id == qstr("TEST_X") || (_id == qstr("#TEST_X"))
|| _id == qstr("TEST_0")); || (_id == qstr("#TEST_0"));
} }
int version() const { int version() const {
return _version; return _version;

View file

@ -51,7 +51,7 @@ auto GenerateCodes() {
}); });
} }
codes.emplace(qsl("loadlang"), [] { codes.emplace(qsl("loadlang"), [] {
Lang::CurrentCloudManager().switchToLanguage(qsl("custom")); Lang::CurrentCloudManager().switchToLanguage(qsl("#custom"));
}); });
codes.emplace(qsl("debugfiles"), [] { codes.emplace(qsl("debugfiles"), [] {
if (!Logs::DebugEnabled()) { if (!Logs::DebugEnabled()) {

View file

@ -40,7 +40,7 @@ void SetupLanguageButton(
button->addClickHandler([=] { button->addClickHandler([=] {
const auto m = button->clickModifiers(); const auto m = button->clickModifiers();
if ((m & Qt::ShiftModifier) && (m & Qt::AltModifier)) { if ((m & Qt::ShiftModifier) && (m & Qt::AltModifier)) {
Lang::CurrentCloudManager().switchToLanguage(qsl("custom")); Lang::CurrentCloudManager().switchToLanguage(qsl("#custom"));
} else { } else {
*guard = LanguageBox::Show(); *guard = LanguageBox::Show();
} }