0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/spec/system/localized_internal_oneboxes_spec.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

75 lines
2.7 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Localized internal oneboxes" do
fab!(:japanese_user) { Fabricate(:user, locale: "ja", refresh_auto_groups: true) }
fab!(:linked_topic) { Fabricate(:topic, title: "Sun Tzu's strategies", locale: "en") }
fab!(:linked_post) do
Fabricate(
:post,
topic: linked_topic,
post_number: 1,
locale: "en",
raw: "Subdue the enemy without fighting.",
)
end
fab!(:host_topic) { Fabricate(:topic, locale: "ja", title: "ホストトピックのタイトルですよ皆さんこんにちは") }
fab!(:host_post) do
Fabricate(:post, topic: host_topic, post_number: 1, locale: "ja", raw: "見てください")
end
let(:host_post_obj) { PageObjects::Components::Post.new(1) }
before do
SiteSetting.allow_user_locale = true
SiteSetting.content_localization_enabled = true
SiteSetting.content_localization_supported_locales = "en|ja"
SiteSetting.content_localization_allowed_groups = Group::AUTO_GROUPS[:everyone]
Fabricate(:topic_localization, topic: linked_topic, locale: "ja", title: "孫子の兵法")
Fabricate(:post_localization, post: linked_post, locale: "ja", cooked: "<p>戦わずして勝つのが最善である</p>")
# bake an internal onebox card (in its original English) into the host post,
# matching what CookedPostProcessor would render for a same-site topic link
host_post.update!(cooked: <<~HTML)
<p></p>
<aside class="quote" data-post="1" data-topic="#{linked_topic.id}">
<div class="title">
<div class="quote-controls"></div>
<div class="quote-title__text-content"><a href="#{linked_topic.relative_url}">Sun Tzu's strategies</a></div>
</div>
<blockquote>Subdue the enemy without fighting.</blockquote>
</aside>
HTML
TopicLink.create!(
topic: host_topic,
post: host_post,
user: host_post.user,
url: "#{Discourse.base_url}#{linked_topic.relative_url}",
domain: Discourse.current_hostname,
internal: true,
quote: true,
reflection: false,
link_topic_id: linked_topic.id,
link_post_id: linked_post.id,
)
end
it "shows the onebox title and preview in the reader's language" do
sign_in(japanese_user)
visit("/t/#{host_topic.id}")
expect(host_post_obj).to have_cooked_content("孫子の兵法")
expect(host_post_obj).to have_cooked_content("戦わずして勝つ")
end
it "leaves the onebox in its original language when automatic translation is off" do
japanese_user.user_option.update!(automatically_translate: false)
sign_in(japanese_user)
visit("/t/#{host_topic.id}")
expect(host_post_obj).to have_cooked_content("Sun Tzu's strategies")
end
end