2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Handle t.me/setlanguage links.

Also support custom langpacks with base langpacks.
This commit is contained in:
John Preston
2018-10-22 15:13:48 +04:00
parent 228fb2f80d
commit 162da089ec
13 changed files with 697 additions and 252 deletions

View File

@@ -142,21 +142,21 @@ void Widget::createLanguageLink() {
updateControlsGeometry();
};
auto currentId = Lang::Current().id();
auto defaultId = Lang::DefaultLanguageId();
auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage();
if (!currentId.isEmpty() && currentId != defaultId) {
const auto currentId = Lang::LanguageIdOrDefault(Lang::Current().id());
const auto defaultId = Lang::DefaultLanguageId();
const auto suggested = Lang::CurrentCloudManager().suggestedLanguage();
if (currentId != defaultId) {
createLink(Lang::GetOriginalValue(lng_switch_to_this), defaultId);
} else if (!suggestedId.isEmpty() && suggestedId != currentId) {
} else if (!suggested.isEmpty() && suggested != currentId) {
request(MTPlangpack_GetStrings(
MTP_string(Lang::CloudLangPackName()),
MTP_string(suggestedId),
MTP_string(suggested),
MTP_vector<MTPstring>(1, MTP_string("lng_switch_to_this"))
)).done([=](const MTPVector<MTPLangPackString> &result) {
auto strings = Lang::Instance::ParseStrings(result);
auto it = strings.find(lng_switch_to_this);
if (it != strings.end()) {
createLink(it->second, suggestedId);
createLink(it->second, suggested);
}
}).send();
}
@@ -619,10 +619,10 @@ void Widget::Step::finish(const MTPUser &user, QImage &&photo) {
}
// Save the default language if we've suggested some other and user ignored it.
auto currentId = Lang::Current().id();
auto defaultId = Lang::DefaultLanguageId();
auto suggestedId = Lang::CurrentCloudManager().suggestedLanguage();
if (currentId.isEmpty() && !suggestedId.isEmpty() && suggestedId != defaultId) {
const auto currentId = Lang::Current().id();
const auto defaultId = Lang::DefaultLanguageId();
const auto suggested = Lang::CurrentCloudManager().suggestedLanguage();
if (currentId.isEmpty() && !suggested.isEmpty() && suggested != defaultId) {
Lang::Current().switchToId(defaultId);
Local::writeLangPack();
}