Merge pull request #3808 from gschlager/i18n-patch4

FIX: Use translated badge name and slug within notifications
This commit is contained in:
Régis Hanol 2015-09-24 09:46:34 +02:00
commit f29cd5f192
4 changed files with 40 additions and 34 deletions

View File

@ -22,8 +22,14 @@ export default Ember.Component.extend({
const it = this.get('notification');
const badgeId = it.get("data.badge_id");
if (badgeId) {
var badgeSlug = it.get("data.badge_slug");
if (!badgeSlug) {
const badgeName = it.get("data.badge_name");
return Discourse.getURL('/badges/' + badgeId + '/' + badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase());
badgeSlug = badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase();
}
return Discourse.getURL('/badges/' + badgeId + '/' + badgeSlug);
}
const topicId = it.get('topic_id');

View File

@ -329,12 +329,38 @@ SQL
Badge.find_each(&:reset_grant_count!)
end
def display_name
if self.system?
key = "admin_js.badges.badge.#{i18n_name}.name"
I18n.t(key, default: self.name)
else
self.name
end
end
def long_description
if self[:long_description].present?
self[:long_description]
else
key = "badges.long_descriptions.#{i18n_name}"
I18n.t(key, default: '')
end
end
def slug
Slug.for(self.display_name, '-')
end
protected
def ensure_not_system
unless id
self.id = [Badge.maximum(:id) + 1, 100].max
end
end
def i18n_name
self.name.downcase.gsub(' ', '_')
end
end
# == Schema Information

View File

@ -12,32 +12,4 @@ class BadgeSerializer < ApplicationSerializer
def include_long_description?
options[:include_long_description]
end
def long_description
if object.long_description.present?
object.long_description
else
key = "badges.long_descriptions.#{i18n_name}"
if I18n.exists?(key)
I18n.t(key)
else
""
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

View File

@ -41,13 +41,15 @@ class BadgeGranter
end
if SiteSetting.enable_badges?
I18n.with_locale(@user.effective_locale) do
notification = @user.notifications.create(
notification_type: Notification.types[:granted_badge],
data: { badge_id: @badge.id, badge_name: @badge.name }.to_json)
data: { badge_id: @badge.id, badge_name: @badge.display_name, badge_slug: @badge.slug }.to_json)
user_badge.update_attributes notification_id: notification.id
end
end
end
end
user_badge
end