mirror of
https://github.com/discourse/discourse.git
synced 2026-03-04 01:15:08 +08:00
There's a bug now that translated category names get replaced. This applies to logged in users on sites where `SiteSetting.content_localization_enabled` and `SiteSetting.lazy_load_categories_groups` are enabled for the user. The fix here has been checked for N+1s, and it was covered before in https://github.com/discourse/discourse/pull/34212/files#diff-a064afa7c610321917d3edfd0a462197d7cb3b76191552dfb770f3b9fb11db18.
39 lines
883 B
Ruby
39 lines
883 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CategoryBadgeSerializer < ApplicationSerializer
|
|
attributes :id,
|
|
:name,
|
|
:slug,
|
|
:color,
|
|
:text_color,
|
|
:style_type,
|
|
:icon,
|
|
:emoji,
|
|
:read_restricted,
|
|
:parent_category_id
|
|
|
|
def include_parent_category_id?
|
|
parent_category_id.present?
|
|
end
|
|
|
|
def name
|
|
return I18n.t("uncategorized_category_name") if object.uncategorized?
|
|
|
|
translated =
|
|
if (ContentLocalization.show_translated_category?(object, scope))
|
|
object.get_localization&.name
|
|
else
|
|
object.name
|
|
end
|
|
|
|
translated || object.name
|
|
end
|
|
|
|
def description_text
|
|
if object.uncategorized?
|
|
I18n.t("category.uncategorized_description", locale: SiteSetting.default_locale)
|
|
else
|
|
object.description_text
|
|
end
|
|
end
|
|
end
|