discourse/lib/localized_cooked_post_processor.rb
Keegan George 8b789c9306
FEATURE: Add support for uploads on translated posts (#35871)
## 🔍 Overview

This update allows for having uploads on localized posts. If no uploads
are made, translated posts will show the original uploaded image.
However, if a translator would like to upload a translated image, the
composer will now support an upload reference.

## 🔗 Relevant Links
As requested on Meta:

https://meta.discourse.org/t/translation-composer-missing-image-upload-support/386829


## 📹 Screen Recordings


https://github.com/user-attachments/assets/f01fdfde-c84b-46d8-a96d-a4641699b3b9
2025-11-12 08:55:21 -08:00

29 lines
755 B
Ruby

# frozen_string_literal: true
class LocalizedCookedPostProcessor
include CookedProcessorMixin
def initialize(post_localization, post, opts = {})
@post_localization = post_localization
@post = post
@opts = opts
@doc = Loofah.html5_fragment(@post_localization.cooked)
@cooking_options = @post.cooking_options || {}
@cooking_options[:topic_id] = @post.topic_id
@cooking_options = @cooking_options.symbolize_keys
@model = @post
@category_id = @post&.topic&.category_id
@omit_nofollow = @post.omit_nofollow?
@size_cache = {}
end
def post_process
post_process_oneboxes
post_process_images
@post_localization.link_post_uploads(fragments: @doc)
end
def html
@doc.try(:to_html)
end
end