mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Reorder translation languages.
This commit is contained in:
parent
ad91592390
commit
95336d4a96
3 changed files with 47 additions and 30 deletions
|
@ -281,17 +281,20 @@ object_ptr<BoxContent> EditSkipTranslationLanguages() {
|
||||||
Core::App().settings().setSkipTranslationLanguages(
|
Core::App().settings().setSkipTranslationLanguages(
|
||||||
std::move(list));
|
std::move(list));
|
||||||
Core::App().saveSettingsDelayed();
|
Core::App().saveSettingsDelayed();
|
||||||
}, Core::App().settings().skipTranslationLanguages());
|
}, Core::App().settings().skipTranslationLanguages(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
object_ptr<BoxContent> ChooseTranslateToBox() {
|
object_ptr<BoxContent> ChooseTranslateToBox() {
|
||||||
|
const auto selected = std::vector<LanguageId>{
|
||||||
|
Core::App().settings().translateTo(),
|
||||||
|
};
|
||||||
return Box(ChooseLanguageBox, tr::lng_languages(), [=](
|
return Box(ChooseLanguageBox, tr::lng_languages(), [=](
|
||||||
const std::vector<LanguageId> &ids) {
|
const std::vector<LanguageId> &ids) {
|
||||||
Expects(!ids.empty());
|
Expects(!ids.empty());
|
||||||
|
|
||||||
Core::App().settings().setTranslateTo(ids.front());
|
Core::App().settings().setTranslateTo(ids.front());
|
||||||
Core::App().saveSettingsDelayed();
|
Core::App().saveSettingsDelayed();
|
||||||
}, std::nullopt);
|
}, selected, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/widgets/multi_select.h"
|
#include "ui/widgets/multi_select.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
|
#include "base/debug_log.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
|
@ -24,33 +25,57 @@ namespace {
|
||||||
const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
||||||
|
|
||||||
[[nodiscard]] std::vector<LanguageId> TranslationLanguagesList() {
|
[[nodiscard]] std::vector<LanguageId> TranslationLanguagesList() {
|
||||||
|
// If adding some languages here you need to check that it is
|
||||||
|
// supported on the server. Right now server supports those:
|
||||||
|
//
|
||||||
|
// 'af', 'sq', 'am', 'ar', 'hy', 'az', 'eu', 'be', 'bn', 'bs', 'bg',
|
||||||
|
// 'ca', 'ceb', 'zh-CN', 'zh', 'zh-TW', 'co', 'hr', 'cs', 'da', 'nl',
|
||||||
|
// 'en', 'eo', 'et', 'fi', 'fr', 'fy', 'gl', 'ka', 'de', 'el', 'gu',
|
||||||
|
// 'ht', 'ha', 'haw', 'he', 'iw', 'hi', 'hmn', 'hu', 'is', 'ig', 'id',
|
||||||
|
// 'ga', 'it', 'ja', 'jv', 'kn', 'kk', 'km', 'rw', 'ko', 'ku', 'ky',
|
||||||
|
// 'lo', 'la', 'lv', 'lt', 'lb', 'mk', 'mg', 'ms', 'ml', 'mt', 'mi',
|
||||||
|
// 'mr', 'mn', 'my', 'ne', 'no', 'ny', 'or', 'ps', 'fa', 'pl', 'pt',
|
||||||
|
// 'pa', 'ro', 'ru', 'sm', 'gd', 'sr', 'st', 'sn', 'sd', 'si', 'sk',
|
||||||
|
// 'sl', 'so', 'es', 'su', 'sw', 'sv', 'tl', 'tg', 'ta', 'tt', 'te',
|
||||||
|
// 'th', 'tr', 'tk', 'uk', 'ur', 'ug', 'uz', 'vi', 'cy', 'xh', 'yi',
|
||||||
|
// 'yo', 'zu',
|
||||||
return {
|
return {
|
||||||
{ QLocale::English },
|
{ QLocale::English },
|
||||||
|
{ QLocale::Arabic },
|
||||||
|
{ QLocale::Belarusian },
|
||||||
|
{ QLocale::Catalan },
|
||||||
|
{ QLocale::Chinese },
|
||||||
|
{ QLocale::Dutch },
|
||||||
|
{ QLocale::French },
|
||||||
|
{ QLocale::German },
|
||||||
|
{ QLocale::Indonesian },
|
||||||
|
{ QLocale::Italian },
|
||||||
|
{ QLocale::Japanese },
|
||||||
|
{ QLocale::Korean },
|
||||||
|
{ QLocale::Polish },
|
||||||
|
{ QLocale::Portuguese },
|
||||||
|
{ QLocale::Russian },
|
||||||
|
{ QLocale::Spanish },
|
||||||
|
{ QLocale::Ukrainian },
|
||||||
|
|
||||||
{ QLocale::Afrikaans },
|
{ QLocale::Afrikaans },
|
||||||
{ QLocale::Albanian },
|
{ QLocale::Albanian },
|
||||||
{ QLocale::Amharic },
|
{ QLocale::Amharic },
|
||||||
{ QLocale::Arabic },
|
|
||||||
{ QLocale::Armenian },
|
{ QLocale::Armenian },
|
||||||
{ QLocale::Azerbaijani },
|
{ QLocale::Azerbaijani },
|
||||||
{ QLocale::Basque },
|
{ QLocale::Basque },
|
||||||
{ QLocale::Belarusian },
|
|
||||||
{ QLocale::Bosnian },
|
{ QLocale::Bosnian },
|
||||||
{ QLocale::Bulgarian },
|
{ QLocale::Bulgarian },
|
||||||
{ QLocale::Burmese },
|
{ QLocale::Burmese },
|
||||||
{ QLocale::Catalan },
|
|
||||||
{ QLocale::Chinese },
|
|
||||||
{ QLocale::Croatian },
|
{ QLocale::Croatian },
|
||||||
{ QLocale::Czech },
|
{ QLocale::Czech },
|
||||||
{ QLocale::Danish },
|
{ QLocale::Danish },
|
||||||
{ QLocale::Dutch },
|
|
||||||
{ QLocale::Esperanto },
|
{ QLocale::Esperanto },
|
||||||
{ QLocale::Estonian },
|
{ QLocale::Estonian },
|
||||||
{ QLocale::Finnish },
|
{ QLocale::Finnish },
|
||||||
{ QLocale::French },
|
|
||||||
{ QLocale::Gaelic },
|
{ QLocale::Gaelic },
|
||||||
{ QLocale::Galician },
|
{ QLocale::Galician },
|
||||||
{ QLocale::Georgian },
|
{ QLocale::Georgian },
|
||||||
{ QLocale::German },
|
|
||||||
{ QLocale::Greek },
|
{ QLocale::Greek },
|
||||||
{ QLocale::Gusii },
|
{ QLocale::Gusii },
|
||||||
{ QLocale::Hausa },
|
{ QLocale::Hausa },
|
||||||
|
@ -58,13 +83,9 @@ const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
||||||
{ QLocale::Hungarian },
|
{ QLocale::Hungarian },
|
||||||
{ QLocale::Icelandic },
|
{ QLocale::Icelandic },
|
||||||
{ QLocale::Igbo },
|
{ QLocale::Igbo },
|
||||||
{ QLocale::Indonesian },
|
|
||||||
{ QLocale::Irish },
|
{ QLocale::Irish },
|
||||||
{ QLocale::Italian },
|
|
||||||
{ QLocale::Japanese },
|
|
||||||
{ QLocale::Kazakh },
|
{ QLocale::Kazakh },
|
||||||
{ QLocale::Kinyarwanda },
|
{ QLocale::Kinyarwanda },
|
||||||
{ QLocale::Korean },
|
|
||||||
{ QLocale::Kurdish },
|
{ QLocale::Kurdish },
|
||||||
{ QLocale::Lao },
|
{ QLocale::Lao },
|
||||||
{ QLocale::Latvian },
|
{ QLocale::Latvian },
|
||||||
|
@ -79,10 +100,7 @@ const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
||||||
{ QLocale::Nepali },
|
{ QLocale::Nepali },
|
||||||
{ QLocale::Pashto },
|
{ QLocale::Pashto },
|
||||||
{ QLocale::Persian },
|
{ QLocale::Persian },
|
||||||
{ QLocale::Polish },
|
|
||||||
{ QLocale::Portuguese },
|
|
||||||
{ QLocale::Romanian },
|
{ QLocale::Romanian },
|
||||||
{ QLocale::Russian },
|
|
||||||
{ QLocale::Serbian },
|
{ QLocale::Serbian },
|
||||||
{ QLocale::Shona },
|
{ QLocale::Shona },
|
||||||
{ QLocale::Sindhi },
|
{ QLocale::Sindhi },
|
||||||
|
@ -90,7 +108,6 @@ const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
||||||
{ QLocale::Slovak },
|
{ QLocale::Slovak },
|
||||||
{ QLocale::Slovenian },
|
{ QLocale::Slovenian },
|
||||||
{ QLocale::Somali },
|
{ QLocale::Somali },
|
||||||
{ QLocale::Spanish },
|
|
||||||
{ QLocale::Sundanese },
|
{ QLocale::Sundanese },
|
||||||
{ QLocale::Swahili },
|
{ QLocale::Swahili },
|
||||||
{ QLocale::Swedish },
|
{ QLocale::Swedish },
|
||||||
|
@ -100,7 +117,6 @@ const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
||||||
{ QLocale::Thai },
|
{ QLocale::Thai },
|
||||||
{ QLocale::Turkish },
|
{ QLocale::Turkish },
|
||||||
{ QLocale::Turkmen },
|
{ QLocale::Turkmen },
|
||||||
{ QLocale::Ukrainian },
|
|
||||||
{ QLocale::Urdu },
|
{ QLocale::Urdu },
|
||||||
{ QLocale::Uzbek },
|
{ QLocale::Uzbek },
|
||||||
{ QLocale::Vietnamese },
|
{ QLocale::Vietnamese },
|
||||||
|
@ -224,13 +240,12 @@ void ChooseLanguageBox(
|
||||||
not_null<GenericBox*> box,
|
not_null<GenericBox*> box,
|
||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
Fn<void(std::vector<LanguageId>)> callback,
|
Fn<void(std::vector<LanguageId>)> callback,
|
||||||
std::optional<std::vector<LanguageId>> toggled) {
|
std::vector<LanguageId> selected,
|
||||||
|
bool multiselect) {
|
||||||
box->setMinHeight(st::boxWidth);
|
box->setMinHeight(st::boxWidth);
|
||||||
box->setMaxHeight(st::boxWidth);
|
box->setMaxHeight(st::boxWidth);
|
||||||
box->setTitle(std::move(title));
|
box->setTitle(std::move(title));
|
||||||
|
|
||||||
const auto hasToggles = toggled.has_value();
|
|
||||||
|
|
||||||
const auto multiSelect = box->setPinnedToTopContent(
|
const auto multiSelect = box->setPinnedToTopContent(
|
||||||
object_ptr<MultiSelect>(
|
object_ptr<MultiSelect>(
|
||||||
box,
|
box,
|
||||||
|
@ -246,11 +261,9 @@ void ChooseLanguageBox(
|
||||||
if (const auto i = ranges::find(list, current); i != end(list)) {
|
if (const auto i = ranges::find(list, current); i != end(list)) {
|
||||||
base::reorder(list, std::distance(begin(list), i), 0);
|
base::reorder(list, std::distance(begin(list), i), 0);
|
||||||
}
|
}
|
||||||
if (hasToggles) {
|
ranges::stable_partition(list, [&](LanguageId id) {
|
||||||
ranges::stable_partition(list, [&](LanguageId id) {
|
return ranges::contains(selected, id);
|
||||||
return ranges::contains(*toggled, id);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}();
|
}();
|
||||||
auto rows = std::vector<not_null<SlideWrap<Row>*>>();
|
auto rows = std::vector<not_null<SlideWrap<Row>*>>();
|
||||||
|
@ -260,9 +273,9 @@ void ChooseLanguageBox(
|
||||||
object_ptr<SlideWrap<Row>>(
|
object_ptr<SlideWrap<Row>>(
|
||||||
container,
|
container,
|
||||||
object_ptr<Row>(container, id)));
|
object_ptr<Row>(container, id)));
|
||||||
if (hasToggles) {
|
if (multiselect) {
|
||||||
button->entity()->toggleOn(
|
button->entity()->toggleOn(
|
||||||
rpl::single(ranges::contains(*toggled, id)),
|
rpl::single(ranges::contains(selected, id)),
|
||||||
false);
|
false);
|
||||||
} else {
|
} else {
|
||||||
button->entity()->setClickedCallback([=] {
|
button->entity()->setClickedCallback([=] {
|
||||||
|
@ -300,7 +313,7 @@ void ChooseLanguageBox(
|
||||||
}, label->lifetime());
|
}, label->lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasToggles) {
|
if (multiselect) {
|
||||||
box->addButton(tr::lng_settings_save(), [=] {
|
box->addButton(tr::lng_settings_save(), [=] {
|
||||||
auto result = ranges::views::all(
|
auto result = ranges::views::all(
|
||||||
rows
|
rows
|
||||||
|
|
|
@ -21,6 +21,7 @@ void ChooseLanguageBox(
|
||||||
not_null<GenericBox*> box,
|
not_null<GenericBox*> box,
|
||||||
rpl::producer<QString> title,
|
rpl::producer<QString> title,
|
||||||
Fn<void(std::vector<LanguageId>)> callback,
|
Fn<void(std::vector<LanguageId>)> callback,
|
||||||
std::optional<std::vector<LanguageId>> toggled);
|
std::vector<LanguageId> selected,
|
||||||
|
bool multiselect);
|
||||||
|
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
Loading…
Add table
Reference in a new issue