0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/app/helpers/topics_helper.rb
Natalie Tay cff8f6ea4d
FEATURE: Allow selection of multiple content languages when viewing topics and posts (#42128)
Related:
https://meta.discourse.org/t/multi-language-preferences-for-displaying-localized-content/381116

Allow anon and logged in users to set more than one language that they
understand, when content localization is enabled.


### User preferences

In user preferences, we now include a Content Languages section when the
site has Content Localization enabled.

### Topic menu

In topics where there are any languages that's not the user's language,
the option will appear to set their preferred content languages. This
appears for anon and logged in users, but anon users will be asked to
logged in to set the languages.
__________

These preferences apply only to topic titles and posts. They do not
affect navigational features like categories, tags, or sidebar content.
The per-post option to show the original remains independent of the
user's preferences.

This PR temporarily retains `show_original_content` as a compatibility
field computed from `automatically_translate`, keeping cached clients
and rolling deployments safe. A follow-up PR will remove the legacy API
and frontend compatibility code, then retire the old database column
through the staged column-removal process.
2026-07-30 12:19:44 +08:00

39 lines
1.2 KiB
Ruby
Vendored

# 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)
# locale param is appropriately set in the application controller
# depending on site settings and presence of user
locale = I18n.locale
if ContentLocalization.show_translated_topic?(topic_view.topic, guardian)
LocalizationAttributesReplacer.replace_topic_attributes(topic_view.topic, locale)
end
topic_view.posts.each do |post|
if ContentLocalization.show_translated_post?(post, guardian)
LocalizationAttributesReplacer.replace_post_attributes(post, locale)
end
end
end
end