Merge pull request #3791 from gschlager/i18n-patch2

FIX: Slugs for badges
This commit is contained in:
Régis Hanol 2015-09-23 11:35:38 +02:00
commit ae5134f88e
2 changed files with 18 additions and 3 deletions

View File

@ -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")
};
},

View File

@ -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