mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
FIX: Use user's locale for badge notifications
This commit is contained in:
parent
4d6c99cb3d
commit
25e9aa7653
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user