discourse/app/serializers/concerns/basic_category_attributes.rb
Natalie Tay d177263591
FIX: Do not return translated name when editing category (#35297)
The inheritance chain is for category serializers is
```
  CategorySerializer -> SiteCategorySerializer -> BasicCategorySerializer
```

The BasicCategorySerializer includes BasicCategoryAttributes (provides
untranslated name/description), the SiteCategorySerializer overrides
name and description to provide translated versions, the
CategorySerializer tries to include BasicCategoryAttributes but this
does nothing because the module is already in the ancestor chain from
BasicCategorySerializer. In Ruby, including a module that's already in
the ancestor chain has no effect.

This commit fixes the issue
2025-10-09 17:46:02 +08:00

19 lines
428 B
Ruby
Vendored

# frozen_string_literal: true
module BasicCategoryAttributes
def category_name
if object.uncategorized?
I18n.t("uncategorized_category_name", locale: SiteSetting.default_locale)
else
object.name
end
end
def category_description
if object.uncategorized?
I18n.t("category.uncategorized_description", locale: SiteSetting.default_locale)
else
object.description
end
end
end