From 09778ba687146bba896fab38f39ab042f9282373 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 1ca2998a4..233e1f0dc 100644 --- a/Telegram/Resources/langs/rewrites/en.json +++ b/Telegram/Resources/langs/rewrites/en.json @@ -159,6 +159,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 6a3460b3c..bd89006e4 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -81,6 +81,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" @@ -1802,6 +1803,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 7862eb4b5..acd573fa5 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -111,6 +111,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{ @@ -153,6 +154,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 }, }; [[maybe_unused]] constexpr auto kNoValue = { diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index 263fdef9c..8ab615ec4 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -79,6 +79,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) {