Skip to content

Commit

Permalink
Add translation bar dropdown menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Feb 2, 2023
1 parent 1689c1a commit f5be551
Show file tree
Hide file tree
Showing 27 changed files with 700 additions and 384 deletions.
5 changes: 2 additions & 3 deletions Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ add_subdirectory(lib_crl)
add_subdirectory(lib_base)
add_subdirectory(lib_ui)
add_subdirectory(lib_tl)
if (NOT DESKTOP_APP_DISABLE_SPELLCHECK)
add_subdirectory(lib_spellcheck)
endif()
add_subdirectory(lib_spellcheck)
add_subdirectory(lib_storage)
add_subdirectory(lib_lottie)
add_subdirectory(lib_qr)
Expand Down Expand Up @@ -72,6 +70,7 @@ PRIVATE
desktop-app::lib_crl
desktop-app::lib_ui
desktop-app::lib_tl
desktop-app::lib_spellcheck
desktop-app::lib_storage
desktop-app::lib_lottie
desktop-app::lib_qr
Expand Down
38 changes: 8 additions & 30 deletions Telegram/SourceFiles/boxes/language_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For license and copyright information please follow this link:
#include "boxes/language_box.h"

#include "lang/lang_keys.h"
#include "ui/boxes/choose_language_box.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
Expand Down Expand Up @@ -44,16 +45,6 @@ For license and copyright information please follow this link:
#include <QtGui/QClipboard>

namespace {
namespace {

[[nodiscard]] std::vector<QLocale> SkipLocalesFromSettings() {
const auto list = Core::App().settings().skipTranslationLanguages();
return list
| ranges::views::transform(&LanguageId::locale)
| ranges::to_vector;
}

} // namespace

using Language = Lang::Language;
using Languages = Lang::CloudManager::Languages;
Expand Down Expand Up @@ -1128,8 +1119,7 @@ void LanguageBox::prepare() {
Core::App().saveSettingsDelayed();
}, translateEnabled->lifetime());

using Locales = std::vector<QLocale>;
const auto label = lifetime().make_state<rpl::event_stream<Locales>>();
using Languages = std::vector<LanguageId>;
const auto translateSkipWrap = topContainer->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
topContainer,
Expand All @@ -1141,28 +1131,16 @@ void LanguageBox::prepare() {
const auto translateSkip = Settings::AddButtonWithLabel(
translateSkipWrap->entity(),
tr::lng_translate_settings_choose(),
label->events(
) | rpl::map([](const Locales &locales) {
return (locales.size() > 1)
? tr::lng_languages_count(tr::now, lt_count, locales.size())
: Ui::LanguageName(locales.front());
Core::App().settings().skipTranslationLanguagesValue(
) | rpl::map([](const Languages &list) {
return (list.size() > 1)
? tr::lng_languages_count(tr::now, lt_count, list.size())
: Ui::LanguageName(list.front());
}),
st::settingsButtonNoIcon);

label->fire(SkipLocalesFromSettings());
translateSkip->setClickedCallback([=] {
Ui::BoxShow(this).showBox(
Box(Ui::ChooseLanguageBox, [=](Locales locales) {
label->fire_copy(locales);
using namespace ranges::views;
Core::App().settings().setSkipTranslationLanguages(all(
locales
) | transform([](const QLocale &l) {
return LanguageId{ l.language() };
}) | ranges::to_vector);
Core::App().saveSettingsDelayed();
}, SkipLocalesFromSettings()),
Ui::LayerOption::KeepOther);
Ui::BoxShow(this).showBox(Ui::EditSkipTranslationLanguages());
});
Settings::AddSkip(topContainer);
Settings::AddDividerText(
Expand Down
2 changes: 2 additions & 0 deletions Telegram/SourceFiles/boxes/language_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ For license and copyright information please follow this link:
#include "boxes/abstract_box.h"
#include "base/binary_guard.h"

struct LanguageId;

namespace Ui {
class MultiSelect;
struct ScrollToRequest;
Expand Down
5 changes: 5 additions & 0 deletions Telegram/SourceFiles/boxes/premium_preview_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
return tr::lng_premium_summary_subtitle_profile_badge();
case PremiumPreview::AnimatedUserpics:
return tr::lng_premium_summary_subtitle_animated_userpics();
case PremiumPreview::RealTimeTranslation:
return tr::lng_premium_summary_subtitle_translation();
}
Unexpected("PremiumPreview in SectionTitle.");
}
Expand Down Expand Up @@ -142,6 +144,8 @@ void PreloadSticker(const std::shared_ptr<Data::DocumentMedia> &media) {
return tr::lng_premium_summary_about_profile_badge();
case PremiumPreview::AnimatedUserpics:
return tr::lng_premium_summary_about_animated_userpics();
case PremiumPreview::RealTimeTranslation:
return tr::lng_premium_summary_about_translation();
}
Unexpected("PremiumPreview in SectionTitle.");
}
Expand Down Expand Up @@ -453,6 +457,7 @@ struct VideoPreviewDocument {
case PremiumPreview::InfiniteReactions: return "infinite_reactions";
case PremiumPreview::ProfileBadge: return "profile_badge";
case PremiumPreview::AnimatedUserpics: return "animated_userpics";
case PremiumPreview::RealTimeTranslation: return "translations";
}
return "";
}();
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/boxes/premium_preview_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ enum class PremiumPreview {
AdvancedChatManagement,
ProfileBadge,
AnimatedUserpics,
RealTimeTranslation,

kCount,
};
Expand Down
Loading

0 comments on commit f5be551

Please sign in to comment.