mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: Use translated badge names for slugs
FIX: Use configured slug generater method for badges
This commit is contained in:
parent
0717517332
commit
4cb070f28c
2 changed files with 18 additions and 3 deletions
|
@ -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")
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue