From d4a1c1537f17b2cdce376e886fbf4c3883b1ff6a Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sun, 11 Sep 2022 03:31:54 +0300 Subject: [PATCH] [Improvement] Shortcut and settings code to reload language --- Telegram/Resources/langs/rewrites/en.json | 1 + Telegram/SourceFiles/core/application.cpp | 8 ++++++++ Telegram/SourceFiles/core/shortcuts.cpp | 2 ++ Telegram/SourceFiles/core/shortcuts.h | 1 + Telegram/SourceFiles/settings/settings_codes.cpp | 7 +++++++ 5 files changed, 19 insertions(+) diff --git a/Telegram/Resources/langs/rewrites/en.json b/Telegram/Resources/langs/rewrites/en.json index 2b29f2db0..272127303 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -170,6 +170,7 @@ "ktg_send_silent_preview": "Send preview silent", "ktg_reminder_preview": "Remind with preview", "ktg_schedule_preview": "Send preview scheduled", + "ktg_language_reloaded": "Kotatogram-specific language strings were reloaded.", "ktg_forward_sender_names_and_captions_removed": "Sender names and captions removed", "ktg_forward_remember_mode": "Remember forward mode", "ktg_forward_mode": "Forward mode", diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 1f6ee30df..9d4cea300 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -78,6 +78,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/gl/gl_detection.h" #include "ui/image/image.h" #include "ui/text/text_options.h" +#include "ui/toast/toast.h" #include "ui/emoji_config.h" #include "ui/effects/animations.h" #include "ui/effects/spoiler_mess.h" @@ -1772,6 +1773,13 @@ void Application::startShortcuts() { request->check(Command::Close) && request->handle([=] { return closeActiveWindow(); }); + request->check(Command::ReloadLang) && request->handle([=] { + Kotato::Lang::Load( + Lang::GetInstance().baseId(), + Lang::GetInstance().id()); + Ui::Toast::Show(ktr("ktg_language_reloaded")); + return true; + }); }, _lifetime); } diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index dd0ecee34..398914ffd 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -109,6 +109,7 @@ const auto CommandByName = base::flat_map{ { qsl("save_draft") , Command::SaveDraft }, { qsl("jump_to_date") , Command::JumpToDate }, + { qsl("reload_lang") , Command::ReloadLang }, }; const auto CommandNames = base::flat_map{ @@ -158,6 +159,7 @@ const auto CommandNames = base::flat_map{ { Command::SaveDraft , u"save_draft"_q }, { Command::JumpToDate , u"jump_to_date"_q }, + { Command::ReloadLang , u"reload_lang"_q }, }; class Manager { diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index bb1f82d34..4787d16fd 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -76,6 +76,7 @@ enum class Command { SaveDraft, JumpToDate, + ReloadLang, }; [[maybe_unused]] constexpr auto kShowFolder = { diff --git a/Telegram/SourceFiles/settings/settings_codes.cpp b/Telegram/SourceFiles/settings/settings_codes.cpp index 28f495897..a3cf0ff5d 100644 --- a/Telegram/SourceFiles/settings/settings_codes.cpp +++ b/Telegram/SourceFiles/settings/settings_codes.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "settings/settings_codes.h" +#include "kotato/kotato_lang.h" #include "ui/toast/toast.h" #include "mainwidget.h" #include "mainwindow.h" @@ -248,6 +249,12 @@ auto GenerateCodes() { Data::CloudThemes::SetTestingColors(now); Ui::Toast::Show(now ? "Testing chat theme colors!" : "Not testing.."); }); + codes.emplace(qsl("reloadlang"), [](SessionController *window) { + Kotato::Lang::Load( + Lang::GetInstance().baseId(), + Lang::GetInstance().id()); + Ui::Toast::Show(ktr("ktg_language_reloaded")); + }); #ifdef Q_OS_MAC codes.emplace(u"customicon"_q, [](SessionController *window) {