mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
Merge pull request #3808 from gschlager/i18n-patch4
FIX: Use translated badge name and slug within notifications
This commit is contained in:
commit
f29cd5f192
|
@ -22,8 +22,14 @@ export default Ember.Component.extend({
|
|||
const it = this.get('notification');
|
||||
const badgeId = it.get("data.badge_id");
|
||||
if (badgeId) {
|
||||
const badgeName = it.get("data.badge_name");
|
||||
return Discourse.getURL('/badges/' + badgeId + '/' + badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase());
|
||||
var badgeSlug = it.get("data.badge_slug");
|
||||
|
||||
if (!badgeSlug) {
|
||||
const badgeName = it.get("data.badge_name");
|
||||
badgeSlug = badgeName.replace(/[^A-Za-z0-9_]+/g, '-').toLowerCase();
|
||||
}
|
||||
|
||||
return Discourse.getURL('/badges/' + badgeId + '/' + badgeSlug);
|
||||
}
|
||||
|
||||
const topicId = it.get('topic_id');
|
||||
|
|
|
@ -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, badge_slug: @badge.slug }.to_json)
|
||||
user_badge.update_attributes notification_id: notification.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user