0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/app/serializers/sidebar_section_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

43 lines
1,015 B
Ruby
Vendored

# frozen_string_literal: true
class SidebarSectionSerializer < ApplicationSerializer
attributes :id, :title, :links, :slug, :public, :section_type, :locale
has_many :localizations, embed: :objects, serializer: SidebarSectionLocalizationSerializer
def links
object.sidebar_urls.map do |sidebar_url|
SidebarUrlSerializer.new(
sidebar_url,
root: false,
scope: scope,
show_translated_name: show_translated_sidebar_url?(sidebar_url),
).as_json
end
end
def title
if ContentLocalization.show_translated_sidebar_section?(object, scope)
object.get_localization&.title || object.title
else
object.title
end
end
def slug
object.title.parameterize
end
def include_localizations?
false
end
private
def show_translated_sidebar_url?(sidebar_url)
return false if !object.public?
return true if object.custom_section?
object.community_section? && !sidebar_url.built_in_community_section_link?
end
end