mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
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
32 lines
717 B
Ruby
Vendored
32 lines
717 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class SidebarUrlSerializer < ApplicationSerializer
|
|
attributes :id, :name, :value, :icon, :external, :segment, :locale, :can_localize
|
|
|
|
has_many :localizations, embed: :objects, serializer: SidebarUrlLocalizationSerializer
|
|
|
|
def name
|
|
if @options[:show_translated_name] &&
|
|
ContentLocalization.show_translated_sidebar_url?(object, scope)
|
|
object.get_localization&.name || object.name
|
|
else
|
|
object.name
|
|
end
|
|
end
|
|
|
|
def external
|
|
object.external?
|
|
end
|
|
|
|
def include_localizations?
|
|
@options[:include_localizations]
|
|
end
|
|
|
|
def can_localize
|
|
@options[:can_localize]
|
|
end
|
|
|
|
def include_can_localize?
|
|
@options.key?(:can_localize)
|
|
end
|
|
end
|