diff --git a/app/assets/javascripts/discourse/routes/badges-show.js.es6 b/app/assets/javascripts/discourse/routes/badges-show.js.es6 index 5f835d76d..42bc89e9a 100644 --- a/app/assets/javascripts/discourse/routes/badges-show.js.es6 +++ b/app/assets/javascripts/discourse/routes/badges-show.js.es6 @@ -12,7 +12,7 @@ export default Discourse.Route.extend({ serialize(model) { return { id: model.get("id"), - slug: model.get("name").replace(/[^A-Za-z0-9_]+/g, "-").toLowerCase() + slug: model.get("slug") }; }, diff --git a/app/serializers/badge_serializer.rb b/app/serializers/badge_serializer.rb index 415404d5c..8223ecd78 100644 --- a/app/serializers/badge_serializer.rb +++ b/app/serializers/badge_serializer.rb @@ -1,7 +1,7 @@ class BadgeSerializer < ApplicationSerializer attributes :id, :name, :description, :grant_count, :allow_title, :multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id, - :system, :long_description + :system, :long_description, :slug has_one :badge_type @@ -17,7 +17,7 @@ class BadgeSerializer < ApplicationSerializer if object.long_description.present? object.long_description else - key = "badges.long_descriptions.#{object.name.downcase.gsub(" ", "_")}" + key = "badges.long_descriptions.#{i18n_name}" if I18n.exists?(key) I18n.t(key) else @@ -25,4 +25,19 @@ class BadgeSerializer < ApplicationSerializer end end end + + def slug + Slug.for(display_name, '') + end + + private + + def i18n_name + object.name.downcase.gsub(' ', '_') + end + + def display_name + key = "admin_js.badges.badge.#{i18n_name}.name" + I18n.t(key, default: object.name) + end end