discourse/app/helpers/topics_helper.rb
Natalie Tay 78269b5ce9
FEATURE: Localize topic view in crawler view (#34253)
Follow up to https://github.com/discourse/discourse/pull/34212

This commit affects the crawler view for topic view, e.g.
\<site>/t/:slug/:id, and updates the title, subcategory (+parent
category breadcrumb), post, if any of them are not in the site default
locale, and have an equivalent localization.


| before | after |
|---|---|
| <img width="1264" height="831" alt="Screenshot 2025-08-12 at 7 09
50 PM"
src="https://github.com/user-attachments/assets/677d4595-4d4a-482e-b948-c0043576348e"
/> mixed mode | <img width="1264" height="831" alt="Screenshot
2025-08-12 at 7 11 35 PM"
src="https://github.com/user-attachments/assets/552f16ca-ebf2-4bdd-a052-a3abb8174a29"
/> site default locale |
2025-08-13 16:38:07 +08:00

32 lines
1,010 B
Ruby

# frozen_string_literal: true
module TopicsHelper
include ApplicationHelper
def render_topic_title(topic)
link_to(Emoji.gsub_emoji_to_unicode(topic.title), topic.relative_url)
end
def categories_breadcrumb(topic)
breadcrumb = []
category = topic.category
if category && !category.uncategorized?
breadcrumb.push(url: category.url, name: category.name, color: category.color)
while category = category.parent_category
breadcrumb.prepend(url: category.url, name: category.name, color: category.color)
end
end
Plugin::Filter.apply(:topic_categories_breadcrumb, topic, breadcrumb)
end
def localize_topic_view_content(topic_view)
crawl_locale = params[Discourse::LOCALE_PARAM].presence || SiteSetting.default_locale
LocalizationAttributesReplacer.replace_topic_attributes(topic_view.topic, crawl_locale)
topic_view.posts.each do |post|
LocalizationAttributesReplacer.replace_post_attributes(post, crawl_locale)
end
end
end