From a7c8feaecb6e39889f8d837b9b3abb60a33f2f15 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 18 Jun 2019 18:53:27 +0200 Subject: [PATCH] Use tr:: instead of langFactory and __rich. --- Telegram/Resources/langs/lang.strings | 3 +- Telegram/SourceFiles/boxes/about_box.cpp | 28 ++--- Telegram/SourceFiles/boxes/abstract_box.cpp | 52 +++++---- Telegram/SourceFiles/boxes/abstract_box.h | 77 +++++++++---- .../SourceFiles/boxes/add_contact_box.cpp | 43 ++++--- .../SourceFiles/boxes/auto_download_box.cpp | 4 +- Telegram/SourceFiles/boxes/auto_lock_box.cpp | 2 +- Telegram/SourceFiles/boxes/background_box.cpp | 2 +- .../boxes/background_preview_box.cpp | 6 +- Telegram/SourceFiles/boxes/calendar_box.cpp | 2 +- .../SourceFiles/boxes/change_phone_box.cpp | 18 +-- Telegram/SourceFiles/boxes/confirm_box.cpp | 76 ++++++------ Telegram/SourceFiles/boxes/confirm_box.h | 4 +- .../SourceFiles/boxes/confirm_phone_box.cpp | 4 +- Telegram/SourceFiles/boxes/connection_box.cpp | 10 +- .../SourceFiles/boxes/create_poll_box.cpp | 4 +- .../SourceFiles/boxes/download_path_box.cpp | 4 +- .../SourceFiles/boxes/edit_caption_box.cpp | 4 +- Telegram/SourceFiles/boxes/edit_color_box.cpp | 4 +- .../SourceFiles/boxes/edit_privacy_box.cpp | 8 +- Telegram/SourceFiles/boxes/language_box.cpp | 2 +- .../SourceFiles/boxes/local_storage_box.cpp | 20 ++-- .../SourceFiles/boxes/mute_settings_box.cpp | 4 +- Telegram/SourceFiles/boxes/passcode_box.cpp | 18 +-- Telegram/SourceFiles/boxes/peer_list_box.h | 5 +- .../boxes/peer_list_controllers.cpp | 2 +- .../boxes/peers/add_participants_box.cpp | 14 +-- .../boxes/peers/edit_contact_box.cpp | 4 +- .../boxes/peers/edit_linked_chat_box.cpp | 55 +++++---- .../boxes/peers/edit_participant_box.cpp | 39 ++++--- .../boxes/peers/edit_participants_box.cpp | 20 ++-- .../edit_peer_history_visibility_box.cpp | 4 +- .../boxes/peers/edit_peer_info_box.cpp | 4 +- .../boxes/peers/edit_peer_permissions_box.cpp | 4 +- .../boxes/peers/edit_peer_type_box.cpp | 4 +- Telegram/SourceFiles/boxes/photo_crop_box.cpp | 4 +- Telegram/SourceFiles/boxes/rate_call_box.cpp | 6 +- Telegram/SourceFiles/boxes/report_box.cpp | 4 +- .../boxes/self_destruction_box.cpp | 6 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 4 +- Telegram/SourceFiles/boxes/sessions_box.cpp | 2 +- Telegram/SourceFiles/boxes/share_box.cpp | 6 +- .../SourceFiles/boxes/single_choice_box.cpp | 2 +- .../SourceFiles/boxes/sticker_set_box.cpp | 12 +- Telegram/SourceFiles/boxes/stickers_box.cpp | 10 +- Telegram/SourceFiles/boxes/url_auth_box.cpp | 4 +- Telegram/SourceFiles/boxes/username_box.cpp | 4 +- Telegram/SourceFiles/calls/calls_top_bar.cpp | 2 +- .../chat_helpers/emoji_sets_manager.cpp | 2 +- .../chat_helpers/message_field.cpp | 4 +- .../SourceFiles/codegen/lang/generator.cpp | 1 - Telegram/SourceFiles/data/data_document.cpp | 7 +- .../dialogs_search_from_controllers.cpp | 2 +- .../view/export_view_panel_controller.cpp | 4 +- .../export/view/export_view_progress.cpp | 4 +- .../export/view/export_view_settings.cpp | 89 +++++++------- .../export/view/export_view_settings.h | 2 +- .../admin_log/history_admin_log_filter.cpp | 4 +- .../admin_log/history_admin_log_item.cpp | 32 +++-- .../admin_log/history_admin_log_section.cpp | 2 +- .../view/history_view_top_bar_widget.cpp | 6 +- .../info_common_groups_inner_widget.cpp | 3 +- .../info_common_groups_inner_widget.h | 3 +- .../info/profile/info_profile_members.cpp | 3 +- .../info/profile/info_profile_members.h | 3 +- .../inline_bots/inline_results_widget.cpp | 7 +- Telegram/SourceFiles/intro/introcode.cpp | 35 +++--- Telegram/SourceFiles/intro/introcode.h | 2 +- Telegram/SourceFiles/intro/introphone.cpp | 21 ++-- Telegram/SourceFiles/intro/introphone.h | 2 +- Telegram/SourceFiles/intro/intropwdcheck.cpp | 36 +++--- Telegram/SourceFiles/intro/intropwdcheck.h | 2 +- Telegram/SourceFiles/intro/introsignup.cpp | 21 ++-- Telegram/SourceFiles/intro/introsignup.h | 2 +- Telegram/SourceFiles/intro/introstart.cpp | 8 +- Telegram/SourceFiles/intro/introstart.h | 2 +- Telegram/SourceFiles/intro/introwidget.cpp | 109 +++++++++--------- Telegram/SourceFiles/intro/introwidget.h | 26 ++--- .../SourceFiles/lang/lang_cloud_manager.cpp | 36 +++--- Telegram/SourceFiles/lang/lang_keys.h | 4 - .../media/view/media_view_overlay_widget.cpp | 12 +- .../passport/passport_panel_edit_contact.cpp | 6 +- .../passport/passport_panel_edit_document.cpp | 14 +-- .../passport/passport_panel_edit_scans.cpp | 2 +- .../passport/passport_panel_form.cpp | 25 ++-- .../passport/passport_panel_password.cpp | 8 +- .../platform/mac/main_window_mac.mm | 4 +- .../settings/settings_information.cpp | 2 +- .../settings/settings_privacy_controllers.cpp | 2 +- .../settings/settings_privacy_security.cpp | 4 +- .../support/support_autocomplete.cpp | 4 +- .../SourceFiles/support/support_helper.cpp | 4 +- Telegram/SourceFiles/ui/countryinput.cpp | 2 +- Telegram/SourceFiles/ui/widgets/buttons.cpp | 50 ++++---- Telegram/SourceFiles/ui/widgets/buttons.h | 10 +- Telegram/SourceFiles/window/main_window.cpp | 8 +- .../window/notifications_manager_default.cpp | 2 +- .../window/themes/window_theme_editor.cpp | 4 +- .../window/themes/window_theme_warning.cpp | 4 +- .../window/window_lock_widgets.cpp | 22 ++-- .../SourceFiles/window/window_lock_widgets.h | 12 +- .../SourceFiles/window/window_main_menu.cpp | 6 +- .../SourceFiles/window/window_peer_menu.cpp | 16 +-- 103 files changed, 699 insertions(+), 628 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 43ca940d26..0d539498a8 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -866,8 +866,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_manage_linked_channel_about" = "{channel} is linking the group as its discussion board."; "lng_manage_linked_channel_unlink" = "Unlink channel"; "lng_manage_linked_channel_posted" = "All new messages posted in this channel are forwarded to the group."; -"lng_manage_discussion_group_warning" = "\"Chat history for new members\" will be switched to {visible}."; -"lng_manage_discussion_group_visible" = "Visible"; +"lng_manage_discussion_group_warning" = "\"Chat history for new members\" will be switched to **Visible**."; "lng_manage_history_visibility_title" = "Chat history for new members"; "lng_manage_history_visibility_shown" = "Visible"; diff --git a/Telegram/SourceFiles/boxes/about_box.cpp b/Telegram/SourceFiles/boxes/about_box.cpp index 4ca224c911..05a6ef1d8b 100644 --- a/Telegram/SourceFiles/boxes/about_box.cpp +++ b/Telegram/SourceFiles/boxes/about_box.cpp @@ -23,29 +23,31 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { rpl::producer Text1() { - return rpl::single(lng_about_text1__rich( + return tr::lng_about_text1( lt_api_link, - Ui::Text::Link( - lang(lng_about_text1_api), - "https://core.telegram.org/api"))); + tr::lng_about_text1_api( + ) | Ui::Text::ToLink("https://core.telegram.org/api"), + Ui::Text::WithEntities); } rpl::producer Text2() { - return rpl::single(lng_about_text2__rich( + return tr::lng_about_text2( lt_gpl_link, - Ui::Text::Link( - lang(lng_about_text2_gpl), + tr::lng_about_text2_gpl( + ) | Ui::Text::ToLink( "https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE"), lt_github_link, - Ui::Text::Link( - lang(lng_about_text2_github), - "https://github.com/telegramdesktop/tdesktop"))); + tr::lng_about_text2_github( + ) | Ui::Text::ToLink( + "https://github.com/telegramdesktop/tdesktop"), + Ui::Text::WithEntities); } rpl::producer Text3() { - return rpl::single(lng_about_text3__rich( + return tr::lng_about_text3( lt_faq_link, - Ui::Text::Link(lang(lng_about_text3_faq), telegramFaqLink()))); + tr::lng_about_text3_faq() | Ui::Text::ToLink(telegramFaqLink()), + Ui::Text::WithEntities); } } // namespace @@ -60,7 +62,7 @@ AboutBox::AboutBox(QWidget *parent) void AboutBox::prepare() { setTitle(rpl::single(qsl("Telegram Desktop"))); - addButton(langFactory(lng_close), [this] { closeBox(); }); + addButton(tr::lng_close(), [this] { closeBox(); }); _text1->setLinksTrusted(); _text2->setLinksTrusted(); diff --git a/Telegram/SourceFiles/boxes/abstract_box.cpp b/Telegram/SourceFiles/boxes/abstract_box.cpp index 2dc962386b..72ad0e2814 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.cpp +++ b/Telegram/SourceFiles/boxes/abstract_box.cpp @@ -25,19 +25,19 @@ void BoxContent::setTitle(rpl::producer title) { } QPointer BoxContent::addButton( - Fn textFactory, + rpl::producer text, Fn clickCallback) { return addButton( - std::move(textFactory), + std::move(text), std::move(clickCallback), st::defaultBoxButton); } QPointer BoxContent::addLeftButton( - Fn textFactory, + rpl::producer text, Fn clickCallback) { return getDelegate()->addLeftButton( - std::move(textFactory), + std::move(text), std::move(clickCallback), st::defaultBoxButton); } @@ -252,13 +252,21 @@ void BoxContent::paintEvent(QPaintEvent *e) { } } -AbstractBox::AbstractBox(not_null layer, object_ptr content) +AbstractBox::AbstractBox( + not_null layer, + object_ptr content) : LayerWidget(layer) , _layer(layer) , _content(std::move(content)) { - subscribe(Lang::Current().updated(), [this] { refreshLang(); }); + subscribe(Lang::Current().updated(), [=] { refreshLang(); }); _content->setParent(this); _content->setDelegate(this); + + _additionalTitle.changes( + ) | rpl::start_with_next([=] { + updateSize(); + update(); + }, lifetime()); } void AbstractBox::setLayerType(bool layerType) { @@ -297,7 +305,8 @@ void AbstractBox::paintEvent(QPaintEvent *e) { p.fillRect(rect, st::boxBg); } } - if (!_additionalTitle.isEmpty() && clip.intersects(QRect(0, 0, width(), titleHeight()))) { + if (!_additionalTitle.current().isEmpty() + && clip.intersects(QRect(0, 0, width(), titleHeight()))) { paintAdditionalTitle(p); } } @@ -305,7 +314,7 @@ void AbstractBox::paintEvent(QPaintEvent *e) { void AbstractBox::paintAdditionalTitle(Painter &p) { p.setFont(st::boxLayerTitleAdditionalFont); p.setPen(st::boxTitleAdditionalFg); - p.drawTextLeft(_titleLeft + (_title ? _title->width() : 0) + st::boxLayerTitleAdditionalSkip, _titleTop + st::boxTitleFont->ascent - st::boxLayerTitleAdditionalFont->ascent, width(), _additionalTitle); + p.drawTextLeft(_titleLeft + (_title ? _title->width() : 0) + st::boxLayerTitleAdditionalSkip, _titleTop + st::boxTitleFont->ascent - st::boxLayerTitleAdditionalFont->ascent, width(), _additionalTitle.current()); } void AbstractBox::parentResized() { @@ -328,9 +337,8 @@ void AbstractBox::setTitle(rpl::producer title) { } } -void AbstractBox::setAdditionalTitle(Fn additionalFactory) { - _additionalTitleFactory = std::move(additionalFactory); - refreshAdditionalTitle(); +void AbstractBox::setAdditionalTitle(rpl::producer additional) { + _additionalTitle = std::move(additional); } void AbstractBox::setCloseByOutsideClick(bool close) { @@ -341,18 +349,12 @@ bool AbstractBox::closeByOutsideClick() const { return _closeByOutsideClick; } -void AbstractBox::refreshAdditionalTitle() { - _additionalTitle = _additionalTitleFactory ? _additionalTitleFactory() : QString(); - update(); -} - void AbstractBox::refreshLang() { - refreshAdditionalTitle(); InvokeQueued(this, [this] { updateButtonsPositions(); }); } bool AbstractBox::hasTitle() const { - return (_title != nullptr) || !_additionalTitle.isEmpty(); + return (_title != nullptr) || !_additionalTitle.current().isEmpty(); } void AbstractBox::showBox( @@ -405,8 +407,11 @@ void AbstractBox::clearButtons() { _topButton = nullptr; } -QPointer AbstractBox::addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) { - _buttons.push_back(object_ptr(this, std::move(textFactory), st)); +QPointer AbstractBox::addButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) { + _buttons.emplace_back(this, std::move(text), st); auto result = QPointer(_buttons.back()); result->setClickedCallback(std::move(clickCallback)); result->show(); @@ -414,8 +419,11 @@ QPointer AbstractBox::addButton(Fn textFactory, Fn AbstractBox::addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) { - _leftButton = object_ptr(this, std::move(textFactory), st); +QPointer AbstractBox::addLeftButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) { + _leftButton = object_ptr(this, std::move(text), st); auto result = QPointer(_leftButton); result->setClickedCallback(std::move(clickCallback)); result->show(); diff --git a/Telegram/SourceFiles/boxes/abstract_box.h b/Telegram/SourceFiles/boxes/abstract_box.h index 71317a03c5..ab3765b10d 100644 --- a/Telegram/SourceFiles/boxes/abstract_box.h +++ b/Telegram/SourceFiles/boxes/abstract_box.h @@ -31,13 +31,21 @@ class BoxContentDelegate { public: virtual void setLayerType(bool layerType) = 0; virtual void setTitle(rpl::producer title) = 0; - virtual void setAdditionalTitle(Fn additionalFactory) = 0; + virtual void setAdditionalTitle(rpl::producer additional) = 0; virtual void setCloseByOutsideClick(bool close) = 0; virtual void clearButtons() = 0; - virtual QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; - virtual QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) = 0; - virtual QPointer addTopButton(const style::IconButton &st, Fn clickCallback) = 0; + virtual QPointer addButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) = 0; + virtual QPointer addLeftButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) = 0; + virtual QPointer addTopButton( + const style::IconButton &st, + Fn clickCallback) = 0; virtual void updateButtonsPositions() = 0; virtual void showBox( @@ -85,7 +93,7 @@ public: void setTitle(rpl::producer title) { getDelegate()->setTitle(std::move(title)); } - void setAdditionalTitle(Fn additional) { + void setAdditionalTitle(rpl::producer additional) { getDelegate()->setAdditionalTitle(std::move(additional)); } void setCloseByEscape(bool close) { @@ -100,16 +108,30 @@ public: void clearButtons() { getDelegate()->clearButtons(); } - QPointer addButton(Fn textFactory, Fn clickCallback = nullptr); - QPointer addLeftButton(Fn textFactory, Fn clickCallback = nullptr); - QPointer addTopButton(const style::IconButton &st, Fn clickCallback = nullptr) { + QPointer addButton( + rpl::producer text, + Fn clickCallback = nullptr); + QPointer addLeftButton( + rpl::producer text, + Fn clickCallback = nullptr); + QPointer addTopButton( + const style::IconButton &st, + Fn clickCallback = nullptr) { return getDelegate()->addTopButton(st, std::move(clickCallback)); } - QPointer addButton(Fn textFactory, const style::RoundButton &st) { - return getDelegate()->addButton(std::move(textFactory), nullptr, st); + QPointer addButton( + rpl::producer text, + const style::RoundButton &st) { + return getDelegate()->addButton(std::move(text), nullptr, st); } - QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) { - return getDelegate()->addButton(std::move(textFactory), std::move(clickCallback), st); + QPointer addButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) { + return getDelegate()->addButton( + std::move(text), + std::move(clickCallback), + st); } void updateButtonsGeometry() { getDelegate()->updateButtonsPositions(); @@ -156,10 +178,13 @@ protected: getDelegate()->setNoContentMargin(noContentMargin); } void setDimensions( - int newWidth, - int maxHeight, - bool forceCenterPosition = false) { - getDelegate()->setDimensions(newWidth, maxHeight, forceCenterPosition); + int newWidth, + int maxHeight, + bool forceCenterPosition = false) { + getDelegate()->setDimensions( + newWidth, + maxHeight, + forceCenterPosition); } void setDimensionsToContent( int newWidth, @@ -251,16 +276,24 @@ public: void setLayerType(bool layerType) override; void setTitle(rpl::producer title) override; - void setAdditionalTitle(Fn additionalFactory) override; + void setAdditionalTitle(rpl::producer additional) override; void showBox( object_ptr box, LayerOptions options, anim::type animated) override; void clearButtons() override; - QPointer addButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; - QPointer addLeftButton(Fn textFactory, Fn clickCallback, const style::RoundButton &st) override; - QPointer addTopButton(const style::IconButton &st, Fn clickCallback) override; + QPointer addButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) override; + QPointer addLeftButton( + rpl::producer text, + Fn clickCallback, + const style::RoundButton &st) override; + QPointer addTopButton( + const style::IconButton &st, + Fn clickCallback) override; void updateButtonsPositions() override; QPointer outerContainer() override; @@ -301,7 +334,6 @@ protected: private: void paintAdditionalTitle(Painter &p); void updateTitlePosition(); - void refreshAdditionalTitle(); void refreshLang(); bool hasTitle() const; @@ -322,8 +354,7 @@ private: object_ptr _title = { nullptr }; Fn _titleFactory; - QString _additionalTitle; - Fn _additionalTitleFactory; + rpl::variable _additionalTitle; int _titleLeft = 0; int _titleTop = 0; bool _layerType = false; diff --git a/Telegram/SourceFiles/boxes/add_contact_box.cpp b/Telegram/SourceFiles/boxes/add_contact_box.cpp index 2842a43b3a..fee5cd004b 100644 --- a/Telegram/SourceFiles/boxes/add_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/add_contact_box.cpp @@ -400,10 +400,12 @@ void AddContactBox::retry() { void AddContactBox::updateButtons() { clearButtons(); if (_retrying) { - addButton(langFactory(lng_try_other_contact), [this] { retry(); }); + addButton(tr::lng_try_other_contact(), [=] { retry(); }); } else { - addButton(langFactory(_user ? lng_settings_save : lng_add_contact), [this] { save(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton( + _user ? tr::lng_settings_save() : tr::lng_add_contact(), + [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } } @@ -464,8 +466,12 @@ void GroupInfoBox::prepare() { connect(_title, &Ui::InputField::submitted, [=] { submitName(); }); - addButton(langFactory((_type != Type::Group) ? lng_create_group_create : lng_create_group_next), [this] { submit(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton( + (_type != Type::Group + ? tr::lng_create_group_create() + : tr::lng_create_group_next()), + [=] { submit(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); updateMaxHeight(); } @@ -618,12 +624,8 @@ void GroupInfoBox::submit() { } } }; - box->addButton( - langFactory(lng_create_group_create), - std::move(create)); - box->addButton( - langFactory(lng_cancel), - [box] { box->closeBox(); }); + box->addButton(tr::lng_create_group_create(), std::move(create)); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; Ui::show( Box( @@ -744,10 +746,17 @@ void SetupChannelBox::prepare() { setMouseTracking(true); - _checkRequestId = MTP::send(MTPchannels_CheckUsername(_channel->inputChannel, MTP_string("preston")), RPCDoneHandlerPtr(), rpcFail(&SetupChannelBox::onFirstCheckFail)); + _checkRequestId = MTP::send( + MTPchannels_CheckUsername( + _channel->inputChannel, + MTP_string("preston")), + RPCDoneHandlerPtr(), + rpcFail(&SetupChannelBox::onFirstCheckFail)); - addButton(langFactory(lng_settings_save), [=] { save(); }); - addButton(langFactory(_existing ? lng_cancel : lng_create_group_skip), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton( + _existing ? tr::lng_cancel() : tr::lng_create_group_skip(), + [=] { closeBox(); }); connect(_link, &Ui::MaskedInputField::changed, [=] { handleChange(); }); _link->setVisible(_privacyGroup->value() == Privacy::Public); @@ -1101,8 +1110,8 @@ void EditNameBox::prepare() { newHeight += st::boxPadding.bottom() + st::contactPadding.bottom(); setDimensions(st::boxWideWidth, newHeight); - addButton(langFactory(lng_settings_save), [=] { save(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); if (_invertOrder) { setTabOrder(_last, _first); } @@ -1266,7 +1275,7 @@ void RevokePublicLinkBox::prepare() { } }), st::boxLayerScroll, _innerTop); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); subscribe(Auth().downloaderTaskFinished(), [=] { update(); }); diff --git a/Telegram/SourceFiles/boxes/auto_download_box.cpp b/Telegram/SourceFiles/boxes/auto_download_box.cpp index 4f8b42a0c1..c47f85084f 100644 --- a/Telegram/SourceFiles/boxes/auto_download_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_download_box.cpp @@ -121,7 +121,7 @@ void AutoDownloadBox::setupContent() { limits->fire_copy(value); }); - addButton(langFactory(lng_connection_save), [=] { + addButton(tr::lng_connection_save(), [=] { auto allowMore = ranges::view::all( *values ) | ranges::view::filter([&](Pair pair) { @@ -173,7 +173,7 @@ void AutoDownloadBox::setupContent() { } closeBox(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensionsToContent(st::boxWidth, content); } diff --git a/Telegram/SourceFiles/boxes/auto_lock_box.cpp b/Telegram/SourceFiles/boxes/auto_lock_box.cpp index 0afc15b98e..0c1cf79786 100644 --- a/Telegram/SourceFiles/boxes/auto_lock_box.cpp +++ b/Telegram/SourceFiles/boxes/auto_lock_box.cpp @@ -16,7 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL void AutoLockBox::prepare() { setTitle(tr::lng_passcode_autolock()); - addButton(langFactory(lng_box_ok), [this] { closeBox(); }); + addButton(tr::lng_box_ok(), [this] { closeBox(); }); auto options = { 60, 300, 3600, 18000 }; diff --git a/Telegram/SourceFiles/boxes/background_box.cpp b/Telegram/SourceFiles/boxes/background_box.cpp index 4f48f08367..dfb47012fb 100644 --- a/Telegram/SourceFiles/boxes/background_box.cpp +++ b/Telegram/SourceFiles/boxes/background_box.cpp @@ -124,7 +124,7 @@ BackgroundBox::BackgroundBox(QWidget*) { void BackgroundBox::prepare() { setTitle(tr::lng_backgrounds_header()); - addButton(langFactory(lng_close), [=] { closeBox(); }); + addButton(tr::lng_close(), [=] { closeBox(); }); setDimensions(st::boxWideWidth, st::boxMaxListHeight); diff --git a/Telegram/SourceFiles/boxes/background_preview_box.cpp b/Telegram/SourceFiles/boxes/background_preview_box.cpp index 3ca1f73e22..77142c8284 100644 --- a/Telegram/SourceFiles/boxes/background_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/background_preview_box.cpp @@ -409,10 +409,10 @@ not_null BackgroundPreviewBox::delegate() { void BackgroundPreviewBox::prepare() { setTitle(tr::lng_background_header()); - addButton(langFactory(lng_background_apply), [=] { apply(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_background_apply(), [=] { apply(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); if (_paper.hasShareUrl()) { - addLeftButton(langFactory(lng_background_share), [=] { share(); }); + addLeftButton(tr::lng_background_share(), [=] { share(); }); } updateServiceBg(_paper.backgroundColor()); diff --git a/Telegram/SourceFiles/boxes/calendar_box.cpp b/Telegram/SourceFiles/boxes/calendar_box.cpp index bf725a82c4..d4aea75bbc 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -501,7 +501,7 @@ void CalendarBox::prepare() { // _inner = setInnerWidget(object_ptr(this, _context.get()), st::calendarScroll, st::calendarTitleHeight); _inner->setDateChosenCallback(std::move(_callback)); - addButton(langFactory(lng_close), [this] { closeBox(); }); + addButton(tr::lng_close(), [this] { closeBox(); }); subscribe(_context->month(), [this](QDate month) { monthChanged(month); }); diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index c29b17ef68..58e322da5d 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -135,8 +135,8 @@ void ChangePhoneBox::EnterPhone::prepare() { setDimensions(st::boxWidth, description->bottomNoMargins() + st::boxLittleSkip); - addButton(langFactory(lng_change_phone_new_submit), [this] { submit(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_change_phone_new_submit(), [this] { submit(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); } void ChangePhoneBox::EnterPhone::submit() { @@ -237,9 +237,11 @@ ChangePhoneBox::EnterCode::EnterCode(QWidget*, const QString &phone, const QStri void ChangePhoneBox::EnterCode::prepare() { setTitle(tr::lng_change_phone_title()); - auto descriptionText = lng_change_phone_code_description__rich( + auto descriptionText = tr::lng_change_phone_code_description( + tr::now, lt_phone, - Ui::Text::Bold(App::formatPhone(_phone))); + Ui::Text::Bold(App::formatPhone(_phone)), + Ui::Text::WithEntities); auto description = object_ptr(this, rpl::single(descriptionText), st::changePhoneLabel); description->moveToLeft(st::boxPadding.left(), 0); @@ -259,8 +261,8 @@ void ChangePhoneBox::EnterCode::prepare() { updateCall(); } - addButton(langFactory(lng_change_phone_new_submit), [=] { submit(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_change_phone_new_submit(), [=] { submit(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } int ChangePhoneBox::EnterCode::countHeight() { @@ -339,12 +341,12 @@ bool ChangePhoneBox::EnterCode::sendCodeFail(const RPCError &error) { void ChangePhoneBox::prepare() { setTitle(tr::lng_change_phone_title()); - addButton(langFactory(lng_change_phone_button), [] { + addButton(tr::lng_change_phone_button(), [] { Ui::show(Box(lang(lng_change_phone_warning), [] { Ui::show(Box()); })); }); - addButton(langFactory(lng_cancel), [this] { + addButton(tr::lng_cancel(), [this] { closeBox(); }); diff --git a/Telegram/SourceFiles/boxes/confirm_box.cpp b/Telegram/SourceFiles/boxes/confirm_box.cpp index 92c13f0c91..4fb193d2ce 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_box.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/toast/toast.h" #include "ui/image/image.h" +#include "ui/text/text_utilities.h" #include "ui/empty_userpic.h" #include "core/click_handler_types.h" #include "window/window_session_controller.h" @@ -183,12 +184,12 @@ void ConfirmBox::init(const TextWithEntities &text) { void ConfirmBox::prepare() { addButton( - [=] { return _confirmText; }, + rpl::single(_confirmText), [=] { confirmed(); }, _confirmStyle); if (!_informative) { addButton( - [=] { return _cancelText; }, + rpl::single(_cancelText), [=] { _cancelled = true; closeBox(); }); } @@ -320,7 +321,7 @@ MaxInviteBox::MaxInviteBox(QWidget*, not_null channel) : BoxConten void MaxInviteBox::prepare() { setMouseTracking(true); - addButton(langFactory(lng_box_ok), [this] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); _textWidth = st::boxWidth - st::boxPadding.left() - st::boxButtonPadding.right(); _textHeight = qMin(_text.countHeight(_textWidth), 16 * st::boxLabelStyle.lineHeight); @@ -396,8 +397,8 @@ PinMessageBox::PinMessageBox( } void PinMessageBox::prepare() { - addButton(langFactory(lng_pinned_pin), [this] { pinMessage(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_pinned_pin(), [this] { pinMessage(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); if (_peer->isChat() || _peer->isMegagroup()) { _notify.create(this, lang(lng_pinned_notify), true, st::defaultBoxCheckbox); @@ -488,7 +489,7 @@ void DeleteMessagesBox::prepare() { const auto appendDetails = [&](TextWithEntities &&text) { details.append(qstr("\n\n")).append(std::move(text)); }; - auto deleteKey = lng_box_delete; + auto deleteText = tr::lng_box_delete(); auto deleteStyle = &st::defaultBoxButton; if (const auto peer = _wipeHistoryPeer) { if (_wipeHistoryJustClear) { @@ -508,9 +509,9 @@ void DeleteMessagesBox::prepare() { : lang(peer->isMegagroup() ? lng_sure_leave_group : lng_sure_leave_channel); - deleteKey = _wipeHistoryPeer->isUser() - ? lng_box_delete - : lng_box_leave; + deleteText = _wipeHistoryPeer->isUser() + ? tr::lng_box_delete() + : tr::lng_box_leave(); deleteStyle = &(peer->isChannel() ? st::defaultBoxButton : st::attentionBoxButton); @@ -521,6 +522,7 @@ void DeleteMessagesBox::prepare() { } } else if (_moderateFrom) { Assert(_moderateInChannel != nullptr); + details.text = lang(lng_selected_delete_sure_this); if (_moderateBan) { _banUser.create(this, lang(lng_ban_user), false, st::defaultBoxCheckbox); @@ -552,10 +554,10 @@ void DeleteMessagesBox::prepare() { _text.create(this, rpl::single(std::move(details)), st::boxLabel); addButton( - langFactory(deleteKey), + std::move(deleteText), [=] { deleteAndClear(); }, *deleteStyle); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); auto fullHeight = st::boxPadding.top() + _text->height() + st::boxPadding.bottom(); if (_moderateFrom) { @@ -639,34 +641,37 @@ auto DeleteMessagesBox::revokeText(not_null peer) const lt_user, user->firstName); } else { - result.checkbox = lang(lng_delete_for_everyone_check); + result.checkbox = tr::lng_delete_for_everyone_check(tr::now); } return result; } else if (canRevokeOutgoingCount > 0) { - result.checkbox = lang(lng_delete_for_other_my); + result.checkbox = tr::lng_delete_for_other_my(tr::now); if (const auto user = peer->asUser()) { - auto boldName = TextWithEntities{ user->firstName }; - boldName.entities.push_back( - { EntityType::Bold, 0, boldName.text.size() }); if (canRevokeOutgoingCount == 1) { - result.description = lng_selected_unsend_about_user_one__rich( + result.description = tr::lng_selected_unsend_about_user_one( + tr::now, lt_user, - boldName); + Ui::Text::Bold(user->shortName()), + Ui::Text::WithEntities); } else { - result.description = lng_selected_unsend_about_user__rich( + result.description = tr::lng_selected_unsend_about_user( + tr::now, lt_count, canRevokeOutgoingCount, lt_user, - boldName); + Ui::Text::Bold(user->shortName()), + Ui::Text::WithEntities); } } else if (canRevokeOutgoingCount == 1) { - result.description = TextWithEntities{ - lang(lng_selected_unsend_about_group_one) }; + result.description = tr::lng_selected_unsend_about_group_one( + tr::now, + Ui::Text::WithEntities); } else { - result.description = TextWithEntities{ - lng_selected_unsend_about_group( - lt_count, - canRevokeOutgoingCount) }; + result.description = tr::lng_selected_unsend_about_group( + tr::now, + lt_count, + canRevokeOutgoingCount, + Ui::Text::WithEntities); } return result; } @@ -836,11 +841,12 @@ std::vector> ConfirmInviteBox::GetParticipants( } void ConfirmInviteBox::prepare() { - const auto joinKey = _isChannel - ? lng_profile_join_channel - : lng_profile_join_group; - addButton(langFactory(joinKey), _submit); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton( + (_isChannel + ? tr::lng_profile_join_channel() + : tr::lng_profile_join_group()), + _submit); + addButton(tr::lng_cancel(), [=] { closeBox(); }); while (_participants.size() > 4) { _participants.pop_back(); @@ -913,16 +919,16 @@ ConfirmDontWarnBox::ConfirmDontWarnBox( QWidget*, rpl::producer text, const QString &checkbox, - const QString &confirm, + rpl::producer confirm, FnMut callback) -: _confirm(confirm) +: _confirm(std::move(confirm)) , _content(setupContent(std::move(text), checkbox, std::move(callback))) { } void ConfirmDontWarnBox::prepare() { setDimensionsToContent(st::boxWidth, _content); - addButton([=] { return _confirm; }, [=] { _callback(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(std::move(_confirm), [=] { _callback(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } not_null ConfirmDontWarnBox::setupContent( diff --git a/Telegram/SourceFiles/boxes/confirm_box.h b/Telegram/SourceFiles/boxes/confirm_box.h index a6d5f6218b..afaa940374 100644 --- a/Telegram/SourceFiles/boxes/confirm_box.h +++ b/Telegram/SourceFiles/boxes/confirm_box.h @@ -226,7 +226,7 @@ public: QWidget*, rpl::producer text, const QString &checkbox, - const QString &confirm, + rpl::producer confirm, FnMut callback); protected: @@ -238,7 +238,7 @@ private: const QString &checkbox, FnMut callback); - QString _confirm; + rpl::producer _confirm; FnMut _callback; not_null _content; diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index 0adaa0f257..5a046dfa7d 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -284,8 +284,8 @@ void ConfirmPhoneBox::prepare() { setTitle(tr::lng_confirm_phone_title()); - addButton(langFactory(lng_confirm_phone_send), [=] { sendCode(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_confirm_phone_send(), [=] { sendCode(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensions(st::boxWidth, st::usernamePadding.top() + _code->height() + st::usernameSkip + _about->height() + st::usernameSkip); diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 2fe3826fd4..f0b72df396 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -471,8 +471,8 @@ ProxiesBox::ProxiesBox( void ProxiesBox::prepare() { setTitle(tr::lng_proxy_settings()); - addButton(langFactory(lng_proxy_add), [=] { addNewProxy(); }); - addButton(langFactory(lng_close), [=] { closeBox(); }); + addButton(tr::lng_proxy_add(), [=] { addNewProxy(); }); + addButton(tr::lng_close(), [=] { closeBox(); }); setupContent(); } @@ -706,12 +706,12 @@ void ProxyBox::prepare() { void ProxyBox::refreshButtons() { clearButtons(); - addButton(langFactory(lng_settings_save), [=] { save(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); const auto type = _type->value(); if (type == Type::Socks5 || type == Type::Mtproto) { - addLeftButton(langFactory(lng_proxy_share), [=] { share(); }); + addLeftButton(tr::lng_proxy_share(), [=] { share(); }); } } diff --git a/Telegram/SourceFiles/boxes/create_poll_box.cpp b/Telegram/SourceFiles/boxes/create_poll_box.cpp index 6f89b93892..163b32b17d 100644 --- a/Telegram/SourceFiles/boxes/create_poll_box.cpp +++ b/Telegram/SourceFiles/boxes/create_poll_box.cpp @@ -700,10 +700,10 @@ object_ptr CreatePollBox::setupContent() { clearButtons(); if (valid) { addButton( - langFactory(lng_polls_create_button), + tr::lng_polls_create_button(), [=] { _submitRequests.fire(collectResult()); }); } - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); }, lifetime()); options->isValidChanged( diff --git a/Telegram/SourceFiles/boxes/download_path_box.cpp b/Telegram/SourceFiles/boxes/download_path_box.cpp index 27fdff328a..3bfc1c1ec4 100644 --- a/Telegram/SourceFiles/boxes/download_path_box.cpp +++ b/Telegram/SourceFiles/boxes/download_path_box.cpp @@ -26,8 +26,8 @@ DownloadPathBox::DownloadPathBox(QWidget *parent) } void DownloadPathBox::prepare() { - addButton(langFactory(lng_connection_save), [this] { save(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_connection_save(), [this] { save(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); setTitle(tr::lng_download_path_header()); diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 395ece0d79..421f1df94e 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -583,13 +583,13 @@ void EditCaptionBox::createEditMediaButton() { } void EditCaptionBox::prepare() { - addButton(langFactory(lng_settings_save), [this] { save(); }); + addButton(tr::lng_settings_save(), [this] { save(); }); if (_isAllowedEditMedia) { createEditMediaButton(); } else { _preparedList.files.clear(); } - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); updateBoxSize(); connect(_field, &Ui::InputField::submitted, [=] { save(); }); diff --git a/Telegram/SourceFiles/boxes/edit_color_box.cpp b/Telegram/SourceFiles/boxes/edit_color_box.cpp index 99e7a346f4..e4b6ae08b9 100644 --- a/Telegram/SourceFiles/boxes/edit_color_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_color_box.cpp @@ -654,8 +654,8 @@ void EditColorBox::prepare() { connect(_blueField, &Ui::MaskedInputField::submitted, submitted); connect(_result, &Ui::MaskedInputField::submitted, submitted); - addButton(langFactory(lng_settings_save), [=] { saveColor(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { saveColor(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); auto height = st::colorEditSkip + st::colorPickerSize + st::colorEditSkip + st::colorSliderWidth + st::colorEditSkip; setDimensions(st::colorEditWidth, height); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 4ed9dc72e0..75a6c0c7fd 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -133,7 +133,7 @@ void EditPrivacyBox::editExceptions( exceptions(exception)); auto initBox = [=, controller = controller.get()]( not_null box) { - box->addButton(langFactory(lng_settings_save), crl::guard(this, [=] { + box->addButton(tr::lng_settings_save(), crl::guard(this, [=] { exceptions(exception) = controller->getResult(); const auto type = [&] { switch (exception) { @@ -151,7 +151,7 @@ void EditPrivacyBox::editExceptions( done(); box->closeBox(); })); - box->addButton(langFactory(lng_cancel), [=] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; Ui::show( Box(std::move(controller), std::move(initBox)), @@ -354,7 +354,7 @@ void EditPrivacyBox::setupContent() { content->add(std::move(below)); } - addButton(langFactory(lng_settings_save), [=] { + addButton(tr::lng_settings_save(), [=] { const auto someAreDisallowed = (_value.option != Option::Everyone) || !_value.never.empty(); _controller->confirmSave(someAreDisallowed, crl::guard(this, [=] { @@ -364,7 +364,7 @@ void EditPrivacyBox::setupContent() { closeBox(); })); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); const auto linkHeight = st::settingsButton.padding.top() + st::settingsButton.height diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index 6cf02dbe6f..c679160588 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -1035,7 +1035,7 @@ Ui::ScrollToRequest Content::jump(int rows) { } // namespace void LanguageBox::prepare() { - addButton(langFactory(lng_box_ok), [=] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); setTitle(tr::lng_languages()); diff --git a/Telegram/SourceFiles/boxes/local_storage_box.cpp b/Telegram/SourceFiles/boxes/local_storage_box.cpp index 84c90b5f9e..6ca24418bc 100644 --- a/Telegram/SourceFiles/boxes/local_storage_box.cpp +++ b/Telegram/SourceFiles/boxes/local_storage_box.cpp @@ -124,7 +124,7 @@ public: Row( QWidget *parent, Fn title, - Fn clear, + rpl::producer clear, const Database::TaggedSummary &data); void update(const Database::TaggedSummary &data); @@ -153,7 +153,7 @@ private: LocalStorageBox::Row::Row( QWidget *parent, Fn title, - Fn clear, + rpl::producer clear, const Database::TaggedSummary &data) : RpWidget(parent) , _titleFactory(std::move(title)) @@ -299,7 +299,7 @@ void LocalStorageBox::Show( void LocalStorageBox::prepare() { setTitle(tr::lng_local_storage_title()); - addButton(langFactory(lng_box_ok), [this] { closeBox(); }); + addButton(tr::lng_box_ok(), [this] { closeBox(); }); setupControls(); } @@ -365,7 +365,7 @@ void LocalStorageBox::setupControls() { const auto createRow = [&]( uint16 tag, Fn title, - Fn clear, + rpl::producer clear, const Database::TaggedSummary &data) { auto result = container->add(object_ptr>( container, @@ -395,7 +395,7 @@ void LocalStorageBox::setupControls() { tracker.track(createRow( tag, std::move(title), - langFactory(lng_local_storage_clear_some), + tr::lng_local_storage_clear_some(), data)); }; auto summaryTitle = [](size_type) { @@ -407,7 +407,7 @@ void LocalStorageBox::setupControls() { createRow( 0, std::move(summaryTitle), - langFactory(lng_local_storage_clear), + tr::lng_local_storage_clear(), summary()); setupLimits(container); const auto shadow = container->add(object_ptr>( @@ -422,7 +422,7 @@ void LocalStorageBox::setupControls() { tracker.track(createRow( kFakeMediaCacheTag, std::move(mediaCacheTitle), - langFactory(lng_local_storage_clear_some), + tr::lng_local_storage_clear_some(), _statsBig.full)); shadow->toggleOn( std::move(tracker).atLeastOneShownValue() @@ -572,10 +572,10 @@ void LocalStorageBox::limitsChanged() { _limitsChanged = changed; clearButtons(); if (_limitsChanged) { - addButton(langFactory(lng_settings_save), [=] { save(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } else { - addButton(langFactory(lng_box_ok), [=] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); } } } diff --git a/Telegram/SourceFiles/boxes/mute_settings_box.cpp b/Telegram/SourceFiles/boxes/mute_settings_box.cpp index be96723ead..9de1132d8e 100644 --- a/Telegram/SourceFiles/boxes/mute_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/mute_settings_box.cpp @@ -78,8 +78,8 @@ void MuteSettingsBox::prepare() { muteForSeconds); closeBox(); }; - addButton(langFactory(lng_box_ok), _save); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_box_ok(), _save); + addButton(tr::lng_cancel(), [this] { closeBox(); }); setDimensions(st::boxWidth, y); } diff --git a/Telegram/SourceFiles/boxes/passcode_box.cpp b/Telegram/SourceFiles/boxes/passcode_box.cpp index a59aa45d24..c04aeebe3b 100644 --- a/Telegram/SourceFiles/boxes/passcode_box.cpp +++ b/Telegram/SourceFiles/boxes/passcode_box.cpp @@ -92,12 +92,14 @@ bool PasscodeBox::onlyCheckCurrent() const { } void PasscodeBox::prepare() { - addButton([=] { - return _cloudFields.customSubmitButton.value_or(lang(_turningOff - ? lng_passcode_remove_button - : lng_settings_save)); - }, [=] { save(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton( + (_cloudFields.customSubmitButton + ? rpl::single(*_cloudFields.customSubmitButton) + : _turningOff + ? tr::lng_passcode_remove_button() + : tr::lng_settings_save()), + [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); _about.setText( st::passcodeTextStyle, @@ -914,8 +916,8 @@ rpl::producer<> RecoverBox::recoveryExpired() const { void RecoverBox::prepare() { setTitle(tr::lng_signin_recover_title()); - addButton(langFactory(lng_passcode_submit), [=] { submit(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_passcode_submit(), [=] { submit(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensions(st::boxWidth, st::passcodePadding.top() + st::passcodePadding.bottom() + st::passcodeTextLine + _recoverCode->height() + st::passcodeTextLine); diff --git a/Telegram/SourceFiles/boxes/peer_list_box.h b/Telegram/SourceFiles/boxes/peer_list_box.h index e5992f9d16..0823fec5d8 100644 --- a/Telegram/SourceFiles/boxes/peer_list_box.h +++ b/Telegram/SourceFiles/boxes/peer_list_box.h @@ -226,7 +226,7 @@ struct PeerListState; class PeerListDelegate { public: virtual void peerListSetTitle(rpl::producer title) = 0; - virtual void peerListSetAdditionalTitle(Fn title) = 0; + virtual void peerListSetAdditionalTitle(rpl::producer title) = 0; virtual void peerListSetDescription(object_ptr description) = 0; virtual void peerListSetSearchLoading(object_ptr loading) = 0; virtual void peerListSetSearchNoResults(object_ptr noResults) = 0; @@ -758,8 +758,7 @@ public: void peerListSetTitle(rpl::producer title) override { setTitle(std::move(title)); } - void peerListSetAdditionalTitle( - Fn title) override { + void peerListSetAdditionalTitle(rpl::producer title) override { setAdditionalTitle(std::move(title)); } void peerListSetSearchMode(PeerListSearchMode mode) override; diff --git a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp index c687751a55..d8bcddab5b 100644 --- a/Telegram/SourceFiles/boxes/peer_list_controllers.cpp +++ b/Telegram/SourceFiles/boxes/peer_list_controllers.cpp @@ -393,7 +393,7 @@ std::unique_ptr ContactsBoxController::createRow(not_null bot) { auto initBox = [=](not_null box) { - box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; Ui::show(Box(std::make_unique(bot), std::move(initBox))); } diff --git a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp index a82c42b605..a1205d76ee 100644 --- a/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_participants_box.cpp @@ -153,10 +153,10 @@ void AddParticipantsBoxController::updateTitle() { const auto additional = (_peer && _peer->isChannel() && !_peer->isMegagroup()) - ? QString() : - QString("%1 / %2").arg(fullCount()).arg(Global::MegagroupSizeMax()); + ? QString() + : qsl("%1 / %2").arg(fullCount()).arg(Global::MegagroupSizeMax()); delegate()->peerListSetTitle(tr::lng_profile_add_participant()); - delegate()->peerListSetAdditionalTitle([=] { return additional; }); + delegate()->peerListSetAdditionalTitle(rpl::single(additional)); } bool AddParticipantsBoxController::inviteSelectedUsers( @@ -183,12 +183,12 @@ void AddParticipantsBoxController::Start(not_null chat) { auto controller = std::make_unique(chat); const auto weak = controller.get(); auto initBox = [=](not_null box) { - box->addButton(langFactory(lng_participant_invite), [=] { + box->addButton(tr::lng_participant_invite(), [=] { if (weak->inviteSelectedUsers(box)) { Ui::showPeerHistory(chat, ShowAtTheEndMsgId); } }); - box->addButton(langFactory(lng_cancel), [=] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; Ui::show( Box( @@ -206,7 +206,7 @@ void AddParticipantsBoxController::Start( std::move(alreadyIn)); const auto weak = controller.get(); auto initBox = [=](not_null box) { - box->addButton(langFactory(lng_participant_invite), [=] { + box->addButton(tr::lng_participant_invite(), [=] { if (weak->inviteSelectedUsers(box)) { if (channel->isMegagroup()) { Ui::showPeerHistory(channel, ShowAtTheEndMsgId); @@ -216,7 +216,7 @@ void AddParticipantsBoxController::Start( } }); box->addButton( - langFactory(justCreated ? lng_create_group_skip : lng_cancel), + justCreated ? tr::lng_create_group_skip() : tr::lng_cancel(), [=] { box->closeBox(); }); if (justCreated) { box->boxClosing() | rpl::start_with_next([=] { diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 2f746204ce..b25aab530b 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -80,8 +80,8 @@ void Controller::prepare() { ? tr::lng_edit_contact_title() : tr::lng_enter_contact_data()); - _box->addButton(langFactory(lng_box_done), _save); - _box->addButton(langFactory(lng_cancel), [=] { _box->closeBox(); }); + _box->addButton(tr::lng_box_done(), _save); + _box->addButton(tr::lng_cancel(), [=] { _box->closeBox(); }); _box->setFocusCallback(_focus); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp index b0dfdec4c8..f0eca85732 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_linked_chat_box.cpp @@ -116,22 +116,25 @@ void Controller::rowClicked(not_null row) { } void Controller::choose(not_null chat) { - auto text = lng_manage_discussion_group_sure__rich( + auto text = tr::lng_manage_discussion_group_sure( + tr::now, lt_group, Ui::Text::Bold(chat->name), lt_channel, - Ui::Text::Bold(_channel->name)); + Ui::Text::Bold(_channel->name), + Ui::Text::WithEntities); if (!_channel->isPublic()) { text.append( - "\n\n" + lang(lng_manage_linked_channel_private)); + "\n\n" + tr::lng_manage_linked_channel_private(tr::now)); } if (!chat->isPublic()) { - text.append("\n\n" + lang(lng_manage_discussion_group_private)); + text.append( + "\n\n" + tr::lng_manage_discussion_group_private(tr::now)); if (chat->hiddenPreHistory()) { text.append("\n\n"); - text.append(lng_manage_discussion_group_warning__rich( - lt_visible, - Ui::Text::Bold(lang(lng_manage_discussion_group_visible)))); + text.append(tr::lng_manage_discussion_group_warning( + tr::now, + Ui::Text::RichLangValue)); } } const auto box = std::make_shared>(); @@ -151,20 +154,21 @@ void Controller::choose(not_null chat) { } void Controller::choose(not_null chat) { - auto text = lng_manage_discussion_group_sure__rich( + auto text = tr::lng_manage_discussion_group_sure( + tr::now, lt_group, Ui::Text::Bold(chat->name), lt_channel, - Ui::Text::Bold(_channel->name)); + Ui::Text::Bold(_channel->name), + Ui::Text::WithEntities); if (!_channel->isPublic()) { - text.append( - "\n\n" + lang(lng_manage_linked_channel_private)); + text.append("\n\n" + tr::lng_manage_linked_channel_private(tr::now)); } - text.append("\n\n" + lang(lng_manage_discussion_group_private)); + text.append("\n\n" + tr::lng_manage_discussion_group_private(tr::now)); text.append("\n\n"); - text.append(lng_manage_discussion_group_warning__rich( - lt_visible, - Ui::Text::Bold(lang(lng_manage_discussion_group_visible)))); + text.append(tr::lng_manage_discussion_group_warning( + tr::now, + Ui::Text::RichLangValue)); const auto box = std::make_shared>(); const auto sure = [=] { if (*box) { @@ -192,18 +196,23 @@ object_ptr SetupAbout( parent, QString(), st::linkedChatAbout); - about->setMarkedText([&]() -> TextWithEntities { + about->setMarkedText([&] { if (!channel->isBroadcast()) { - return lng_manage_linked_channel_about__rich( + return tr::lng_manage_linked_channel_about( + tr::now, lt_channel, - Ui::Text::Bold(chat->name)); + Ui::Text::Bold(chat->name), + Ui::Text::WithEntities); } else if (chat != nullptr) { - return lng_manage_discussion_group_about_chosen__rich( + return tr::lng_manage_discussion_group_about_chosen( + tr::now, lt_group, - Ui::Text::Bold(chat->name)); - } else { - return { lang(lng_manage_discussion_group_about) }; + Ui::Text::Bold(chat->name), + Ui::Text::WithEntities); } + return tr::lng_manage_discussion_group_about( + tr::now, + Ui::Text::WithEntities); }()); return std::move(about); } @@ -288,7 +297,7 @@ object_ptr EditLinkedChatBox( box->setTitle(channel->isBroadcast() ? tr::lng_manage_discussion_group() : tr::lng_manage_linked_channel()); - box->addButton(langFactory(lng_close), [=] { box->closeBox(); }); + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); }; auto controller = std::make_unique( channel, diff --git a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp index a7e73e4a9a..90b9003ad7 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participant_box.cpp @@ -72,30 +72,37 @@ void TransferPasswordError( box->setTitle(tr::lng_rights_transfer_check()); box->setWidth(st::transferCheckWidth); - auto text = lng_rights_transfer_check_about__rich( + auto text = tr::lng_rights_transfer_check_about( + tr::now, lt_user, - Ui::Text::Bold(user->shortName()) + Ui::Text::Bold(user->shortName()), + Ui::Text::WithEntities ).append('\n').append('\n').append( - Ui::Text::RichLangValue(lang(lng_rights_transfer_check_password)) + tr::lng_rights_transfer_check_password( + tr::now, + Ui::Text::RichLangValue) ).append('\n').append('\n').append( - Ui::Text::RichLangValue(lang(lng_rights_transfer_check_session)) + tr::lng_rights_transfer_check_session( + tr::now, + Ui::Text::RichLangValue) ); if (error == PasswordErrorType::Later) { text.append('\n').append('\n').append( - Ui::Text::RichLangValue(lang(lng_rights_transfer_check_later)) - ); + tr::lng_rights_transfer_check_later( + tr::now, + Ui::Text::RichLangValue)); } box->addRow(object_ptr( box, rpl::single(text), st::boxLabel)); if (error == PasswordErrorType::Later) { - box->addButton(langFactory(lng_box_ok), [=] { box->closeBox(); }); + box->addButton(tr::lng_box_ok(), [=] { box->closeBox(); }); } else { - box->addButton(langFactory(lng_rights_transfer_set_password), [=] { + box->addButton(tr::lng_rights_transfer_set_password(), [=] { SetCloudPassword(box, user); }); - box->addButton(langFactory(lng_cancel), [=] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } } @@ -355,7 +362,7 @@ void EditAdminBox::prepare() { }, lifetime()); if (canSave()) { - addButton(langFactory(lng_settings_save), [=, value = getChecked] { + addButton(tr::lng_settings_save(), [=, value = getChecked] { if (!_saveCallback) { return; } @@ -367,9 +374,9 @@ void EditAdminBox::prepare() { _oldRights, MTP_chatAdminRights(MTP_flags(newFlags))); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); } else { - addButton(langFactory(lng_box_ok), [this] { closeBox(); }); + addButton(tr::lng_box_ok(), [this] { closeBox(); }); } } @@ -652,10 +659,10 @@ void EditRestrictedBox::prepare() { MTP_flags(value()), MTP_int(getRealUntilValue()))); }; - addButton(langFactory(lng_settings_save), save); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), save); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } else { - addButton(langFactory(lng_box_ok), [=] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); } } @@ -682,7 +689,7 @@ void EditRestrictedBox::showRestrictUntil() { QDate::currentDate().addDays(kMaxRestrictDelayDays)); _restrictUntilBox->setMinDate(tomorrow); _restrictUntilBox->addLeftButton( - langFactory(lng_rights_chat_banned_forever), + tr::lng_rights_chat_banned_forever(), [=] { setRestrictUntil(0); }); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp index a52a29dc5f..3a0ccc3c89 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_participants_box.cpp @@ -787,7 +787,7 @@ void ParticipantsBoxController::Start( role); auto initBox = [=, controller = controller.get()]( not_null box) { - box->addButton(langFactory(lng_close), [=] { box->closeBox(); }); + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); const auto chat = peer->asChat(); const auto channel = peer->asChannel(); @@ -814,23 +814,23 @@ void ParticipantsBoxController::Start( Unexpected("Role value in ParticipantsBoxController::Start()"); }(); - const auto addNewItemText = [&] { + auto addNewItemText = [&] { switch (role) { case Role::Members: - return langFactory((chat || channel->isMegagroup()) - ? lng_channel_add_members - : lng_channel_add_users); + return (chat || channel->isMegagroup()) + ? tr::lng_channel_add_members() + : tr::lng_channel_add_users(); case Role::Admins: - return langFactory(lng_channel_add_admin); + return tr::lng_channel_add_admin(); case Role::Restricted: - return langFactory(lng_channel_add_exception); + return tr::lng_channel_add_exception(); case Role::Kicked: - return langFactory(lng_channel_add_removed); + return tr::lng_channel_add_removed(); } Unexpected("Role value in ParticipantsBoxController::Start()"); }(); if (canAddNewItem) { - box->addLeftButton(addNewItemText, [=] { + box->addLeftButton(std::move(addNewItemText), [=] { controller->addNewItem(); }); } @@ -858,7 +858,7 @@ void ParticipantsBoxController::addNewItem() { editRestrictedDone(user, rights); }); const auto initBox = [](not_null box) { - box->addButton(langFactory(lng_cancel), [=] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }; _addBox = Ui::show( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp index 9286c84adf..f82e4f5d4a 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_history_visibility_box.cpp @@ -112,12 +112,12 @@ void EditPeerHistoryVisibilityBox::prepare() { _peer->updateFull(); setTitle(tr::lng_manage_history_visibility_title()); - addButton(langFactory(lng_settings_save), [=] { + addButton(tr::lng_settings_save(), [=] { auto local = std::move(_savedCallback); local(_historyVisibility->value()); closeBox(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setupContent(); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 98f4546aa5..50283d98dd 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -272,10 +272,10 @@ Controller::Controller( _box->setTitle(_isGroup ? tr::lng_edit_group() : tr::lng_edit_channel_title()); - _box->addButton(langFactory(lng_settings_save), [this] { + _box->addButton(tr::lng_settings_save(), [this] { save(); }); - _box->addButton(langFactory(lng_cancel), [this] { + _box->addButton(tr::lng_cancel(), [this] { _box->closeBox(); }); subscribeToMigration(); diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index d640274aac..19d7c71efe 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -345,8 +345,8 @@ void EditPeerPermissionsBox::prepare() { addBannedButtons(inner); _value = getRestrictions; - _save = addButton(langFactory(lng_settings_save)); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + _save = addButton(tr::lng_settings_save()); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensionsToContent(st::boxWidth, inner); } diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp index de0f936c8f..11ea635fbb 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_type_box.cpp @@ -733,7 +733,7 @@ void EditPeerTypeBox::prepare() { setTitle(controller->getTitle()); if (!controller->isInviteLink() && _savedCallback.has_value()) { - addButton(langFactory(lng_settings_save), [=] { + addButton(tr::lng_settings_save(), [=] { const auto v = controller->getPrivacy(); if (!controller->isAllowSave() && (v == Privacy::Public)) { controller->setFocusUsername(); @@ -749,7 +749,7 @@ void EditPeerTypeBox::prepare() { }); } addButton( - langFactory(controller->isInviteLink() ? lng_close : lng_cancel), + controller->isInviteLink() ? tr::lng_close() : tr::lng_cancel(), [=] { closeBox(); }); setDimensionsToContent(st::boxWideWidth, content); diff --git a/Telegram/SourceFiles/boxes/photo_crop_box.cpp b/Telegram/SourceFiles/boxes/photo_crop_box.cpp index d4ae20f824..d2922db5a4 100644 --- a/Telegram/SourceFiles/boxes/photo_crop_box.cpp +++ b/Telegram/SourceFiles/boxes/photo_crop_box.cpp @@ -20,8 +20,8 @@ PhotoCropBox::PhotoCropBox( } void PhotoCropBox::prepare() { - addButton(langFactory(lng_settings_save), [this] { sendPhoto(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_settings_save(), [this] { sendPhoto(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); int32 s = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(); _thumb = App::pixmapFromImageInPlace(_img.scaled(s * cIntRetinaFactor(), s * cIntRetinaFactor(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); diff --git a/Telegram/SourceFiles/boxes/rate_call_box.cpp b/Telegram/SourceFiles/boxes/rate_call_box.cpp index f0c2f8d9b8..ea059dbcf9 100644 --- a/Telegram/SourceFiles/boxes/rate_call_box.cpp +++ b/Telegram/SourceFiles/boxes/rate_call_box.cpp @@ -32,7 +32,7 @@ RateCallBox::RateCallBox(QWidget*, uint64 callId, uint64 callAccessHash) void RateCallBox::prepare() { setTitle(tr::lng_call_rate_label()); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); for (auto i = 0; i < kMaxRating; ++i) { _stars.push_back(object_ptr(this, st::callRatingStar)); @@ -62,8 +62,8 @@ void RateCallBox::ratingChanged(int value) { Expects(value > 0 && value <= kMaxRating); if (!_rating) { clearButtons(); - addButton(langFactory(lng_send_button), [this] { send(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_send_button(), [this] { send(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); } _rating = value; diff --git a/Telegram/SourceFiles/boxes/report_box.cpp b/Telegram/SourceFiles/boxes/report_box.cpp index 0c4108c912..fb20282ef5 100644 --- a/Telegram/SourceFiles/boxes/report_box.cpp +++ b/Telegram/SourceFiles/boxes/report_box.cpp @@ -46,8 +46,8 @@ void ReportBox::prepare() { } }()); - addButton(langFactory(lng_report_button), [=] { report(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_report_button(), [=] { report(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); _reasonGroup = std::make_shared>( Reason::Spam); diff --git a/Telegram/SourceFiles/boxes/self_destruction_box.cpp b/Telegram/SourceFiles/boxes/self_destruction_box.cpp index d4a31639bd..633467ebf4 100644 --- a/Telegram/SourceFiles/boxes/self_destruction_box.cpp +++ b/Telegram/SourceFiles/boxes/self_destruction_box.cpp @@ -72,11 +72,11 @@ void SelfDestructionBox::showContent() { showChildren(); clearButtons(); - addButton(langFactory(lng_settings_save), [=] { + addButton(tr::lng_settings_save(), [=] { Auth().api().saveSelfDestruct(_ttlGroup->value()); closeBox(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } QString SelfDestructionBox::DaysLabel(int days) { @@ -102,7 +102,7 @@ void SelfDestructionBox::prepare() { setDimensions(st::boxWidth, boxHeight); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); if (_loading) { _loading->moveToLeft( diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 69472da367..fe9c6cce01 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -1441,8 +1441,8 @@ void SendFilesBox::setupShadows( } void SendFilesBox::prepare() { - _send = addButton(langFactory(lng_send_button), [=] { send(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + _send = addButton(tr::lng_send_button(), [=] { send(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); initSendWay(); setupCaption(); preparePreview(); diff --git a/Telegram/SourceFiles/boxes/sessions_box.cpp b/Telegram/SourceFiles/boxes/sessions_box.cpp index 410865a3cf..b2cb0b613e 100644 --- a/Telegram/SourceFiles/boxes/sessions_box.cpp +++ b/Telegram/SourceFiles/boxes/sessions_box.cpp @@ -82,7 +82,7 @@ SessionsBox::SessionsBox(QWidget*) void SessionsBox::prepare() { setTitle(tr::lng_sessions_other_header()); - addButton(langFactory(lng_close), [=] { closeBox(); }); + addButton(tr::lng_close(), [=] { closeBox(); }); setDimensions(st::boxWideWidth, st::sessionsHeight); diff --git a/Telegram/SourceFiles/boxes/share_box.cpp b/Telegram/SourceFiles/boxes/share_box.cpp index 50f3f014d7..e3bed8befe 100644 --- a/Telegram/SourceFiles/boxes/share_box.cpp +++ b/Telegram/SourceFiles/boxes/share_box.cpp @@ -400,11 +400,11 @@ void ShareBox::keyPressEvent(QKeyEvent *e) { void ShareBox::createButtons() { clearButtons(); if (_hasSelected) { - addButton(langFactory(lng_share_confirm), [=] { submit(); }); + addButton(tr::lng_share_confirm(), [=] { submit(); }); } else if (_copyCallback) { - addButton(langFactory(lng_share_copy_link), [=] { copyLink(); }); + addButton(tr::lng_share_copy_link(), [=] { copyLink(); }); } - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } void ShareBox::applyFilterUpdate(const QString &query) { diff --git a/Telegram/SourceFiles/boxes/single_choice_box.cpp b/Telegram/SourceFiles/boxes/single_choice_box.cpp index 90c69805ae..8844a1780a 100644 --- a/Telegram/SourceFiles/boxes/single_choice_box.cpp +++ b/Telegram/SourceFiles/boxes/single_choice_box.cpp @@ -30,7 +30,7 @@ SingleChoiceBox::SingleChoiceBox( void SingleChoiceBox::prepare() { setTitle(std::move(_title)); - addButton(langFactory(lng_box_ok), [=] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); const auto group = std::make_shared(_initialSelection); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 8779ccfd15..2647162656 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -157,16 +157,16 @@ void StickerSetBox::updateButtons() { clearButtons(); if (_inner->loaded()) { if (_inner->notInstalled()) { - addButton(langFactory(lng_stickers_add_pack), [=] { addStickers(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_stickers_add_pack(), [=] { addStickers(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } else if (_inner->official()) { - addButton(langFactory(lng_about_done), [=] { closeBox(); }); + addButton(tr::lng_about_done(), [=] { closeBox(); }); } else { - addButton(langFactory(lng_stickers_share_pack), [=] { shareStickers(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_stickers_share_pack(), [=] { shareStickers(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } } else { - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } update(); } diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 351f17e102..fd1e15938e 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -291,11 +291,15 @@ void StickersBox::prepare() { } if (_megagroupSet) { - addButton(langFactory(lng_settings_save), [this] { _installed.widget()->saveGroupSet(); closeBox(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton( + tr::lng_settings_save(), + [=] { _installed.widget()->saveGroupSet(); closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } else { const auto close = _section == Section::Attached; - addButton(langFactory(close ? lng_close : lng_about_done), [this] { closeBox(); }); + addButton( + close ? tr::lng_close() : tr::lng_about_done(), + [=] { closeBox(); }); } if (_section == Section::Installed) { diff --git a/Telegram/SourceFiles/boxes/url_auth_box.cpp b/Telegram/SourceFiles/boxes/url_auth_box.cpp index bc2730b5b2..ac82c2ba18 100644 --- a/Telegram/SourceFiles/boxes/url_auth_box.cpp +++ b/Telegram/SourceFiles/boxes/url_auth_box.cpp @@ -135,8 +135,8 @@ UrlAuthBox::UrlAuthBox( void UrlAuthBox::prepare() { setDimensionsToContent(st::boxWidth, _content); - addButton(langFactory(lng_open_link), [=] { _callback(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_open_link(), [=] { _callback(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } not_null UrlAuthBox::setupContent( diff --git a/Telegram/SourceFiles/boxes/username_box.cpp b/Telegram/SourceFiles/boxes/username_box.cpp index 5c80256f44..4901ee250e 100644 --- a/Telegram/SourceFiles/boxes/username_box.cpp +++ b/Telegram/SourceFiles/boxes/username_box.cpp @@ -44,8 +44,8 @@ void UsernameBox::prepare() { setTitle(tr::lng_username_title()); - addButton(langFactory(lng_settings_save), [=] { save(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); connect(_username, &Ui::MaskedInputField::changed, [=] { changed(); }); connect(_username, &Ui::MaskedInputField::submitted, [=] { save(); }); diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 9f727de89c..0da971ee88 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -50,7 +50,7 @@ DebugInfoBox::DebugInfoBox(QWidget*, base::weak_ptr call) void DebugInfoBox::prepare() { setTitle(rpl::single(qsl("Call Debug"))); - addButton(langFactory(lng_close), [this] { closeBox(); }); + addButton(tr::lng_close(), [this] { closeBox(); }); _text = setInnerWidget( object_ptr>( this, diff --git a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp index 40a96e0ff1..0adfbc9aa1 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_sets_manager.cpp @@ -659,7 +659,7 @@ void ManageSetsBox::prepare() { setTitle(tr::lng_emoji_manage_sets()); - addButton(langFactory(lng_close), [=] { closeBox(); }); + addButton(tr::lng_close(), [=] { closeBox(); }); setDimensionsToContent(st::boxWidth, inner); } diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index efb90cbd84..af60a8f9e0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -161,8 +161,8 @@ void EditLinkBox::prepare() { ? tr::lng_formatting_link_create_title() : tr::lng_formatting_link_edit_title()); - addButton(langFactory(lng_formatting_link_create), submit); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_formatting_link_create(), submit); + addButton(tr::lng_cancel(), [=] { closeBox(); }); content->resizeToWidth(st::boxWidth); content->moveToLeft(0, 0); diff --git a/Telegram/SourceFiles/codegen/lang/generator.cpp b/Telegram/SourceFiles/codegen/lang/generator.cpp index de9fb85b7b..1c6d96a132 100644 --- a/Telegram/SourceFiles/codegen/lang/generator.cpp +++ b/Telegram/SourceFiles/codegen/lang/generator.cpp @@ -188,7 +188,6 @@ ResultString " << (isPlural ? entry.keyBase : key) << "__generic(" << genericPar return result;\n\ }\n\ inline constexpr auto " << (isPlural ? entry.keyBase : key) << " = &" << (isPlural ? entry.keyBase : key) << "__generic;\n\ -inline constexpr auto " << (isPlural ? entry.keyBase : key) << "__rich = &" << (isPlural ? entry.keyBase : key) << "__generic;\n\ \n"; } } diff --git a/Telegram/SourceFiles/data/data_document.cpp b/Telegram/SourceFiles/data/data_document.cpp index 55eb72f15c..4877e4da3e 100644 --- a/Telegram/SourceFiles/data/data_document.cpp +++ b/Telegram/SourceFiles/data/data_document.cpp @@ -97,11 +97,12 @@ void LaunchWithWarning(const QString &name, HistoryItem *item) { File::Launch(name); }; Ui::show(Box( - rpl::single(lng_launch_exe_warning__rich( + tr::lng_launch_exe_warning( lt_extension, - Ui::Text::Bold(extension))), + rpl::single(Ui::Text::Bold(extension)), + Ui::Text::WithEntities), lang(lng_launch_exe_dont_ask), - lang(lng_launch_exe_sure), + tr::lng_launch_exe_sure(), callback)); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp index 421503c7c7..4455636449 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_search_from_controllers.cpp @@ -39,7 +39,7 @@ void ShowSearchFromBox( if (auto controller = createController()) { auto subscription = std::make_shared(); auto box = Ui::show(Box(std::move(controller), [subscription](not_null box) { - box->addButton(langFactory(lng_cancel), [box, subscription] { + box->addButton(tr::lng_cancel(), [box, subscription] { box->closeBox(); }); }), LayerOption::KeepOther); diff --git a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp index 80e45a8751..fdd4d60078 100644 --- a/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp +++ b/Telegram/SourceFiles/export/view/export_view_panel_controller.cpp @@ -43,11 +43,11 @@ SuggestBox::SuggestBox(QWidget*) { void SuggestBox::prepare() { setTitle(tr::lng_export_suggest_title()); - addButton(langFactory(lng_box_ok), [=] { + addButton(tr::lng_box_ok(), [=] { closeBox(); Auth().data().startExport(Local::ReadExportSettings().singlePeer); }); - addButton(langFactory(lng_export_suggest_cancel), [=] { closeBox(); }); + addButton(tr::lng_export_suggest_cancel(), [=] { closeBox(); }); setCloseByOutsideClick(false); const auto content = Ui::CreateChild( diff --git a/Telegram/SourceFiles/export/view/export_view_progress.cpp b/Telegram/SourceFiles/export/view/export_view_progress.cpp index 9a95daf066..14a034f599 100644 --- a/Telegram/SourceFiles/export/view/export_view_progress.cpp +++ b/Telegram/SourceFiles/export/view/export_view_progress.cpp @@ -257,7 +257,7 @@ ProgressWidget::ProgressWidget( _cancel = base::make_unique_q( this, - langFactory(lng_export_stop), + tr::lng_export_stop(), st::exportCancelButton); setupBottomButton(_cancel.get()); } @@ -310,7 +310,7 @@ void ProgressWidget::showDone() { _about->setText(lang(lng_export_about_done)); _done = base::make_unique_q( this, - langFactory(lng_export_done), + tr::lng_export_done(), st::exportDoneButton); const auto desired = std::min( st::exportDoneButton.font->width(lang(lng_export_done).toUpper()) diff --git a/Telegram/SourceFiles/export/view/export_view_settings.cpp b/Telegram/SourceFiles/export/view/export_view_settings.cpp index 228c2585f2..f70001a436 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.cpp +++ b/Telegram/SourceFiles/export/view/export_view_settings.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/padding_wrap.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/fade_wrap.h" +#include "ui/text/text_utilities.h" #include "platform/platform_specific.h" #include "core/file_utilities.h" #include "boxes/calendar_box.h" @@ -246,30 +247,24 @@ void SettingsWidget::setupPathAndFormat( void SettingsWidget::addLocationLabel( not_null container) { #ifndef OS_MAC_STORE - auto pathLabel = value() | rpl::map([](const Settings &data) { + auto pathLink = value() | rpl::map([](const Settings &data) { return data.path; }) | rpl::distinct_until_changed( ) | rpl::map([](const QString &path) { const auto text = IsDefaultPath(path) ? QString("Downloads/Telegram Desktop") : path; - auto pathLink = TextWithEntities{ + return Ui::Text::Link( QDir::toNativeSeparators(text), - EntitiesInText() - }; - pathLink.entities.push_back({ - EntityType::CustomUrl, - 0, - text.size(), - QString("internal:edit_export_path") }); - return lng_export_option_location__rich( - lt_path, - pathLink); + QString("internal:edit_export_path")); }); const auto label = container->add( object_ptr( container, - std::move(pathLabel), + tr::lng_export_option_location( + lt_path, + std::move(pathLink), + Ui::Text::WithEntities), st::exportLocationLabel), st::exportLocationPadding); label->setClickHandlerFilter([=](auto&&...) { @@ -281,40 +276,40 @@ void SettingsWidget::addLocationLabel( void SettingsWidget::addLimitsLabel( not_null container) { - auto pathLabel = value() | rpl::map([](const Settings &data) { - return std::make_tuple(data.singlePeerFrom, data.singlePeerTill); + auto fromLink = value() | rpl::map([](const Settings &data) { + return data.singlePeerFrom; }) | rpl::distinct_until_changed( - ) | rpl::map([](TimeId from, TimeId till) { - const auto begin = from - ? langDayOfMonthFull(ParseDateTime(from).date()) - : lang(lng_export_beginning); - const auto end = till - ? langDayOfMonthFull(ParseDateTime(till).date()) - : lang(lng_export_end); - auto fromLink = TextWithEntities{ begin }; - fromLink.entities.push_back({ - EntityType::CustomUrl, - 0, - begin.size(), - QString("internal:edit_from") }); - auto tillLink = TextWithEntities{ end }; - tillLink.entities.push_back({ - EntityType::CustomUrl, - 0, - end.size(), - QString("internal:edit_till") }); - return lng_export_limits__rich( - lt_from, - fromLink, - lt_till, - tillLink); - }) | rpl::after_next([=] { + ) | rpl::map([](TimeId from) { + return (from + ? rpl::single(langDayOfMonthFull(ParseDateTime(from).date())) + : tr::lng_export_beginning() + ) | Ui::Text::ToLink(qsl("internal:edit_from")); + }) | rpl::flatten_latest(); + + auto tillLink = value() | rpl::map([](const Settings &data) { + return data.singlePeerTill; + }) | rpl::distinct_until_changed( + ) | rpl::map([](TimeId till) { + return (till + ? rpl::single(langDayOfMonthFull(ParseDateTime(till).date())) + : tr::lng_export_end() + ) | Ui::Text::ToLink(qsl("internal:edit_till")); + }) | rpl::flatten_latest(); + + auto datesText = tr::lng_export_limits( + lt_from, + std::move(fromLink), + lt_till, + std::move(tillLink), + Ui::Text::WithEntities + ) | rpl::after_next([=] { container->resizeToWidth(container->width()); }); + const auto label = container->add( object_ptr( container, - std::move(pathLabel), + std::move(datesText), st::exportLocationLabel), st::exportLimitsPadding); label->setClickHandlerFilter([=]( @@ -331,7 +326,7 @@ void SettingsWidget::addLimitsLabel( readData().singlePeerFrom, 0, readData().singlePeerTill, - lng_export_from_beginning, + tr::lng_export_from_beginning(), done); } else if (url == qstr("internal:edit_till")) { const auto done = [=](TimeId limit) { @@ -343,7 +338,7 @@ void SettingsWidget::addLimitsLabel( readData().singlePeerTill, readData().singlePeerFrom, 0, - lng_export_till_end, + tr::lng_export_till_end(), done); } else { Unexpected("Click handler URL in export limits edit."); @@ -357,7 +352,7 @@ void SettingsWidget::editDateLimit( TimeId current, TimeId min, TimeId max, - LangKey resetLabel, + rpl::producer resetLabel, Fn done) { Expects(_showBoxCallback != nullptr); @@ -377,7 +372,7 @@ void SettingsWidget::editDateLimit( box->setMinDate(min ? ParseDateTime(min).date() : QDate(2013, 8, 1)); // Telegram was launched in August 2013 :) - box->addLeftButton(langFactory(resetLabel), crl::guard(this, [=] { + box->addLeftButton(std::move(resetLabel), crl::guard(this, [=] { done(0); if (const auto weak = shared->data()) { weak->closeBox(); @@ -632,7 +627,7 @@ void SettingsWidget::refreshButtons( const auto start = canStart ? Ui::CreateChild( container.get(), - langFactory(lng_export_start), + tr::lng_export_start(), st::defaultBoxButton) : nullptr; if (start) { @@ -652,7 +647,7 @@ void SettingsWidget::refreshButtons( const auto cancel = Ui::CreateChild( container.get(), - langFactory(lng_cancel), + tr::lng_cancel(), st::defaultBoxButton); cancel->show(); _cancelClicks = cancel->clicks( diff --git a/Telegram/SourceFiles/export/view/export_view_settings.h b/Telegram/SourceFiles/export/view/export_view_settings.h index 7754f1ecd9..d3656ff57a 100644 --- a/Telegram/SourceFiles/export/view/export_view_settings.h +++ b/Telegram/SourceFiles/export/view/export_view_settings.h @@ -88,7 +88,7 @@ private: TimeId current, TimeId min, TimeId max, - LangKey resetLabel, + rpl::producer resetLabel, Fn done); const Settings &readData() const; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp index b87a23b9a5..52d60339b4 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_filter.cpp @@ -396,13 +396,13 @@ void FilterBox::prepare() { void FilterBox::refreshButtons() { clearButtons(); if (_inner->canSave()) { - addButton(langFactory(lng_settings_save), [this] { + addButton(tr::lng_settings_save(), [this] { if (_saveCallback) { _saveCallback(_inner->filter()); } }); } - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); } void FilterBox::resizeToContent() { diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp index 44af5c4374..ffd8798d13 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_item.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" #include "lang/lang_keys.h" +#include "ui/text/text_utilities.h" #include "boxes/sticker_set_box.h" #include "core/application.h" #include "auth_session.h" @@ -134,7 +135,7 @@ TextWithEntities GenerateAdminChangeText( auto newFlags = newRights ? newRights->c_chatAdminRights().vflags.v : MTPDchatAdminRights::Flags(0); auto prevFlags = prevRights ? prevRights->c_chatAdminRights().vflags.v : MTPDchatAdminRights::Flags(0); - auto result = lng_admin_log_promoted__rich(lt_user, user); + auto result = tr::lng_admin_log_promoted(tr::now, lt_user, user, Ui::Text::WithEntities); auto useInviteLinkPhrase = channel->isMegagroup() && channel->anyoneCanAddMembers(); auto invitePhrase = (useInviteLinkPhrase ? lng_admin_log_admin_invite_link : lng_admin_log_admin_invite_users); @@ -202,18 +203,21 @@ TextWithEntities GenerateBannedChangeText( auto newUntil = newRights ? newRights->c_chatBannedRights().vuntil_date.v : TimeId(0); auto indefinitely = ChannelData::IsRestrictedForever(newUntil); if (newFlags & Flag::f_view_messages) { - return lng_admin_log_banned__rich(lt_user, user); + return tr::lng_admin_log_banned(tr::now, lt_user, user, Ui::Text::WithEntities); } auto untilText = indefinitely - ? lang(lng_admin_log_restricted_forever) - : lng_admin_log_restricted_until( + ? tr::lng_admin_log_restricted_forever(tr::now) + : tr::lng_admin_log_restricted_until( + tr::now, lt_date, langDateTime(ParseDateTime(newUntil))); - auto result = lng_admin_log_restricted__rich( + auto result = tr::lng_admin_log_restricted( + tr::now, lt_user, user, lt_until, - TextWithEntities { untilText }); + TextWithEntities { untilText }, + Ui::Text::WithEntities); const auto changes = GenerateBannedChangeText(newRights, prevRights); if (!changes.isEmpty()) { result.text.append('\n' + changes); @@ -242,7 +246,13 @@ auto GenerateUserString(MTPint userId) { EntityType::Mention, 0, mention.text.size() }); - return lng_admin_log_user_with_username__rich(lt_name, name, lt_mention, mention); + return tr::lng_admin_log_user_with_username( + tr::now, + lt_name, + name, + lt_mention, + mention, + Ui::Text::WithEntities); } auto GenerateParticipantChangeTextInner( @@ -252,9 +262,11 @@ auto GenerateParticipantChangeTextInner( const auto oldType = oldParticipant ? oldParticipant->type() : 0; return participant.match([&](const MTPDchannelParticipantCreator &data) { // No valid string here :( - return lng_admin_log_invited__rich( + return tr::lng_admin_log_invited( + tr::now, lt_user, - GenerateUserString(data.vuser_id)); + GenerateUserString(data.vuser_id), + Ui::Text::WithEntities); }, [&](const MTPDchannelParticipantAdmin &data) { auto user = GenerateUserString(data.vuser_id); return GenerateAdminChangeText( @@ -286,7 +298,7 @@ auto GenerateParticipantChangeTextInner( nullptr, &oldParticipant->c_channelParticipantBanned().vbanned_rights); } - return lng_admin_log_invited__rich(lt_user, user); + return tr::lng_admin_log_invited(tr::now, lt_user, user, Ui::Text::WithEntities); }); } diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp index c1ec04d631..9129712ef0 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_section.cpp @@ -108,7 +108,7 @@ FixedBar::FixedBar( , _backButton(this, lang(lng_admin_log_title_all)) , _search(this, st::topBarSearch) , _cancel(this, st::historyAdminLogCancelSearch) -, _filter(this, langFactory(lng_admin_log_filter), st::topBarButton) { +, _filter(this, tr::lng_admin_log_filter(), st::topBarButton) { _backButton->moveToLeft(0, 0); _backButton->setClickedCallback([=] { goBack(); }); _filter->setClickedCallback([=] { showFilterSignal.notify(); }); diff --git a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp index 23e18a013d..05821cb379 100644 --- a/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_top_bar_widget.cpp @@ -49,9 +49,9 @@ TopBarWidget::TopBarWidget( not_null controller) : RpWidget(parent) , _controller(controller) -, _clear(this, langFactory(lng_selected_clear), st::topBarClearButton) -, _forward(this, langFactory(lng_selected_forward), st::defaultActiveButton) -, _delete(this, langFactory(lng_selected_delete), st::defaultActiveButton) +, _clear(this, tr::lng_selected_clear(), st::topBarClearButton) +, _forward(this, tr::lng_selected_forward(), st::defaultActiveButton) +, _delete(this, tr::lng_selected_delete(), st::defaultActiveButton) , _back(this, st::historyTopBarBack) , _call(this, st::topBarCall) , _search(this, st::topBarSearch) diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp index d86c459db9..4e76e2a3f9 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.cpp @@ -243,8 +243,7 @@ object_ptr InnerWidget::setupList( void InnerWidget::peerListSetTitle(rpl::producer title) { } -void InnerWidget::peerListSetAdditionalTitle( - Fn title) { +void InnerWidget::peerListSetAdditionalTitle(rpl::producer title) { } bool InnerWidget::peerListIsRowSelected(not_null peer) { diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h index 37afd51c48..07b57eda49 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_inner_widget.h @@ -49,8 +49,7 @@ private: // PeerListContentDelegate interface. void peerListSetTitle(rpl::producer title) override; - void peerListSetAdditionalTitle( - Fn title) override; + void peerListSetAdditionalTitle(rpl::producer title) override; bool peerListIsRowSelected(not_null peer) override; int peerListSelectedRowsCount() override; std::vector> peerListCollectSelectedRows() override; diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.cpp b/Telegram/SourceFiles/info/profile/info_profile_members.cpp index a5703ac526..30077198f3 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_members.cpp @@ -412,8 +412,7 @@ void Members::visibleTopBottomUpdated( void Members::peerListSetTitle(rpl::producer title) { } -void Members::peerListSetAdditionalTitle( - Fn title) { +void Members::peerListSetAdditionalTitle(rpl::producer title) { } bool Members::peerListIsRowSelected(not_null peer) { diff --git a/Telegram/SourceFiles/info/profile/info_profile_members.h b/Telegram/SourceFiles/info/profile/info_profile_members.h index 96469fc3cc..126efac283 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_members.h +++ b/Telegram/SourceFiles/info/profile/info_profile_members.h @@ -60,8 +60,7 @@ private: // PeerListContentDelegate interface. void peerListSetTitle(rpl::producer title) override; - void peerListSetAdditionalTitle( - Fn title) override; + void peerListSetAdditionalTitle(rpl::producer title) override; bool peerListIsRowSelected(not_null peer) override; int peerListSelectedRowsCount() override; std::vector> peerListCollectSelectedRows() override; diff --git a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp index 51642bdbb3..b4bb5c6a2e 100644 --- a/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_results_widget.cpp @@ -428,15 +428,14 @@ void Inner::refreshSwitchPmButton(const CacheEntry *entry) { _switchPmStartToken.clear(); } else { if (!_switchPmButton) { - _switchPmButton.create(this, Fn(), st::switchPmButton); + _switchPmButton.create(this, nullptr, st::switchPmButton); _switchPmButton->show(); _switchPmButton->setTextTransform(Ui::RoundButton::TextTransform::NoTransform); connect(_switchPmButton, SIGNAL(clicked()), this, SLOT(onSwitchPm())); } - auto text = entry->switchPmText; - _switchPmButton->setText([text] { return text; }); // doesn't perform text.toUpper() + _switchPmButton->setText(rpl::single(entry->switchPmText)); _switchPmStartToken = entry->switchPmStartToken; - auto buttonTop = st::stickerPanPadding; + const auto buttonTop = st::stickerPanPadding; _switchPmButton->move(st::inlineResultsLeft - st::buttonRadius, buttonTop); if (isRestrictedView()) { _switchPmButton->hide(); diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index 6182e47e10..3a7dafb7f1 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -91,7 +91,7 @@ CodeWidget::CodeWidget(QWidget *parent, Widget::Data *data) : Step(parent, data) _code->setDigitsCountMax(getData()->codeLength); setErrorBelowLink(true); - setTitleText([text = App::formatPhone(getData()->phone)] { return text; }); + setTitleText(rpl::single(App::formatPhone(getData()->phone))); updateDescText(); } @@ -103,10 +103,9 @@ void CodeWidget::refreshLang() { void CodeWidget::updateDescText() { const auto byTelegram = getData()->codeByTelegram; - setDescriptionText([=] { - return Ui::Text::RichLangValue( - lang(byTelegram ? lng_code_from_telegram : lng_code_desc)); - }); + setDescriptionText( + (byTelegram ? tr::lng_code_from_telegram : tr::lng_code_desc)( + Ui::Text::RichLangValue)); if (getData()->codeByTelegram) { _noTelegramCode->show(); _callTimer->stop(); @@ -155,9 +154,9 @@ void CodeWidget::updateControlsGeometry() { _callLabel->moveToLeft(contentLeft() + st::buttonRadius, linkTop); } -void CodeWidget::showCodeError(Fn textFactory) { - if (textFactory) _code->showError(); - showError(std::move(textFactory)); +void CodeWidget::showCodeError(rpl::producer text) { + _code->showError(); + showError(std::move(text)); } void CodeWidget::setInnerFocus() { @@ -217,7 +216,7 @@ void CodeWidget::codeSubmitDone(const MTPauth_Authorization &result) { _sentRequest = 0; auto &d = result.c_auth_authorization(); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? - showCodeError(&Lang::Hard::ServerError); + showCodeError(rpl::single(Lang::Hard::ServerError())); return; } cSetLoggedPhoneNumber(getData()->phone); @@ -228,7 +227,7 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); _sentRequest = 0; - showCodeError(langFactory(lng_flood_error)); + showCodeError(tr::lng_flood_error()); return true; } if (MTP::isDefaultHandledError(error)) return false; @@ -242,7 +241,7 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) { goBack(); return true; } else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) { - showCodeError(langFactory(lng_bad_code)); + showCodeError(tr::lng_bad_code()); return true; } else if (err == qstr("PHONE_NUMBER_UNOCCUPIED")) { // success, need to signUp getData()->code = _sentCode; @@ -255,10 +254,9 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) { return true; } if (Logs::DebugEnabled()) { // internal server error - auto text = err + ": " + error.description(); - showCodeError([text] { return text; }); + showCodeError(rpl::single(err + ": " + error.description())); } else { - showCodeError(&Lang::Hard::ServerError); + showCodeError(rpl::single(Lang::Hard::ServerError())); } return false; } @@ -358,7 +356,7 @@ void CodeWidget::noTelegramCodeDone(const MTPauth_SentCode &result) { _noTelegramCodeRequestId = 0; if (result.type() != mtpc_auth_sentCode) { - showCodeError(&Lang::Hard::ServerError); + showCodeError(rpl::single(Lang::Hard::ServerError())); return; } @@ -379,7 +377,7 @@ void CodeWidget::noTelegramCodeDone(const MTPauth_SentCode &result) { bool CodeWidget::noTelegramCodeFail(const RPCError &error) { if (MTP::isFloodError(error)) { _noTelegramCodeRequestId = 0; - showCodeError(langFactory(lng_flood_error)); + showCodeError(tr::lng_flood_error()); return true; } if (MTP::isDefaultHandledError(error)) { @@ -388,10 +386,9 @@ bool CodeWidget::noTelegramCodeFail(const RPCError &error) { _noTelegramCodeRequestId = 0; if (Logs::DebugEnabled()) { // internal server error - auto text = error.type() + ": " + error.description(); - showCodeError([text] { return text; }); + showCodeError(rpl::single(error.type() + ": " + error.description())); } else { - showCodeError(&Lang::Hard::ServerError); + showCodeError(rpl::single(Lang::Hard::ServerError())); } return false; } diff --git a/Telegram/SourceFiles/intro/introcode.h b/Telegram/SourceFiles/intro/introcode.h index 7e4d349029..2b8d99d74a 100644 --- a/Telegram/SourceFiles/intro/introcode.h +++ b/Telegram/SourceFiles/intro/introcode.h @@ -69,7 +69,7 @@ private: void codeSubmitDone(const MTPauth_Authorization &result); bool codeSubmitFail(const RPCError &error); - void showCodeError(Fn textFactory); + void showCodeError(rpl::producer text); void callDone(const MTPauth_SentCode &v); void gotPassword(const MTPaccount_Password &result); diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index 33f0e42de7..40de7214da 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -44,8 +44,8 @@ PhoneWidget::PhoneWidget(QWidget *parent, Widget::Data *data) : Step(parent, dat connect(_code, SIGNAL(changed()), this, SLOT(onInputChange())); connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest())); - setTitleText(langFactory(lng_phone_title)); - setDescriptionText(langFactory(lng_phone_desc)); + setTitleText(tr::lng_phone_title()); + setDescriptionText(tr::lng_phone_desc()); subscribe(getData()->updated, [this] { countryChanged(); }); setErrorCentered(true); @@ -72,9 +72,9 @@ void PhoneWidget::updateSignupGeometry() { } } -void PhoneWidget::showPhoneError(Fn textFactory) { +void PhoneWidget::showPhoneError(rpl::producer text) { _phone->showError(); - showError(std::move(textFactory)); + showError(std::move(text)); } void PhoneWidget::hidePhoneError() { @@ -101,7 +101,7 @@ void PhoneWidget::submit() { const auto phone = fullNumber(); if (!AllowPhoneAttempt(phone)) { - showPhoneError(langFactory(lng_bad_phone)); + showPhoneError(tr::lng_bad_phone()); _phone->setFocus(); return; } @@ -146,7 +146,7 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) { _sentRequest = 0; if (result.type() != mtpc_auth_sentCode) { - showPhoneError(&Lang::Hard::ServerError); + showPhoneError(rpl::single(Lang::Hard::ServerError())); return; } @@ -169,7 +169,7 @@ bool PhoneWidget::phoneSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); _sentRequest = 0; - showPhoneError(langFactory(lng_flood_error)); + showPhoneError(tr::lng_flood_error()); return true; } if (MTP::isDefaultHandledError(error)) return false; @@ -181,17 +181,16 @@ bool PhoneWidget::phoneSubmitFail(const RPCError &error) { Ui::show(Box(lang(lng_error_phone_flood))); return true; } else if (err == qstr("PHONE_NUMBER_INVALID")) { // show error - showPhoneError(langFactory(lng_bad_phone)); + showPhoneError(tr::lng_bad_phone()); return true; } else if (err == qstr("PHONE_NUMBER_BANNED")) { ShowPhoneBannedError(_sentPhone); return true; } if (Logs::DebugEnabled()) { // internal server error - auto text = err + ": " + error.description(); - showPhoneError([text] { return text; }); + showPhoneError(rpl::single(err + ": " + error.description())); } else { - showPhoneError(&Lang::Hard::ServerError); + showPhoneError(rpl::single(Lang::Hard::ServerError())); } return false; } diff --git a/Telegram/SourceFiles/intro/introphone.h b/Telegram/SourceFiles/intro/introphone.h index 3fefac3065..6dd6598b1e 100644 --- a/Telegram/SourceFiles/intro/introphone.h +++ b/Telegram/SourceFiles/intro/introphone.h @@ -54,7 +54,7 @@ private: QString fullNumber() const; void stopCheck(); - void showPhoneError(Fn textFactory); + void showPhoneError(rpl::producer text); void hidePhoneError(); bool _changed = false; diff --git a/Telegram/SourceFiles/intro/intropwdcheck.cpp b/Telegram/SourceFiles/intro/intropwdcheck.cpp index 41605c1199..03bd3691a1 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.cpp +++ b/Telegram/SourceFiles/intro/intropwdcheck.cpp @@ -45,7 +45,7 @@ PwdCheckWidget::PwdCheckWidget( connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange())); connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange())); - setTitleText(langFactory(lng_signin_title)); + setTitleText(tr::lng_signin_title()); updateDescriptionText(); setErrorBelowLink(true); @@ -130,7 +130,7 @@ void PwdCheckWidget::pwdSubmitDone(bool recover, const MTPauth_Authorization &re } auto &d = result.c_auth_authorization(); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); return; } finish(d.vuser); @@ -140,7 +140,7 @@ void PwdCheckWidget::pwdSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { _sentRequest = 0; stopCheck(); - showError(langFactory(lng_flood_error)); + showError(tr::lng_flood_error()); _pwdField->showError(); return; } @@ -150,7 +150,7 @@ void PwdCheckWidget::pwdSubmitFail(const RPCError &error) { const auto &type = error.type(); if (type == qstr("PASSWORD_HASH_INVALID") || type == qstr("SRP_PASSWORD_CHANGED")) { - showError(langFactory(lng_signin_bad_password)); + showError(tr::lng_signin_bad_password()); _pwdField->selectAll(); _pwdField->showError(); } else if (type == qstr("PASSWORD_EMPTY") @@ -160,10 +160,9 @@ void PwdCheckWidget::pwdSubmitFail(const RPCError &error) { handleSrpIdInvalid(); } else { if (Logs::DebugEnabled()) { // internal server error - const auto text = type + ": " + error.description(); - showError([=] { return text; }); + showError(rpl::single(type + ": " + error.description())); } else { - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); } _pwdField->setFocus(); } @@ -174,7 +173,7 @@ void PwdCheckWidget::handleSrpIdInvalid() { if (_lastSrpIdInvalidTime > 0 && now - _lastSrpIdInvalidTime < Core::kHandleSrpIdInvalidTimeout) { _request.id = 0; - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); } else { _lastSrpIdInvalidTime = now; requestPasswordData(); @@ -223,12 +222,12 @@ void PwdCheckWidget::passwordChecked() { } void PwdCheckWidget::serverError() { - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); } void PwdCheckWidget::codeSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { - showError(langFactory(lng_flood_error)); + showError(tr::lng_flood_error()); _codeField->showError(); return; } @@ -245,15 +244,14 @@ void PwdCheckWidget::codeSubmitFail(const RPCError &error) { _emailPattern = QString(); onToPassword(); } else if (type == qstr("CODE_INVALID")) { - showError(langFactory(lng_signin_wrong_code)); + showError(tr::lng_signin_wrong_code()); _codeField->selectAll(); _codeField->showError(); } else { if (Logs::DebugEnabled()) { // internal server error - const auto text = type + ": " + error.description(); - showError([=] { return text; }); + showError(rpl::single(type + ": " + error.description())); } else { - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); } _codeField->setFocus(); } @@ -326,9 +324,9 @@ void PwdCheckWidget::showReset() { void PwdCheckWidget::updateDescriptionText() { auto pwdHidden = _pwdField->isHidden(); auto emailPattern = _emailPattern; - setDescriptionText([=] { - return pwdHidden ? lng_signin_recover_desc(lt_email, emailPattern) : lang(lng_signin_desc); - }); + setDescriptionText(pwdHidden + ? tr::lng_signin_recover_desc(lt_email, rpl::single(emailPattern)) + : tr::lng_signin_desc()); } void PwdCheckWidget::onInputChange() { @@ -379,8 +377,8 @@ void PwdCheckWidget::submit() { } } -QString PwdCheckWidget::nextButtonText() const { - return lang(lng_intro_submit); +rpl::producer PwdCheckWidget::nextButtonText() const { + return tr::lng_intro_submit(); } } // namespace Intro diff --git a/Telegram/SourceFiles/intro/intropwdcheck.h b/Telegram/SourceFiles/intro/intropwdcheck.h index 6b6581a4c6..0036d6f9a2 100644 --- a/Telegram/SourceFiles/intro/intropwdcheck.h +++ b/Telegram/SourceFiles/intro/intropwdcheck.h @@ -29,7 +29,7 @@ public: void activate() override; void cancelled() override; void submit() override; - QString nextButtonText() const override; + rpl::producer nextButtonText() const override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index b3aa28684b..4ea8605280 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -41,8 +41,8 @@ SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, d setErrorCentered(true); - setTitleText(langFactory(lng_signup_title)); - setDescriptionText(langFactory(lng_signup_desc)); + setTitleText(tr::lng_signup_title()); + setDescriptionText(tr::lng_signup_desc()); setMouseTracking(true); } @@ -122,7 +122,7 @@ void SignupWidget::nameSubmitDone(const MTPauth_Authorization &result) { stopCheck(); auto &d = result.c_auth_authorization(); if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf? - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); return; } finish(d.vuser, _photo->takeResultImage()); @@ -131,7 +131,7 @@ void SignupWidget::nameSubmitDone(const MTPauth_Authorization &result) { bool SignupWidget::nameSubmitFail(const RPCError &error) { if (MTP::isFloodError(error)) { stopCheck(); - showError(langFactory(lng_flood_error)); + showError(tr::lng_flood_error()); if (_invertOrder) { _first->setFocus(); } else { @@ -155,19 +155,18 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) { goBack(); return true; } else if (err == "FIRSTNAME_INVALID") { - showError(langFactory(lng_bad_name)); + showError(tr::lng_bad_name()); _first->setFocus(); return true; } else if (err == "LASTNAME_INVALID") { - showError(langFactory(lng_bad_name)); + showError(tr::lng_bad_name()); _last->setFocus(); return true; } if (Logs::DebugEnabled()) { // internal server error - auto text = err + ": " + error.description(); - showError([text] { return text; }); + showError(rpl::single(err + ": " + error.description())); } else { - showError(&Lang::Hard::ServerError); + showError(rpl::single(Lang::Hard::ServerError())); } if (_invertOrder) { _last->setFocus(); @@ -230,8 +229,8 @@ void SignupWidget::submit() { } } -QString SignupWidget::nextButtonText() const { - return lang(lng_intro_finish); +rpl::producer SignupWidget::nextButtonText() const { + return tr::lng_intro_finish(); } } // namespace Intro diff --git a/Telegram/SourceFiles/intro/introsignup.h b/Telegram/SourceFiles/intro/introsignup.h index 295567f3b4..ee5b9a1418 100644 --- a/Telegram/SourceFiles/intro/introsignup.h +++ b/Telegram/SourceFiles/intro/introsignup.h @@ -28,7 +28,7 @@ public: void activate() override; void cancelled() override; void submit() override; - QString nextButtonText() const override; + rpl::producer nextButtonText() const override; protected: void resizeEvent(QResizeEvent *e) override; diff --git a/Telegram/SourceFiles/intro/introstart.cpp b/Telegram/SourceFiles/intro/introstart.cpp index 9de68067c7..9822f3678a 100644 --- a/Telegram/SourceFiles/intro/introstart.cpp +++ b/Telegram/SourceFiles/intro/introstart.cpp @@ -16,8 +16,8 @@ namespace Intro { StartWidget::StartWidget(QWidget *parent, Widget::Data *data) : Step(parent, data, true) { setMouseTracking(true); - setTitleText([] { return qsl("Telegram Desktop"); }); - setDescriptionText(langFactory(lng_intro_about)); + setTitleText(rpl::single(qsl("Telegram Desktop"))); + setDescriptionText(tr::lng_intro_about()); show(); } @@ -25,8 +25,8 @@ void StartWidget::submit() { goNext(new Intro::PhoneWidget(parentWidget(), getData())); } -QString StartWidget::nextButtonText() const { - return lang(lng_start_msgs); +rpl::producer StartWidget::nextButtonText() const { + return tr::lng_start_msgs(); } } // namespace Intro diff --git a/Telegram/SourceFiles/intro/introstart.h b/Telegram/SourceFiles/intro/introstart.h index 9b2eb7d0f0..1a0489151e 100644 --- a/Telegram/SourceFiles/intro/introstart.h +++ b/Telegram/SourceFiles/intro/introstart.h @@ -22,7 +22,7 @@ public: StartWidget(QWidget *parent, Widget::Data *data); void submit() override; - QString nextButtonText() const override; + rpl::producer nextButtonText() const override; }; diff --git a/Telegram/SourceFiles/intro/introwidget.cpp b/Telegram/SourceFiles/intro/introwidget.cpp index 210e05c927..46f6759c66 100644 --- a/Telegram/SourceFiles/intro/introwidget.cpp +++ b/Telegram/SourceFiles/intro/introwidget.cpp @@ -65,9 +65,9 @@ Widget::Widget(QWidget *parent) : RpWidget(parent) this, object_ptr( this, - langFactory(lng_menu_settings), + tr::lng_menu_settings(), st::defaultBoxButton)) -, _next(this, Fn(), st::introNextButton) { +, _next(this, nullptr, st::introNextButton) { auto country = Platform::SystemCountry(); if (country.isEmpty()) { country = str_const_toString(kDefaultCountry); @@ -174,7 +174,7 @@ void Widget::onCheckUpdateStatus() { this, object_ptr( this, - langFactory(lng_menu_update), + tr::lng_menu_update(), st::defaultBoxButton)); if (!_a_show.animating()) { _update->setVisible(true); @@ -241,7 +241,7 @@ void Widget::historyMove(Direction direction) { if (_update) { _update->toggle(!stepHasCover, anim::type::normal); } - _next->setText([this] { return getStep()->nextButtonText(); }); + _next->setText(getStep()->nextButtonText()); if (_resetAccount) _resetAccount->show(anim::type::normal); if (_terms) _terms->show(anim::type::normal); if (_changeLanguage) { @@ -307,7 +307,10 @@ void Widget::appendStep(Step *step) { void Widget::showResetButton() { if (!_resetAccount) { - auto entity = object_ptr(this, langFactory(lng_signin_reset_account), st::introResetButton); + auto entity = object_ptr( + this, + tr::lng_signin_reset_account(), + st::introResetButton); _resetAccount.create(this, std::move(entity)); _resetAccount->hide(anim::type::instant); _resetAccount->entity()->setClickedCallback([this] { resetAccount(); }); @@ -325,9 +328,10 @@ void Widget::showTerms() { } else if (!_terms) { auto entity = object_ptr( this, - rpl::single(lng_terms_signup__rich( + tr::lng_terms_signup( lt_link, - Ui::Text::Link(lang(lng_terms_signup_link)))), + tr::lng_terms_signup_link() | Ui::Text::ToLink(), + Ui::Text::WithEntities), st::introTermsLabel); _terms.create(this, std::move(entity)); _terms->entity()->setClickHandlerFilter([=]( @@ -385,7 +389,7 @@ void Widget::resetAccount() { Ui::show(Box(lang(lng_signin_reset_cancelled))); } else { Ui::hideLayer(); - getStep()->showError(&Lang::Hard::ServerError); + getStep()->showError(rpl::single(Lang::Hard::ServerError())); } }).send(); }))); @@ -415,11 +419,11 @@ void Widget::showTerms(Fn callback) { const auto box = Ui::show(callback ? Box( getData()->termsLock, - langFactory(lng_terms_agree), - langFactory(lng_terms_decline)) + tr::lng_terms_agree(), + tr::lng_terms_decline()) : Box( getData()->termsLock.text, - langFactory(lng_box_ok), + tr::lng_box_ok(), nullptr)); box->setCloseByEscape(false); @@ -439,8 +443,8 @@ void Widget::showTerms(Fn callback) { ) | rpl::start_with_next([=] { const auto box = Ui::show(Box( TextWithEntities{ lang(lng_terms_signup_sorry) }, - langFactory(lng_intro_finish), - langFactory(lng_terms_decline))); + tr::lng_intro_finish(), + tr::lng_terms_decline())); box->agreeClicks( ) | rpl::start_with_next([=] { if (weak) { @@ -459,7 +463,7 @@ void Widget::showTerms(Fn callback) { void Widget::showControls() { getStep()->show(); _next->show(); - _next->setText([this] { return getStep()->nextButtonText(); }); + _next->setText(getStep()->nextButtonText()); _connecting->setForceHidden(false); auto hasCover = getStep()->hasCover(); _settings->toggle(!hasCover, anim::type::instant); @@ -605,8 +609,8 @@ Widget::~Widget() { if (App::wnd()) App::wnd()->noIntro(this); } -QString Widget::Step::nextButtonText() const { - return lang(lng_intro_next); +rpl::producer Widget::Step::nextButtonText() const { + return tr::lng_intro_next(); } void Widget::Step::finish(const MTPUser &user, QImage &&photo) { @@ -673,39 +677,19 @@ void Widget::Step::updateLabelsPosition() { } } -void Widget::Step::setTitleText(Fn titleTextFactory) { - _titleTextFactory = std::move(titleTextFactory); - refreshTitle(); - updateLabelsPosition(); +void Widget::Step::setTitleText(rpl::producer titleText) { + _titleText = std::move(titleText); } -void Widget::Step::refreshTitle() { - _title->setText(_titleTextFactory()); +void Widget::Step::setDescriptionText( + rpl::producer descriptionText) { + setDescriptionText( + std::move(descriptionText) | Ui::Text::ToWithEntities()); } -void Widget::Step::setDescriptionText(Fn descriptionTextFactory) { - _descriptionTextFactory = [=] { - return TextWithEntities{ descriptionTextFactory() }; - }; - refreshDescription(); - updateLabelsPosition(); -} - -void Widget::Step::setDescriptionText(Fn richDescriptionTextFactory) { - _descriptionTextFactory = std::move(richDescriptionTextFactory); - refreshDescription(); - updateLabelsPosition(); -} - -void Widget::Step::refreshDescription() { - _description->entity()->setMarkedText(_descriptionTextFactory()); -} - -void Widget::Step::refreshLang() { - refreshTitle(); - refreshDescription(); - refreshError(); - updateLabelsPosition(); +void Widget::Step::setDescriptionText( + rpl::producer richDescriptionText) { + _descriptionText = std::move(richDescriptionText); } void Widget::Step::showFinished() { @@ -886,14 +870,12 @@ void Widget::Step::setErrorBelowLink(bool below) { } } -void Widget::Step::showError(Fn textFactory) { - _errorTextFactory = std::move(textFactory); - refreshError(); - updateLabelsPosition(); +void Widget::Step::showError(rpl::producer text) { + _errorText = std::move(text); } -void Widget::Step::refreshError() { - if (!_errorTextFactory) { +void Widget::Step::refreshError(const QString &text) { + if (text.isEmpty()) { if (_error) _error->hide(anim::type::normal); } else { if (!_error) { @@ -906,13 +888,14 @@ void Widget::Step::refreshError() { : st::introError)); _error->hide(anim::type::instant); } - _error->entity()->setText(_errorTextFactory()); + _error->entity()->setText(text); updateLabelsPosition(); _error->show(anim::type::normal); } } -Widget::Step::Step(QWidget *parent, Data *data, bool hasCover) : TWidget(parent) +Widget::Step::Step(QWidget *parent, Data *data, bool hasCover) +: RpWidget(parent) , _data(data) , _hasCover(hasCover) , _title(this, _hasCover ? st::introCoverTitle : st::introTitle) @@ -933,7 +916,23 @@ Widget::Step::Step(QWidget *parent, Data *data, bool hasCover) : TWidget(parent) } } }); - subscribe(Lang::Current().updated(), [this] { refreshLang(); }); + + _errorText.value( + ) | rpl::start_with_next([=](const QString &text) { + refreshError(text); + }, lifetime()); + + _titleText.value( + ) | rpl::start_with_next([=](const QString &text) { + _title->setText(text); + updateLabelsPosition(); + }, lifetime()); + + _descriptionText.value( + ) | rpl::start_with_next([=](const TextWithEntities &text) { + _description->entity()->setMarkedText(text); + updateLabelsPosition(); + }, lifetime()); } void Widget::Step::prepareShowAnimated(Step *after) { @@ -1030,7 +1029,7 @@ bool Widget::Step::hasBack() const { void Widget::Step::activate() { _title->show(); _description->show(anim::type::instant); - if (_errorTextFactory) { + if (!_errorText.current().isEmpty()) { _error->show(anim::type::instant); } } diff --git a/Telegram/SourceFiles/intro/introwidget.h b/Telegram/SourceFiles/intro/introwidget.h index 416f5c7652..8b5badcdf8 100644 --- a/Telegram/SourceFiles/intro/introwidget.h +++ b/Telegram/SourceFiles/intro/introwidget.h @@ -90,7 +90,7 @@ public: Forward, Replace, }; - class Step : public TWidget, public RPCSender, protected base::Subscriber { + class Step : public Ui::RpWidget, public RPCSender, protected base::Subscriber { public: Step(QWidget *parent, Data *data, bool hasCover = false); @@ -120,16 +120,16 @@ public: virtual void finished(); virtual void submit() = 0; - virtual QString nextButtonText() const; + virtual rpl::producer nextButtonText() const; int contentLeft() const; int contentTop() const; void setErrorCentered(bool centered); void setErrorBelowLink(bool below); - void showError(Fn textFactory); + void showError(rpl::producer text); void hideError() { - showError(Fn()); + showError(rpl::single(QString())); } ~Step(); @@ -138,9 +138,10 @@ public: void paintEvent(QPaintEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void setTitleText(Fn titleTextFactory); - void setDescriptionText(Fn descriptionTextFactory); - void setDescriptionText(Fn richDescriptionTextFactory); + void setTitleText(rpl::producer titleText); + void setDescriptionText(rpl::producer descriptionText); + void setDescriptionText( + rpl::producer richDescriptionText); bool paintAnimated(Painter &p, QRect clip); void fillSentCodeData(const MTPDauth_sentCode &type); @@ -190,7 +191,7 @@ public: }; void updateLabelsPosition(); void paintContentSnapshot(Painter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden); - void refreshError(); + void refreshError(const QString &text); void refreshTitle(); void refreshDescription(); void refreshLang(); @@ -208,17 +209,16 @@ public: Fn _goCallback; Fn _showResetCallback; Fn _showTermsCallback; - Fn callback)> _acceptTermsCallback; + Fn callback)> _acceptTermsCallback; + rpl::variable _titleText; object_ptr _title; - Fn _titleTextFactory; + rpl::variable _descriptionText; object_ptr> _description; - Fn _descriptionTextFactory; bool _errorCentered = false; bool _errorBelowLink = false; - Fn _errorTextFactory; + rpl::variable _errorText; object_ptr> _error = { nullptr }; Ui::Animations::Simple _a_show; diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index cd7e61943a..97fdfdbc94 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -73,30 +73,31 @@ ConfirmSwitchBox::ConfirmSwitchBox( void ConfirmSwitchBox::prepare() { setTitle(tr::lng_language_switch_title()); - const auto text = (_official - ? lng_language_switch_about_official__rich - : lng_language_switch_about_unofficial__rich)( - lt_lang_name, - Ui::Text::Bold(_name), - lt_percent, - Ui::Text::Bold(QString::number(_percent)), - lt_link, - Ui::Text::Link(lang(lng_language_switch_link), _editLink)); + auto text = (_official + ? tr::lng_language_switch_about_official + : tr::lng_language_switch_about_unofficial)( + lt_lang_name, + rpl::single(Ui::Text::Bold(_name)), + lt_percent, + rpl::single(Ui::Text::Bold(QString::number(_percent))), + lt_link, + tr::lng_language_switch_link() | Ui::Text::ToLink(_editLink), + Ui::Text::WithEntities); const auto content = Ui::CreateChild>( this, object_ptr( this, - rpl::single(text), + std::move(text), st::boxLabel), QMargins{ st::boxPadding.left(), 0, st::boxPadding.right(), 0 }); content->entity()->setLinksTrusted(); - addButton(langFactory(lng_language_switch_apply), [=] { + addButton(tr::lng_language_switch_apply(), [=] { const auto apply = _apply; closeBox(); apply(); }); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); content->resizeToWidth(st::boxWideWidth); content->heightValue( @@ -115,21 +116,22 @@ NotReadyBox::NotReadyBox( void NotReadyBox::prepare() { setTitle(tr::lng_language_not_ready_title()); - const auto text = lng_language_not_ready_about__rich( + auto text = tr::lng_language_not_ready_about( lt_lang_name, - TextWithEntities{ _name }, + rpl::single(_name) | Ui::Text::ToWithEntities(), lt_link, - Ui::Text::Link(lang(lng_language_not_ready_link), _editLink)); + tr::lng_language_not_ready_link() | Ui::Text::ToLink(_editLink), + Ui::Text::WithEntities); const auto content = Ui::CreateChild>( this, object_ptr( this, - rpl::single(text), + std::move(text), st::boxLabel), QMargins{ st::boxPadding.left(), 0, st::boxPadding.right(), 0 }); content->entity()->setLinksTrusted(); - addButton(langFactory(lng_box_ok), [=] { closeBox(); }); + addButton(tr::lng_box_ok(), [=] { closeBox(); }); content->resizeToWidth(st::boxWidth); content->heightValue( diff --git a/Telegram/SourceFiles/lang/lang_keys.h b/Telegram/SourceFiles/lang/lang_keys.h index e80f13abe5..e33e97379b 100644 --- a/Telegram/SourceFiles/lang/lang_keys.h +++ b/Telegram/SourceFiles/lang/lang_keys.h @@ -14,10 +14,6 @@ inline QString lang(LangKey key) { return Lang::Current().getValue(key); } -inline Fn langFactory(LangKey key) { - return [key] { return Lang::Current().getValue(key); }; -} - template inline QString langDateMaybeWithYear(QDate date, WithYear withYear, WithoutYear withoutYear) { auto month = date.month(); diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index b7555c8416..f1579cec5d 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -236,11 +236,13 @@ OverlayWidget::OverlayWidget() setWindowIcon(Window::CreateIcon(&Core::App().activeAccount())); setWindowTitle(qsl("Media viewer")); - const auto text = lng_mediaview_saved_to__rich( + const auto text = tr::lng_mediaview_saved_to( + tr::now, lt_downloads, Ui::Text::Link( - lang(lng_mediaview_downloads), - "internal:show_saved_message")); + tr::lng_mediaview_downloads(tr::now), + "internal:show_saved_message"), + Ui::Text::WithEntities); _saveMsgText.setMarkedText(st::mediaviewSaveMsgStyle, text, Ui::DialogTextOptions()); _saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom()); @@ -2241,7 +2243,7 @@ void OverlayWidget::initThemePreview() { if (_themePreview) { _themeApply.create( this, - langFactory(lng_theme_preview_apply), + tr::lng_theme_preview_apply(), st::themePreviewApplyButton); _themeApply->show(); _themeApply->setClickedCallback([this] { @@ -2251,7 +2253,7 @@ void OverlayWidget::initThemePreview() { }); _themeCancel.create( this, - langFactory(lng_cancel), + tr::lng_cancel(), st::themePreviewCancelButton); _themeCancel->show(); _themeCancel->setClickedCallback([this] { close(); }); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp index 849f226c6f..a3099b5d21 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp @@ -187,8 +187,8 @@ void VerifyBox::setInnerFocus() { void VerifyBox::prepare() { setTitle(std::move(_title)); - addButton(langFactory(lng_change_phone_new_submit), _submit); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_change_phone_new_submit(), _submit); + addButton(tr::lng_cancel(), [=] { closeBox(); }); _content->resizeToWidth(st::boxWidth); _content->heightValue( @@ -214,7 +214,7 @@ PanelEditContact::PanelEditContact( , _bottomShadow(this) , _done( this, - langFactory(lng_passport_save_value), + tr::lng_passport_save_value(), st::passportPanelSaveValue) { setupControls(data, existing); } diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index 082f89159a..2fc28fd3c3 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -89,8 +89,8 @@ RequestTypeBox::RequestTypeBox( void RequestTypeBox::prepare() { setTitle(std::move(_title)); - addButton(langFactory(lng_passport_upload_document), _submit); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_passport_upload_document(), _submit); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensions(st::boxWidth, _height); } @@ -154,8 +154,8 @@ DeleteDocumentBox::DeleteDocumentBox( } void DeleteDocumentBox::prepare() { - addButton(langFactory(lng_box_delete), _submit); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_box_delete(), _submit); + addButton(tr::lng_cancel(), [=] { closeBox(); }); setDimensions(st::boxWidth, _height); } @@ -221,7 +221,7 @@ PanelEditDocument::PanelEditDocument( , _bottomShadow(this) , _done( this, - langFactory(lng_passport_save_value), + tr::lng_passport_save_value(), st::passportPanelSaveValue) { setupControls( &error, @@ -249,7 +249,7 @@ PanelEditDocument::PanelEditDocument( , _bottomShadow(this) , _done( this, - langFactory(lng_passport_save_value), + tr::lng_passport_save_value(), st::passportPanelSaveValue) { setupControls( nullptr, @@ -274,7 +274,7 @@ PanelEditDocument::PanelEditDocument( , _bottomShadow(this) , _done( this, - langFactory(lng_passport_save_value), + tr::lng_passport_save_value(), st::passportPanelSaveValue) { setupControls(&error, &data, nullptr, nullptr, {}, {}, {}); } diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index 5cce716316..fd6baf71c6 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -313,7 +313,7 @@ ScanButton::ScanButton( this, object_ptr( this, - langFactory(lng_passport_delete_scan_undo), + tr::lng_passport_delete_scan_undo(), _st.restore)) { _delete->toggle(!deleted, anim::type::instant); _restore->toggle(deleted, anim::type::instant); diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index f1d2a705ee..bcd48288da 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -177,7 +177,7 @@ PanelForm::PanelForm( , _bottomShadow(this) , _submit( this, - langFactory(lng_passport_authorize), + tr::lng_passport_authorize(), st::passportPanelAuthorize) { setupControls(); } @@ -292,19 +292,24 @@ not_null PanelForm::setupContent() { }); }, lifetime()); const auto policyUrl = _controller->privacyPolicyUrl(); - const auto richText = policyUrl.isEmpty() - ? TextWithEntities{ lng_passport_allow(lt_bot, '@' + bot->username) } - : lng_passport_accept_allow__rich( - lt_policy, - Ui::Text::Link( - lng_passport_policy(lt_bot, App::peerName(bot)), - policyUrl), + auto text = policyUrl.isEmpty() + ? tr::lng_passport_allow( lt_bot, - TextWithEntities{ '@' + bot->username }); + rpl::single('@' + bot->username) + ) | Ui::Text::ToWithEntities() + : tr::lng_passport_accept_allow( + lt_policy, + tr::lng_passport_policy( + lt_bot, + rpl::single(App::peerName(bot)) + ) | Ui::Text::ToLink(policyUrl), + lt_bot, + rpl::single('@' + bot->username) | Ui::Text::ToWithEntities(), + Ui::Text::WithEntities); const auto policy = inner->add( object_ptr( inner, - rpl::single(richText), + std::move(text), st::passportFormPolicy), st::passportFormPolicyPadding); policy->setLinksTrusted(); diff --git a/Telegram/SourceFiles/passport/passport_panel_password.cpp b/Telegram/SourceFiles/passport/passport_panel_password.cpp index eb8eb3ad4a..8d911f78b0 100644 --- a/Telegram/SourceFiles/passport/passport_panel_password.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_password.cpp @@ -45,7 +45,7 @@ PanelAskPassword::PanelAskPassword( this, st::defaultInputField, tr::lng_passport_password_placeholder()) -, _submit(this, langFactory(lng_passport_next), st::passportPasswordSubmit) +, _submit(this, tr::lng_passport_next(), st::passportPasswordSubmit) , _forgot(this, lang(lng_signin_recover), st::defaultLinkButton) { connect(_password, &Ui::PasswordInput::submitted, this, [=] { submit(); @@ -230,7 +230,7 @@ void PanelNoPassword::refreshBottom() { _inner, object_ptr( _inner, - langFactory(lng_passport_password_create), + tr::lng_passport_password_create(), st::defaultBoxButton))); button->entity()->addClickHandler([=] { _controller->setupPassword(); @@ -242,14 +242,14 @@ void PanelNoPassword::refreshBottom() { st::defaultBoxButton.height)); const auto cancel = Ui::CreateChild( container, - langFactory(lng_cancel), + tr::lng_cancel(), st::defaultBoxButton); cancel->addClickHandler([=] { _controller->cancelPasswordSubmit(); }); const auto validate = Ui::CreateChild( container, - langFactory(lng_passport_email_validate), + tr::lng_passport_email_validate(), st::defaultBoxButton); validate->addClickHandler([=] { _controller->validateRecoveryEmail(); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 868b4de752..85235a5d81 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -674,8 +674,8 @@ void MainWindow::createGlobalMenu() { return; } Ui::show(Box(std::make_unique(), [](not_null box) { - box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); - box->addLeftButton(langFactory(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }); + box->addButton(tr::lng_close(), [box] { box->closeBox(); }); + box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); })); })); psAddContact = window->addAction(lang(lng_mac_menu_add_contact), App::wnd(), SLOT(onShowAddContact())); diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 7c24d17971..336814e3be 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -51,7 +51,7 @@ void SetupPhoto( st::settingsInfoPhoto); const auto upload = Ui::CreateChild( wrap, - langFactory(lng_settings_upload), + tr::lng_settings_upload(), st::settingsInfoPhotoSet); upload->setFullRadius(true); upload->addClickHandler([=] { diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 4ddfa1f38c..ef12f5f68d 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -260,7 +260,7 @@ void BlockedBoxController::BlockNewUser() { Auth().api().blockUser(user); box->closeBox(); }); - box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); }); + box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; Ui::show( Box(std::move(controller), std::move(initBox)), diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 48ff0f44b7..bedb038aa4 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -119,10 +119,10 @@ void SetupPrivacy(not_null container) { st::settingsButton )->addClickHandler([] { const auto initBox = [](not_null box) { - box->addButton(langFactory(lng_close), [=] { + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); - box->addLeftButton(langFactory(lng_blocked_list_add), [] { + box->addLeftButton(tr::lng_blocked_list_add(), [] { BlockedBoxController::BlockNewUser(); }); }; diff --git a/Telegram/SourceFiles/support/support_autocomplete.cpp b/Telegram/SourceFiles/support/support_autocomplete.cpp index d9a4e46e0e..c0dd03ee90 100644 --- a/Telegram/SourceFiles/support/support_autocomplete.cpp +++ b/Telegram/SourceFiles/support/support_autocomplete.cpp @@ -539,7 +539,7 @@ void ConfirmContactBox::prepare() { } }; - const auto button = addButton(langFactory(lng_send_button), [] {}); + const auto button = addButton(tr::lng_send_button(), [] {}); button->clicks( ) | rpl::start_with_next([=](Qt::MouseButton which) { _submit((which == Qt::RightButton) @@ -548,7 +548,7 @@ void ConfirmContactBox::prepare() { }, button->lifetime()); button->setAcceptBoth(true); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); } void ConfirmContactBox::keyPressEvent(QKeyEvent *e) { diff --git a/Telegram/SourceFiles/support/support_helper.cpp b/Telegram/SourceFiles/support/support_helper.cpp index 10f8f574bb..cb4899865a 100644 --- a/Telegram/SourceFiles/support/support_helper.cpp +++ b/Telegram/SourceFiles/support/support_helper.cpp @@ -85,8 +85,8 @@ void EditInfoBox::prepare() { }); _submit(_field->getTextWithAppliedMarkdown(), done); }; - addButton(langFactory(lng_settings_save), save); - addButton(langFactory(lng_cancel), [=] { closeBox(); }); + addButton(tr::lng_settings_save(), save); + addButton(tr::lng_cancel(), [=] { closeBox(); }); connect(_field, &Ui::InputField::submitted, save); connect(_field, &Ui::InputField::cancelled, [=] { closeBox(); }); diff --git a/Telegram/SourceFiles/ui/countryinput.cpp b/Telegram/SourceFiles/ui/countryinput.cpp index 1ef60d2f24..5a6320691f 100644 --- a/Telegram/SourceFiles/ui/countryinput.cpp +++ b/Telegram/SourceFiles/ui/countryinput.cpp @@ -245,7 +245,7 @@ void CountrySelectBox::prepare() { st::countriesScroll, _select->height()); - addButton(langFactory(lng_close), [=] { closeBox(); }); + addButton(tr::lng_close(), [=] { closeBox(); }); setDimensions(st::boxWidth, st::boxMaxListHeight); diff --git a/Telegram/SourceFiles/ui/widgets/buttons.cpp b/Telegram/SourceFiles/ui/widgets/buttons.cpp index 145addbfea..2bfc2930c4 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.cpp +++ b/Telegram/SourceFiles/ui/widgets/buttons.cpp @@ -230,21 +230,26 @@ void FlatButton::setTextMargins(QMargins margins) { update(); } -RoundButton::RoundButton(QWidget *parent, Fn textFactory, const style::RoundButton &st) : RippleButton(parent, st.ripple) -, _textFactory(std::move(textFactory)) +RoundButton::RoundButton( + QWidget *parent, + rpl::producer text, + const style::RoundButton &st) +: RippleButton(parent, st.ripple) +, _textFull(std::move(text)) , _st(st) { - subscribe(Lang::Current().updated(), [this] { refreshText(); }); - refreshText(); + _textFull.value( + ) | rpl::start_with_next([=](const QString &text) { + resizeToText(text); + }, lifetime()); } void RoundButton::setTextTransform(TextTransform transform) { _transform = transform; - refreshText(); + resizeToText(_textFull.current()); } -void RoundButton::setText(Fn textFactory) { - _textFactory = std::move(textFactory); - refreshText(); +void RoundButton::setText(rpl::producer text) { + _textFull = std::move(text); } void RoundButton::setNumbersText(const QString &numbersText, int numbers) { @@ -258,7 +263,7 @@ void RoundButton::setNumbersText(const QString &numbersText, int numbers) { } _numbers->setText(numbersText, numbers); } - refreshText(); + resizeToText(_textFull.current()); } void RoundButton::setWidthChangedCallback(Fn callback) { @@ -277,13 +282,12 @@ void RoundButton::finishNumbersAnimation() { } void RoundButton::numbersAnimationCallback() { - resizeToText(); - update(); + resizeToText(_textFull.current()); } void RoundButton::setFullWidth(int newFullWidth) { _fullWidthOverride = newFullWidth; - refreshText(); + resizeToText(_textFull.current()); } void RoundButton::setFullRadius(bool enabled) { @@ -291,24 +295,14 @@ void RoundButton::setFullRadius(bool enabled) { update(); } -void RoundButton::refreshText() { - _text = computeFullText(); - _textWidth = _text.isEmpty() ? 0 : _st.font->width(_text); +void RoundButton::resizeToText(const QString &text) { + _text = (_transform == TextTransform::ToUpper) ? text.toUpper() : text; + _textWidth = _st.font->width(_text); - resizeToText(); - update(); -} - -QString RoundButton::computeFullText() const { - auto result = _textFactory ? _textFactory() : QString(); - return (_transform == TextTransform::ToUpper) ? result.toUpper() : result; -} - -void RoundButton::resizeToText() { int innerWidth = contentWidth(); if (_fullWidthOverride > 0) { if (_fullWidthOverride < innerWidth + (_st.height - _st.font->height)) { - _text = _st.font->elided(computeFullText(), qMax(_fullWidthOverride - (_st.height - _st.font->height), 1)); + _text = _st.font->elided(text, qMax(_fullWidthOverride - (_st.height - _st.font->height), 1)); _textWidth = _st.font->width(_text); } resize(_fullWidthOverride, _st.height + _st.padding.top() + _st.padding.bottom()); @@ -318,11 +312,13 @@ void RoundButton::resizeToText() { resize(innerWidth - _st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); } else { if (_st.width < innerWidth + (_st.height - _st.font->height)) { - _text = _st.font->elided(computeFullText(), qMax(_st.width - (_st.height - _st.font->height), 1)); + _text = _st.font->elided(_text, qMax(_st.width - (_st.height - _st.font->height), 1)); _textWidth = _st.font->width(_text); } resize(_st.width + _st.padding.left() + _st.padding.right(), _st.height + _st.padding.top() + _st.padding.bottom()); } + + update(); } int RoundButton::contentWidth() const { diff --git a/Telegram/SourceFiles/ui/widgets/buttons.h b/Telegram/SourceFiles/ui/widgets/buttons.h index 346a5594cd..8965b52592 100644 --- a/Telegram/SourceFiles/ui/widgets/buttons.h +++ b/Telegram/SourceFiles/ui/widgets/buttons.h @@ -105,10 +105,10 @@ class RoundButton : public RippleButton, private base::Subscriber { public: RoundButton( QWidget *parent, - Fn textFactory, + rpl::producer text, const style::RoundButton &st); - void setText(Fn textFactory); + void setText(rpl::producer text); void setNumbersText(const QString &numbersText) { setNumbersText(numbersText, numbersText.toInt()); @@ -139,14 +139,12 @@ protected: QPoint prepareRippleStartPosition() const override; private: - void refreshText(); - QString computeFullText() const; void setNumbersText(const QString &numbersText, int numbers); void numbersAnimationCallback(); - void resizeToText(); + void resizeToText(const QString &text); + rpl::variable _textFull; QString _text; - Fn _textFactory; int _textWidth; std::unique_ptr _numbers; diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 0f56e04823..6d43f00019 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -170,8 +170,8 @@ void MainWindow::checkLockByTerms() { Ui::hideSettingsAndLayer(anim::type::instant); const auto box = Ui::show(Box( *data, - langFactory(lng_terms_agree), - langFactory(lng_terms_decline))); + tr::lng_terms_agree(), + tr::lng_terms_decline())); box->setCloseByEscape(false); box->setCloseByOutsideClick(false); @@ -205,8 +205,8 @@ void MainWindow::showTermsDecline() { const auto box = Ui::show( Box( TextWithEntities{ lang(lng_terms_update_sorry) }, - langFactory(lng_terms_decline_and_delete), - langFactory(lng_terms_back), + tr::lng_terms_decline_and_delete(), + tr::lng_terms_back(), true), LayerOption::KeepOther); diff --git a/Telegram/SourceFiles/window/notifications_manager_default.cpp b/Telegram/SourceFiles/window/notifications_manager_default.cpp index 800fd52ebb..a2252f5eea 100644 --- a/Telegram/SourceFiles/window/notifications_manager_default.cpp +++ b/Telegram/SourceFiles/window/notifications_manager_default.cpp @@ -518,7 +518,7 @@ Notification::Notification( , _item(msg) , _forwardedCount(forwardedCount) , _close(this, st::notifyClose) -, _reply(this, langFactory(lng_notification_reply), st::defaultBoxButton) { +, _reply(this, tr::lng_notification_reply(), st::defaultBoxButton) { subscribe(Lang::Current().updated(), [this] { refreshLang(); }); auto position = computePosition(st::notifyMinHeight); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp index dc67bfb359..0e42827c94 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor.cpp @@ -570,8 +570,8 @@ ThemeExportBox::ThemeExportBox(QWidget*, const QByteArray &paletteContent, const void ThemeExportBox::prepare() { setTitle(tr::lng_theme_editor_background_image()); - addButton(langFactory(lng_theme_editor_export), [this] { exportTheme(); }); - addButton(langFactory(lng_cancel), [this] { closeBox(); }); + addButton(tr::lng_theme_editor_export(), [this] { exportTheme(); }); + addButton(tr::lng_cancel(), [this] { closeBox(); }); auto height = st::themesSmallSkip + st::themesBackgroundSize + st::themesSmallSkip + _tileBackground->height(); diff --git a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp index dcb6db2212..c418925d6a 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_warning.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_warning.cpp @@ -25,8 +25,8 @@ WarningWidget::WarningWidget(QWidget *parent) : TWidget(parent) , _timer([=] { handleTimer(); }) , _secondsLeft(kWaitBeforeRevertMs / 1000) -, _keepChanges(this, langFactory(lng_theme_keep_changes), st::defaultBoxButton) -, _revert(this, langFactory(lng_theme_revert), st::defaultBoxButton) { +, _keepChanges(this, tr::lng_theme_keep_changes(), st::defaultBoxButton) +, _revert(this, tr::lng_theme_revert(), st::defaultBoxButton) { _keepChanges->setClickedCallback([] { Window::Theme::KeepApplied(); }); _revert->setClickedCallback([] { Window::Theme::Revert(); }); updateText(); diff --git a/Telegram/SourceFiles/window/window_lock_widgets.cpp b/Telegram/SourceFiles/window/window_lock_widgets.cpp index 89be814ad3..bad087173c 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.cpp +++ b/Telegram/SourceFiles/window/window_lock_widgets.cpp @@ -97,7 +97,7 @@ void LockWidget::paintContent(Painter &p) { PasscodeLockWidget::PasscodeLockWidget(QWidget *parent) : LockWidget(parent) , _passcode(this, st::passcodeInput, tr::lng_passcode_ph()) -, _submit(this, langFactory(lng_passcode_submit), st::passcodeSubmit) +, _submit(this, tr::lng_passcode_submit(), st::passcodeSubmit) , _logout(this, lang(lng_passcode_logout)) { connect(_passcode, &Ui::MaskedInputField::changed, [=] { changed(); }); connect(_passcode, &Ui::MaskedInputField::submitted, [=] { submit(); }); @@ -187,22 +187,22 @@ TermsLock TermsLock::FromMTP(const MTPDhelp_termsOfService &data) { TermsBox::TermsBox( QWidget*, const TermsLock &data, - Fn agree, - Fn cancel) + rpl::producer agree, + rpl::producer cancel) : _data(data) -, _agree(agree) -, _cancel(cancel) { +, _agree(std::move(agree)) +, _cancel(std::move(cancel)) { } TermsBox::TermsBox( QWidget*, const TextWithEntities &text, - Fn agree, - Fn cancel, + rpl::producer agree, + rpl::producer cancel, bool attentionAgree) : _data{ {}, text, std::nullopt, false } -, _agree(agree) -, _cancel(cancel) +, _agree(std::move(agree)) +, _cancel(std::move(cancel)) , _attentionAgree(attentionAgree) { } @@ -285,7 +285,7 @@ void TermsBox::prepare() { const auto &agreeStyle = _attentionAgree ? st::attentionBoxButton : st::defaultBoxButton; - addButton(_agree, [=] {}, agreeStyle)->clicks( + addButton(std::move(_agree), [=] {}, agreeStyle)->clicks( ) | rpl::filter([=] { if (age && !age->entity()->checked()) { toggleAgeError(true); @@ -297,7 +297,7 @@ void TermsBox::prepare() { }) | rpl::start_to_stream(_agreeClicks, lifetime()); if (_cancel) { - addButton(_cancel, [=] {})->clicks( + addButton(std::move(_cancel), [=] {})->clicks( ) | rpl::map([] { return rpl::empty_value(); }) | rpl::start_to_stream(_cancelClicks, lifetime()); diff --git a/Telegram/SourceFiles/window/window_lock_widgets.h b/Telegram/SourceFiles/window/window_lock_widgets.h index e256746af7..5e922f6196 100644 --- a/Telegram/SourceFiles/window/window_lock_widgets.h +++ b/Telegram/SourceFiles/window/window_lock_widgets.h @@ -86,13 +86,13 @@ public: TermsBox( QWidget*, const TermsLock &data, - Fn agree, - Fn cancel); + rpl::producer agree, + rpl::producer cancel); TermsBox( QWidget*, const TextWithEntities &text, - Fn agree, - Fn cancel, + rpl::producer agree, + rpl::producer cancel, bool attentionAgree = false); rpl::producer<> agreeClicks() const; @@ -106,8 +106,8 @@ protected: private: TermsLock _data; - Fn _agree; - Fn _cancel; + rpl::producer _agree; + rpl::producer _cancel; rpl::event_stream<> _agreeClicks; rpl::event_stream<> _cancelClicks; QString _lastClickedMention; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 09f3390d09..9ef50342ad 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -239,14 +239,14 @@ void MainMenu::refreshMenu() { }, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver); _menu->addAction(lang(lng_menu_contacts), [] { Ui::show(Box(std::make_unique(), [](not_null box) { - box->addButton(langFactory(lng_close), [box] { box->closeBox(); }); - box->addLeftButton(langFactory(lng_profile_add_contact), [] { App::wnd()->onShowAddContact(); }); + box->addButton(tr::lng_close(), [box] { box->closeBox(); }); + box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); }); })); }, &st::mainMenuContacts, &st::mainMenuContactsOver); if (Global::PhoneCallsEnabled()) { _menu->addAction(lang(lng_menu_calls), [] { Ui::show(Box(std::make_unique(), [](not_null box) { - box->addButton(langFactory(lng_close), [=] { + box->addButton(tr::lng_close(), [=] { box->closeBox(); }); box->addTopButton(st::callSettingsButton, [=] { diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 9fc2227818..835dab342e 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -672,7 +672,7 @@ void PeerMenuShareContactBox(not_null user) { *weak = Ui::show(Box( std::make_unique(std::move(callback)), [](not_null box) { - box->addButton(langFactory(lng_cancel), [box] { + box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); })); @@ -714,10 +714,10 @@ void PeerMenuBlockUserBox( box->addRow(object_ptr( box, - rpl::single( - lng_blocked_list_confirm_text__rich( - lt_name, - Ui::Text::Bold(name))), + tr::lng_blocked_list_confirm_text( + lt_name, + rpl::single(Ui::Text::Bold(name)), + Ui::Text::WithEntities), st::blockUserConfirmation)); box->addSkip(st::boxMediumSkip); @@ -746,7 +746,7 @@ void PeerMenuBlockUserBox( lt_name, rpl::single(name))); - box->addButton(langFactory(lng_blocked_list_confirm_ok), [=] { + box->addButton(tr::lng_blocked_list_confirm_ok(), [=] { const auto reportChecked = report && report->checked(); const auto clearChecked = clear->checked(); @@ -769,7 +769,7 @@ void PeerMenuBlockUserBox( lng_new_contact_block_done(lt_user, user->shortName())); }, st::attentionBoxButton); - box->addButton(langFactory(lng_cancel), [=] { + box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } @@ -803,7 +803,7 @@ QPointer ShowForwardMessagesBox( } }; auto initBox = [](not_null box) { - box->addButton(langFactory(lng_cancel), [box] { + box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); };