FIX: Use user's locale for badge notifications

This commit is contained in:
Gerhard Schlager 2015-09-23 22:52:43 +02:00
parent 4d6c99cb3d
commit 25e9aa7653
3 changed files with 32 additions and 32 deletions

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,10 +41,12 @@ class BadgeGranter
end
if SiteSetting.enable_badges?
notification = @user.notifications.create(
notification_type: Notification.types[:granted_badge],
data: { badge_id: @badge.id, badge_name: @badge.name }.to_json)
user_badge.update_attributes notification_id: notification.id
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.display_name }.to_json)
user_badge.update_attributes notification_id: notification.id
end
end
end
end