diff --git a/Telegram/SourceFiles/data/data_document_media.cpp b/Telegram/SourceFiles/data/data_document_media.cpp index 83bf70d31..fa7b6fb0c 100644 --- a/Telegram/SourceFiles/data/data_document_media.cpp +++ b/Telegram/SourceFiles/data/data_document_media.cpp @@ -66,7 +66,8 @@ enum class FileType { } else if (type == FileType::AnimatedSticker) { return Lottie::ReadThumbnail(Lottie::ReadContent(data, path)); } else if (type == FileType::Theme) { - return Window::Theme::GeneratePreview(data, path); + auto langStrings = Window::Theme::CollectStrings(); + return Window::Theme::GeneratePreview(data, path, langStrings); } else if (type == FileType::WallPatternSVG) { return Images::Read({ .path = path, diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 76c5c1ad7..7ba2678a9 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -3020,13 +3020,15 @@ void OverlayWidget::initThemePreview() { const auto path = _document->location().name(); const auto id = _themePreviewId = base::RandomValue(); const auto weak = Ui::MakeWeak(_widget); + auto langStrings = CollectStrings(); crl::async([=, data = std::move(current)]() mutable { auto preview = GeneratePreview( bytes, path, fields, std::move(data), - Window::Theme::PreviewType::Extended); + Window::Theme::PreviewType::Extended, + langStrings); crl::on_main(weak, [=, result = std::move(preview)]() mutable { const auto session = weakSession.get(); if (id != _themePreviewId || !session) { diff --git a/Telegram/SourceFiles/storage/localimageloader.cpp b/Telegram/SourceFiles/storage/localimageloader.cpp index 33fa80eed..60a907f6e 100644 --- a/Telegram/SourceFiles/storage/localimageloader.cpp +++ b/Telegram/SourceFiles/storage/localimageloader.cpp @@ -897,7 +897,8 @@ void FileLoadTask::process(Args &&args) { thumbnail = PrepareFileThumbnail(std::move(video->thumbnail)); } else if (filemime == qstr("application/x-tdesktop-theme") || filemime == qstr("application/x-tgtheme-tdesktop")) { - goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath); + auto langStrings = Window::Theme::CollectStrings(); + goodThumbnail = Window::Theme::GeneratePreview(_content, _filepath, langStrings); if (!goodThumbnail.isNull()) { QBuffer buffer(&goodThumbnailBytes); goodThumbnail.save(&buffer, "JPG", kThumbnailQuality); diff --git a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp index 4843eb235..0ce606d91 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_editor_box.cpp @@ -392,7 +392,8 @@ SendMediaReady PrepareThemeMedia( PreparedPhotoThumbs thumbnails; QVector sizes; - auto thumbnail = GeneratePreview(content, QString()).scaled( + auto langStrings = CollectStrings(); + auto thumbnail = GeneratePreview(content, QString(), langStrings).scaled( 320, 320, Qt::KeepAspectRatio, diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp index c94c26dbc..931884025 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.cpp @@ -89,7 +89,8 @@ public: Generator( const Instance &theme, CurrentData &¤t, - PreviewType type); + PreviewType type, + QMap lang); [[nodiscard]] QImage generate(); @@ -198,6 +199,8 @@ private: style::TextPalette _textPalette; + QMap _lang; + }; bool Generator::extended() const { @@ -375,7 +378,7 @@ void Generator::generateData() { addRow("Davy Jones", 5, "4:00", Ui::Text::PlainLink("Keynote.pdf")); _topBarName.setText(st::msgNameStyle, "Eva Summer", Ui::NameTextOptions()); - _topBarStatus = "online"; + _topBarStatus = _lang.value(qsl("lng_status_online")); _topBarStatusActive = true; addPhotoBubble(":/gui/art/themeimage.jpg", "To reach a port, we must sail. " + QString::fromUtf8("\xf0\x9f\xa5\xb8"), "7:00", Status::None); @@ -401,11 +404,13 @@ void Generator::generateData() { Generator::Generator( const Instance &theme, CurrentData &¤t, - PreviewType type) + PreviewType type, + QMap lang) : _theme(theme) , _palette(_theme.palette) , _current(std::move(current)) -, _type(type) { +, _type(type) +, _lang(lang) { } QImage Generator::generate() { @@ -605,7 +610,7 @@ void Generator::paintComposeArea() { field.y() + st::historyComposeField.textMargins.top() + st::historyComposeField.placeholderMargins.top(), field.width() - st::historyComposeField.textMargins.left() - st::historyComposeField.textMargins.right(), field.height() - st::historyComposeField.textMargins.top() - st::historyComposeField.textMargins.bottom()); - _p->drawText(placeholderRect, tr::lng_message_ph(tr::now), QTextOption(st::historyComposeField.placeholderAlign)); + _p->drawText(placeholderRect, _lang.value(qsl("lng_message_ph")), QTextOption(st::historyComposeField.placeholderAlign)); _p->restore(); _p->setClipping(false); @@ -647,7 +652,7 @@ void Generator::paintDialogs() { auto phRect = QRect(filter.x() + st::dialogsFilter.textMrg.left() + st::dialogsFilter.phPos.x(), filter.y() + st::dialogsFilter.textMrg.top() + st::dialogsFilter.phPos.y(), filter.width() - st::dialogsFilter.textMrg.left() - st::dialogsFilter.textMrg.right(), filter.height() - st::dialogsFilter.textMrg.top() - st::dialogsFilter.textMrg.bottom());; _p->setFont(st::dialogsFilter.font); _p->setPen(st::dialogsFilter.phColor[_palette]); - _p->drawText(phRect, tr::lng_dlg_filter(tr::now), QTextOption(st::dialogsFilter.phAlign)); + _p->drawText(phRect, _lang.value(qsl("lng_dlg_filter")), QTextOption(st::dialogsFilter.phAlign)); _p->restore(); _p->setClipping(false); @@ -1041,7 +1046,8 @@ std::unique_ptr GeneratePreview( const QString &filepath, const Data::CloudTheme &cloud, CurrentData &&data, - PreviewType type) { + PreviewType type, + QMap lang) { auto result = PreviewFromFile(bytes, filepath, cloud); if (!result) { return nullptr; @@ -1049,23 +1055,34 @@ std::unique_ptr GeneratePreview( result->preview = Generator( result->instance, std::move(data), - type + type, + lang ).generate(); return result; } QImage GeneratePreview( const QByteArray &bytes, - const QString &filepath) { + const QString &filepath, + QMap lang) { const auto preview = GeneratePreview( bytes, filepath, Data::CloudTheme(), CurrentData{ Data::ThemeWallPaper().id() }, - PreviewType::Normal); + PreviewType::Normal, + lang); return preview ? preview->preview : QImage(); } +QMap CollectStrings() { + return { + { "lng_message_ph", tr::lng_message_ph(tr::now) }, + { "lng_dlg_filter", tr::lng_dlg_filter(tr::now) }, + { "lng_status_online", tr::lng_status_online(tr::now) }, + }; +} + int DefaultPreviewTitleHeight() { return st::defaultWindowTitle.height; } diff --git a/Telegram/SourceFiles/window/themes/window_theme_preview.h b/Telegram/SourceFiles/window/themes/window_theme_preview.h index 008763286..1d17efca2 100644 --- a/Telegram/SourceFiles/window/themes/window_theme_preview.h +++ b/Telegram/SourceFiles/window/themes/window_theme_preview.h @@ -38,10 +38,13 @@ std::unique_ptr GeneratePreview( const QString &filepath, const Data::CloudTheme &cloud, CurrentData &&data, - PreviewType type); + PreviewType type, + QMap lang); QImage GeneratePreview( const QByteArray &bytes, - const QString &filepath); + const QString &filepath, + QMap lang); +QMap CollectStrings(); int DefaultPreviewTitleHeight(); void DefaultPreviewWindowFramePaint(