Skip to content

FEATURE: Localize topic titles in notifications and bookmarks #34059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update test
  • Loading branch information
nattsw committed Aug 5, 2025
commit dbc4f617b2ecad15ff3a408a0613679e94af94a8
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ acceptance("User menu", function (needs) {
withPluginApi((api) => {
api.registerModelTransformer("bookmark", (bookmarks) => {
bookmarks.forEach((bookmark) => {
if (bookmark.title) {
bookmark.title = `pluginBookmarkTransformer ${bookmark.title}`;
if (bookmark.fancy_title) {
bookmark.fancy_title = `pluginBookmarkTransformer ${bookmark.fancy_title}`;
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def include_fancy_title?
private

def _topic
return topic if defined?(topic) && topic.class == Topic
return object if object.class == Topic
return topic if defined?(topic) && topic.class == Topic
object.topic if defined?(object.topic) && object.topic.class == Topic
end
end
27 changes: 18 additions & 9 deletions spec/requests/notifications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,36 @@ def expect_correct_notifications(response)
end

context "when a notification topic has localizations" do
fab!(:jap_user) { Fabricate(:user, locale: "ja") }
fab!(:topic) { Fabricate(:topic, locale: "en") }
fab!(:english_topic) { Fabricate(:topic, locale: "en") }
fab!(:topic_localization_es) do
Fabricate(:topic_localization, topic:, locale: "es", fancy_title: "Hola Mundo")
Fabricate(
:topic_localization,
topic: english_topic,
locale: "es",
fancy_title: "Hola Mundo",
)
end
fab!(:topic_localization_ja) do
Fabricate(:topic_localization, topic:, locale: "ja", fancy_title: "こんにちは世界")
Fabricate(
:topic_localization,
topic: english_topic,
locale: "ja",
fancy_title: "こんにちは世界",
)
end
fab!(:notification) do
Fabricate(
:notification,
topic:,
user: jap_user,
topic: english_topic,
user:,
notification_type: Notification.types[:liked],
)
end

it "displays the localized fancy title in the user's locale when content_localization_enabled enabled" do
SiteSetting.content_localization_enabled = true
SiteSetting.allow_user_locale = true
sign_in(jap_user)
user.update!(locale: "ja")

get "/notifications.json"

Expand All @@ -475,13 +484,13 @@ def expect_correct_notifications(response)
it "does not display the localized fancy title in the user's locale when content_localization_enabled disabled" do
SiteSetting.content_localization_enabled = false
SiteSetting.allow_user_locale = true
sign_in(jap_user)
user.update!(locale: "ja")

get "/notifications.json"

expect(response.status).to eq(200)
notifications = response.parsed_body["notifications"]
expect(notifications.first["fancy_title"]).to eq(topic.fancy_title)
expect(notifications.first["fancy_title"]).to eq(english_topic.fancy_title)
end
end
end
Expand Down