From a11fb2816b1d4ee06b46558e4d4dcbc75d0b0d53 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 21 Sep 2018 10:21:52 +0300 Subject: [PATCH] Use current language in change language box. Fixes #5174. --- .../SourceFiles/lang/lang_cloud_manager.cpp | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index 5a692a366e..f3159a9957 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -220,26 +220,28 @@ void CloudManager::switchToLanguage(QString id) { QVector keys; keys.reserve(3); keys.push_back(MTP_string("lng_sure_save_language")); - keys.push_back(MTP_string("lng_box_ok")); - keys.push_back(MTP_string("lng_cancel")); _switchingToLanguageRequest = request(MTPlangpack_GetStrings( MTP_string(Lang::CloudLangPackName()), MTP_string(id), MTP_vector(std::move(keys)) )).done([=](const MTPVector &result) { - auto values = Instance::ParseStrings(result); - auto getValue = [&values](LangKey key) { + const auto values = Instance::ParseStrings(result); + const auto getValue = [&](LangKey key) { auto it = values.find(key); return (it == values.cend()) ? GetOriginalValue(key) : it->second; }; - auto text = getValue(lng_sure_save_language); - auto save = getValue(lng_box_ok); - auto cancel = getValue(lng_cancel); - Ui::show(Box(text, save, cancel, [this, id] { - performSwitchAndRestart(id); - }), LayerOption::KeepOther); + const auto text = lang(lng_sure_save_language) + + "\n\n" + + getValue(lng_sure_save_language); + Ui::show( + Box( + text, + lang(lng_box_ok), + lang(lng_cancel), + [=] { performSwitchAndRestart(id); }), + LayerOption::KeepOther); }).send(); } } @@ -253,24 +255,33 @@ void CloudManager::performSwitchToCustom() { } auto filePath = result.paths.front(); - Lang::FileParser loader(filePath, { lng_sure_save_language, lng_box_ok, lng_cancel }); + Lang::FileParser loader(filePath, { lng_sure_save_language }); if (loader.errors().isEmpty()) { weak->request(weak->_switchingToLanguageRequest).cancel(); if (weak->canApplyWithoutRestart(qsl("custom"))) { weak->_langpack.switchToCustomFile(filePath); } else { - auto values = loader.found(); - auto getValue = [&values](LangKey key) { - auto it = values.find(key); - return (it == values.cend()) ? GetOriginalValue(key) : it.value(); + const auto values = loader.found(); + const auto getValue = [&](LangKey key) { + const auto it = values.find(key); + return (it == values.cend()) + ? GetOriginalValue(key) + : it.value(); }; - auto text = getValue(lng_sure_save_language); - auto save = getValue(lng_box_ok); - auto cancel = getValue(lng_cancel); - Ui::show(Box(text, save, cancel, [weak, filePath] { + const auto text = lang(lng_sure_save_language) + + "\n\n" + + getValue(lng_sure_save_language); + const auto change = [=] { weak->_langpack.switchToCustomFile(filePath); App::restart(); - }), LayerOption::KeepOther); + }; + Ui::show( + Box( + text, + lang(lng_box_ok), + lang(lng_cancel), + change), + LayerOption::KeepOther); } } else { Ui::show(