0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-07 13:19:19 +08:00
discourse/app/serializers/sidebar_section_edit_serializer.rb
Natalie Tay 93e0ba7985
FIX: Allow manual Community sidebar links to be localized (#41898)
Follow up to https://github.com/discourse/discourse/pull/41795

This adds content-localization support for manually created links in the
built-in Community sidebar section.

Built-in Community links like Topics, My posts, Review, Admin, etc.
still use their existing frontend i18n labels and do not expose
localization controls. Only admin-created links in the Community section
can be localized (since only the admin can edit it).

The earlier PR had skipped adding these entirely for the Community
section
2026-07-22 15:57:56 +08:00

29 lines
706 B
Ruby
Vendored

# frozen_string_literal: true
class SidebarSectionEditSerializer < SidebarSectionSerializer
def title
object.title
end
def links
object.sidebar_urls.map do |sidebar_url|
SidebarUrlSerializer.new(
sidebar_url,
root: false,
scope: scope,
include_localizations: can_localize_sidebar_url?(sidebar_url),
can_localize: can_localize_sidebar_url?(sidebar_url),
).as_json
end
end
def include_localizations?
object.localizations.loaded? && scope.can_localize_sidebar_section_title?(object)
end
private
def can_localize_sidebar_url?(sidebar_url)
scope.can_localize_sidebar_section_link?(object, sidebar_url.value)
end
end