mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
Merge pull request #3791 from gschlager/i18n-patch2
FIX: Slugs for badges
This commit is contained in:
commit
ae5134f88e
2 changed files with 18 additions and 3 deletions
|
@ -12,7 +12,7 @@ export default Discourse.Route.extend({
|
||||||
serialize(model) {
|
serialize(model) {
|
||||||
return {
|
return {
|
||||||
id: model.get("id"),
|
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
|
class BadgeSerializer < ApplicationSerializer
|
||||||
attributes :id, :name, :description, :grant_count, :allow_title,
|
attributes :id, :name, :description, :grant_count, :allow_title,
|
||||||
:multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id,
|
:multiple_grant, :icon, :image, :listable, :enabled, :badge_grouping_id,
|
||||||
:system, :long_description
|
:system, :long_description, :slug
|
||||||
|
|
||||||
has_one :badge_type
|
has_one :badge_type
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class BadgeSerializer < ApplicationSerializer
|
||||||
if object.long_description.present?
|
if object.long_description.present?
|
||||||
object.long_description
|
object.long_description
|
||||||
else
|
else
|
||||||
key = "badges.long_descriptions.#{object.name.downcase.gsub(" ", "_")}"
|
key = "badges.long_descriptions.#{i18n_name}"
|
||||||
if I18n.exists?(key)
|
if I18n.exists?(key)
|
||||||
I18n.t(key)
|
I18n.t(key)
|
||||||
else
|
else
|
||||||
|
@ -25,4 +25,19 @@ class BadgeSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue