diff --git a/app/models/badge.rb b/app/models/badge.rb
index 95f2b0daa..e00692e59 100644
--- a/app/models/badge.rb
+++ b/app/models/badge.rb
@@ -322,7 +322,11 @@ SQL
# fields that can not be edited on system badges
def self.protected_system_fields
- [:badge_type_id, :multiple_grant, :target_posts, :show_posts, :query, :trigger, :auto_revoke, :listable]
+ [
+ :badge_type_id, :multiple_grant,
+ :target_posts, :show_posts, :query,
+ :trigger, :auto_revoke, :listable
+ ]
end
def self.trust_level_badge_ids
@@ -386,11 +390,37 @@ SQL
if self[:long_description].present?
self[:long_description]
else
- key = "badges.long_descriptions.#{i18n_name}"
+ key = "badges.#{i18n_name}.long_description"
I18n.t(key, default: '')
end
end
+ def long_description=(val)
+ if val != long_description
+ self[:long_description] = val
+ end
+
+ val
+ end
+
+ def description
+ if self[:description].present?
+ self[:description]
+ else
+ key = "badges.#{i18n_name}.description"
+ I18n.t(key, default: '')
+ end
+ end
+
+ def description=(val)
+ if val != description
+ self[:description] = val
+ end
+
+ val
+ end
+
+
def slug
Slug.for(self.display_name, '-')
end
diff --git a/app/serializers/admin_badge_serializer.rb b/app/serializers/admin_badge_serializer.rb
index 83cccb0c2..535d27d1b 100644
--- a/app/serializers/admin_badge_serializer.rb
+++ b/app/serializers/admin_badge_serializer.rb
@@ -1,3 +1,7 @@
class AdminBadgeSerializer < BadgeSerializer
attributes :query, :trigger, :target_posts, :auto_revoke, :show_posts
+
+ def include_long_description?
+ true
+ end
end
diff --git a/app/serializers/badge_serializer.rb b/app/serializers/badge_serializer.rb
index ede876c90..a726a4dde 100644
--- a/app/serializers/badge_serializer.rb
+++ b/app/serializers/badge_serializer.rb
@@ -12,4 +12,8 @@ class BadgeSerializer < ApplicationSerializer
def include_long_description?
options[:include_long_description]
end
+
+ def name
+ object.display_name
+ end
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 13bc3f377..704e4e3fb 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -2685,6 +2685,7 @@ en:
badge: Badge
display_name: Display Name
description: Description
+ long_description: Long Description
badge_type: Badge Type
badge_grouping: Group
badge_groupings:
@@ -2882,124 +2883,6 @@ en:
name: Other
posting:
name: Posting
- badge:
- editor:
- name: Editor
- description: First post edit
- basic_user:
- name: Basic
- description: Granted all essential community functions
- member:
- name: Member
- description: Granted invitations, group messaging, more likes
- regular:
- name: Regular
- description: Granted recategorize, rename, followed links, wiki, more likes
- leader:
- name: Leader
- description: Granted global edit, pin, close, archive, split and merge, more likes
- welcome:
- name: Welcome
- description: Received a like
- autobiographer:
- name: Autobiographer
- description: Filled out profile information
- anniversary:
- name: Anniversary
- description: Active member for a year, posted at least once
- nice_post:
- name: Nice Reply
- description: Received 10 likes on a reply
- good_post:
- name: Good Reply
- description: Received 25 likes on a reply
- great_post:
- name: Great Reply
- description: Received 50 likes on a reply
- nice_topic:
- name: Nice Topic
- description: Received 10 likes on a topic
- good_topic:
- name: Good Topic
- description: Received 25 likes on a topic
- great_topic:
- name: Great Topic
- description: Received 50 likes on a topic
- nice_share:
- name: Nice Share
- description: Shared a post with 25 unique visitors
- good_share:
- name: Good Share
- description: Shared a post with 300 unique visitors
- great_share:
- name: Great Share
- description: Shared a post with 1000 unique visitors
- first_like:
- name: First Like
- description: Liked a post
- first_flag:
- name: First Flag
- description: Flagged a post
- promoter:
- name: Promoter
- description: Invited a user
- campaigner:
- name: Campaigner
- description: Invited 3 basic users
- champion:
- name: Champion
- description: Invited 5 members
- first_share:
- name: First Share
- description: Shared a post
- first_link:
- name: First Link
- description: Added a link to another topic
- first_quote:
- name: First Quote
- description: Quoted a post
- read_guidelines:
- name: Read Guidelines
- description: Read the community guidelines
- reader:
- name: Reader
- description: Read every reply in a topic with more than 100 replies
- popular_link:
- name: Popular Link
- description: Posted an external link with 50 clicks
- hot_link:
- name: Hot Link
- description: Posted an external link with 300 clicks
- famous_link:
- name: Famous Link
- description: Posted an external link with 1000 clicks
- appreciated:
- name: Appreciated
- description: Received 1 like on 20 posts
- respected:
- name: Respected
- description: Received 2 likes on 100 posts
- admired:
- name: Admired
- description: Received 5 likes on 300 posts
- out_of_love:
- name: Out of Love
- description: Used 50 likes in a day
- higher_love:
- name: Higher Love
- description: Used 50 likes in a day 5 times
- crazy_in_love:
- name: Crazy in Love
- description: Used 50 likes in a day 20 times
- thank_you:
- name: Thank You
- description: Has 20 liked posts and gave 10 likes
- gives_back:
- name: Gives Back
- description: Has 100 liked posts and gave 100 likes
- empathetic:
- name: Empathetic
- description: Has 500 liked posts and gave 1000 likes
google_search: |
badges:
- long_descriptions:
- autobiographer: |
- This badge is granted for filling out your user profile and selecting a profile picture. Letting the community know a bit more about who you are and what you're interested in makes for a better, more connected community. Join us!
- first_like: |
- This badge is granted the first time you like a post using the :heart: button. Liking posts is a great way to let your fellow community members know that what they posted was interesting, useful, cool, or fun. Share the love!
- first_link: |
- This badge is granted the first time you add a link to another topic. Linking topics helps fellow readers find interesting related conversations, by showing the connections between topics in both directions. Link freely!
- first_quote: |
- This badge is granted the first time you quote a post in your reply. Quoting relevant sections of earlier posts in your reply helps keep discussions focused and on topic. And it's easy: you can quickly quote by highlighting a section of any post and using the Quote Reply button that appears near the selection. Quote generously!
- first_share: |
- This badge is granted the first time you share a link to a reply or topic using the share button. Sharing links is a great way to show off interesting discussions with the rest of the world and grow your community.
- read_guidelines: |
- This badge is granted for reading the community guidelines. Following and sharing these simple guidelines helps build a safe, fun, and sustainable community for everyone. Always remember there's another human being, one very much like yourself, on the other side of that screen. Be nice!
- reader: |
- This badge is granted the first time you read a long topic with more than 100 replies. Reading a conversation closely helps you follow the discussion, understand different viewpoints, and leads to more interesting conversations. The more you read, the better the conversation gets. As we like to say, Reading is Fundamental! :slight_smile:
- editor: |
+ editor:
+ name: Editor
+ description: First post edit
+ long_description: |
This badge is granted the first time you edit one of your posts. While you won't be able to edit your posts forever, editing is always a good idea — you can improve your posts, fix small mistakes, or add anything you missed when you originally posted. Edit to make your posts even better!
- first_flag: |
- This badge is granted the first time you flag a post. Flagging is how we all help keep this a clean, well lit place for everyone. If you notice any posts that require moderator attention for any reason please don't hesitate to flag. You can also flag to send personal messages to fellow users if you see an issue with their post. If you see a problem, :flag_black: flag it!
- welcome: |
- This badge is granted when you receive your first like on a post. Congratulations, you've posted something that your fellow community members found interesting, cool, or useful!
- anniversary: |
- This badge is granted when you've been a member for a year with at least one post in that year. Thank you for sticking around and contributing to our community. We couldn't do it without you.
- nice_share: |
- This badge is granted for sharing a link that was clicked by 25 outside visitors. Thanks for spreading the word about our discussions, and this community.
- good_share: |
- This badge is granted for sharing a link that was clicked by 300 outside visitors. Good work! You've shown off a great discussion to a bunch of new people and helped this community grow.
- great_share: |
- This badge is granted for sharing a link that was clicked by 1000 outside visitors. Wow! You've promoted an interesting discussion to a huge new audience, and helped us grow our community in a big way!
- nice_topic: |
- This badge is granted when your topic gets 10 likes. Hey, you started an interesting conversation that the community enjoyed!
- nice_post: |
- This badge is granted when your reply gets 10 likes. Your reply really made an impression on the community and helped move the conversation forward!
- good_topic: |
- This badge is granted when your topic gets 25 likes. You launched a vibrant conversation that the community rallied around and loved!
- good_post: |
- This badge is granted when your reply gets 25 likes. Your reply was exceptional and made the conversation a whole lot better for everyone!
- great_topic: |
- This badge is granted when your topic gets 50 likes. You kicked off a fascinating conversation and the community enjoyed the dynamic discussion that resulted!
- great_post: |
- This badge is granted when your reply gets 50 likes. Wow! Your reply was inspiring, fascinating, hilarious, or insightful and the community loved it.
- appreciated: |
- This badge is granted when you receive at least one like on 20 different posts. The community is enjoying your contributions to the conversations here!
- respected: |
- This badge is granted when you receive at least 2 likes on 100 different posts. The community is growing to respect your many contributions to the conversations here.
- admired: |
- This badge is granted when you receive at least 5 likes on 300 different posts. Wow! The community admires your frequent, high quality contributions to the conversations here.
- out_of_love: |
- This badge is granted when you use all 50 of your daily likes. Remembering to take a moment and like the posts you enjoy and appreciate encourages your fellow community members to create even more great discussions in the future.
- higher_love: |
- This badge is granted when you use all 50 of your daily likes for 5 days. Thanks for taking the time actively encouraging the best conversations every day!
- crazy_in_love: |
- This badge is granted when you use all 50 of your daily likes for 20 days. Wow! You're a model of regularly encouraging your fellow community members!
- promoter: |
- This badge is granted when you invite someone to join the community via the invite button on your user page, or at the bottom of a topic. Inviting friends who might be interested in specific discussions is an great way to introduce new people to our community, so thanks!
- campaigner: |
- This badge is granted when you've invited 3 people who subsequently spent enough time on the site to become basic users. A vibrant community needs a regular infusion of newcomers who regularly participate and add new voices to the conversationss.
- champion: |
- This badge is granted when you've invited 5 people who subsequently spent enough time on the site to become full members. Wow! Thanks for expanding the diversity of our community with new members!
- thank_you: |
- This badge is granted when you've received 20 likes on your posts and have given 10 or more likes in return. When someone likes your posts, you find the time to like what other people are posting in return.
- gives_back: |
- This badge is granted when you've received 100 likes and have given 100 or more likes in return. Thanks for paying it forward, and liking in return!
- empathetic: |
- This badge is granted when you've received 500 likes and have given 1000 or more likes in return. Wow! You're a model of generosity and mutual love :two_hearts:.
- basic_user: |
+ basic_user:
+ name: Basic
+ description: Granted all essential community functions
+ long_description: |
This badge is granted when you reach trust level 1. Thanks for sticking around a little while and reading a few topics to learn what our community is about. Your new user restrictions have been lifted; you've been granted all essential community abilities, such as personal messaging, flagging, wiki editing, and the ability to post multiple images and links.
- member: |
+ member:
+ name: Member
+ description: Granted invitations, group messaging, more likes
+ long_description: |
This badge is granted when you reach trust level 2. Thanks for participating over a period of weeks to truly join our community. You can now send invitations from your user page or individual topics, create group personal messages, and have a few more likes per day.
- regular: |
+ regular:
+ name: Regular
+ description: Granted recategorize, rename, followed links, wiki, more likes
+ long_description: |
This badge is granted when you reach trust level 3. Thanks for being a regular part of our community over a period of months. You're now one of the most active readers, and a reliable contributor that makes our community great. You can now recategorize and rename topics, take advantage of more powerful spam flags, access a private lounge area, and you'll also get lots more likes per day.
- leader: |
+ leader:
+ name: Leader
+ description: Granted global edit, pin, close, archive, split and merge, more likes
+ long_description: |
This badge is granted when you reach trust level 4. You're a leader in this community as selected by staff, and you set a positive example for the rest of the community in your actions and words here. You have the ability to edit all posts, take common topic moderator actions such as pin, close, unlist, archive, split, and merge, and you have tons of likes per day.
- popular_link: |
+ welcome:
+ name: Welcome
+ description: Received a like
+ long_description: |
+ This badge is granted when you receive your first like on a post. Congratulations, you've posted something that your fellow community members found interesting, cool, or useful!
+ autobiographer:
+ name: Autobiographer
+ description: Filled out profile information
+ long_description: |
+ This badge is granted for filling out your user profile and selecting a profile picture. Letting the community know a bit more about who you are and what you're interested in makes for a better, more connected community. Join us!
+ anniversary:
+ name: Anniversary
+ description: Active member for a year, posted at least once
+ long_description: |
+ This badge is granted when you've been a member for a year with at least one post in that year. Thank you for sticking around and contributing to our community. We couldn't do it without you.
+ nice_post:
+ name: Nice Reply
+ description: Received 10 likes on a reply
+ long_description: |
+ This badge is granted when your reply gets 10 likes. Your reply really made an impression on the community and helped move the conversation forward!
+ good_post:
+ name: Good Reply
+ description: Received 25 likes on a reply
+ long_description: |
+ This badge is granted when your reply gets 25 likes. Your reply was exceptional and made the conversation a whole lot better for everyone!
+ great_post:
+ name: Great Reply
+ description: Received 50 likes on a reply
+ long_description: |
+ This badge is granted when your reply gets 50 likes. Wow! Your reply was inspiring, fascinating, hilarious, or insightful and the community loved it.
+ nice_topic:
+ name: Nice Topic
+ description: Received 10 likes on a topic
+ long_description: |
+ This badge is granted when your topic gets 10 likes. Hey, you started an interesting conversation that the community enjoyed!
+ good_topic:
+ name: Good Topic
+ description: Received 25 likes on a topic
+ long_description: |
+ This badge is granted when your topic gets 25 likes. You launched a vibrant conversation that the community rallied around and loved!
+ great_topic:
+ name: Great Topic
+ description: Received 50 likes on a topic
+ long_description: |
+ This badge is granted when your topic gets 50 likes. You kicked off a fascinating conversation and the community enjoyed the dynamic discussion that resulted!
+ nice_share:
+ name: Nice Share
+ description: Shared a post with 25 unique visitors
+ long_description: |
+ This badge is granted for sharing a link that was clicked by 25 outside visitors. Thanks for spreading the word about our discussions, and this community.
+ good_share:
+ name: Good Share
+ description: Shared a post with 300 unique visitors
+ long_description: |
+ This badge is granted for sharing a link that was clicked by 300 outside visitors. Good work! You've shown off a great discussion to a bunch of new people and helped this community grow.
+ great_share:
+ name: Great Share
+ description: Shared a post with 1000 unique visitors
+ long_description: |
+ This badge is granted for sharing a link that was clicked by 1000 outside visitors. Wow! You've promoted an interesting discussion to a huge new audience, and helped us grow our community in a big way!
+ first_like:
+ name: First Like
+ description: Liked a post
+ long_description: |
+ This badge is granted the first time you like a post using the :heart: button. Liking posts is a great way to let your fellow community members know that what they posted was interesting, useful, cool, or fun. Share the love!
+ first_flag:
+ name: First Flag
+ description: Flagged a post
+ long_description: |
+ This badge is granted the first time you flag a post. Flagging is how we all help keep this a clean, well lit place for everyone. If you notice any posts that require moderator attention for any reason please don't hesitate to flag. You can also flag to send personal messages to fellow users if you see an issue with their post. If you see a problem, :flag_black: flag it!
+ promoter:
+ name: Promoter
+ description: Invited a user
+ long_description: |
+ This badge is granted when you invite someone to join the community via the invite button on your user page, or at the bottom of a topic. Inviting friends who might be interested in specific discussions is an great way to introduce new people to our community, so thanks!
+ campaigner:
+ name: Campaigner
+ description: Invited 3 basic users
+ long_description: |
+ This badge is granted when you've invited 3 people who subsequently spent enough time on the site to become basic users. A vibrant community needs a regular infusion of newcomers who regularly participate and add new voices to the conversationss.
+ champion:
+ name: Champion
+ description: Invited 5 members
+ long_description: |
+ This badge is granted when you've invited 5 people who subsequently spent enough time on the site to become full members. Wow! Thanks for expanding the diversity of our community with new members!
+ first_share:
+ name: First Share
+ description: Shared a post
+ long_description: |
+ This badge is granted the first time you share a link to a reply or topic using the share button. Sharing links is a great way to show off interesting discussions with the rest of the world and grow your community.
+ first_link:
+ name: First Link
+ description: Added a link to another topic
+ long_description: |
+ This badge is granted the first time you add a link to another topic. Linking topics helps fellow readers find interesting related conversations, by showing the connections between topics in both directions. Link freely!
+ first_quote:
+ name: First Quote
+ description: Quoted a post
+ long_description: |
+ This badge is granted the first time you quote a post in your reply. Quoting relevant sections of earlier posts in your reply helps keep discussions focused and on topic. And it's easy: you can quickly quote by highlighting a section of any post and using the Quote Reply button that appears near the selection. Quote generously!
+ read_guidelines:
+ name: Read Guidelines
+ description: Read the community guidelines
+ long_description: |
+ This badge is granted for reading the community guidelines. Following and sharing these simple guidelines helps build a safe, fun, and sustainable community for everyone. Always remember there's another human being, one very much like yourself, on the other side of that screen. Be nice!
+ reader:
+ name: Reader
+ description: Read every reply in a topic with more than 100 replies
+ long_description: |
+ This badge is granted the first time you read a long topic with more than 100 replies. Reading a conversation closely helps you follow the discussion, understand different viewpoints, and leads to more interesting conversations. The more you read, the better the conversation gets. As we like to say, Reading is Fundamental! :slight_smile:
+ popular_link:
+ name: Popular Link
+ description: Posted an external link with 50 clicks
+ long_description: |
This badge is granted when a link you shared gets 50 clicks. Thanks for posting a useful link that added interesting context to the conversation!
- hot_link: |
+ hot_link:
+ name: Hot Link
+ description: Posted an external link with 300 clicks
+ long_description: |
This badge is granted when a link you shared gets 300 clicks. Thanks for posting a fascinating link that drove the conversation forward and illuminated the discussion!
- famous_link: |
+ famous_link:
+ name: Famous Link
+ description: Posted an external link with 1000 clicks
+ long_description: |
This badge is granted when a link you shared gets 1000 clicks. Wow! You posted a link that significantly improved the conversation by addding essential detail, context, and information. Great work!
-
+ appreciated:
+ name: Appreciated
+ description: Received 1 like on 20 posts
+ long_description: |
+ This badge is granted when you receive at least one like on 20 different posts. The community is enjoying your contributions to the conversations here!
+ respected:
+ name: Respected
+ description: Received 2 likes on 100 posts
+ long_description: |
+ This badge is granted when you receive at least 2 likes on 100 different posts. The community is growing to respect your many contributions to the conversations here.
+ admired:
+ name: Admired
+ description: Received 5 likes on 300 posts
+ long_description: |
+ This badge is granted when you receive at least 5 likes on 300 different posts. Wow! The community admires your frequent, high quality contributions to the conversations here.
+ out_of_love:
+ name: Out of Love
+ description: Used 50 likes in a day
+ long_description: |
+ This badge is granted when you use all 50 of your daily likes. Remembering to take a moment and like the posts you enjoy and appreciate encourages your fellow community members to create even more great discussions in the future.
+ higher_love:
+ name: Higher Love
+ description: Used 50 likes in a day 5 times
+ long_description: |
+ This badge is granted when you use all 50 of your daily likes for 5 days. Thanks for taking the time actively encouraging the best conversations every day!
+ crazy_in_love:
+ name: Crazy in Love
+ description: Used 50 likes in a day 20 times
+ long_description: |
+ This badge is granted when you use all 50 of your daily likes for 20 days. Wow! You're a model of regularly encouraging your fellow community members!
+ thank_you:
+ name: Thank You
+ description: Has 20 liked posts and gave 10 likes
+ long_description: |
+ This badge is granted when you've received 20 likes on your posts and have given 10 or more likes in return. When someone likes your posts, you find the time to like what other people are posting in return.
+ gives_back:
+ name: Gives Back
+ description: Has 100 liked posts and gave 100 likes
+ long_description: |
+ This badge is granted when you've received 100 likes and have given 100 or more likes in return. Thanks for paying it forward, and liking in return!
+ empathetic:
+ name: Empathetic
+ description: Has 500 liked posts and gave 1000 likes
+ long_description: |
+ This badge is granted when you've received 500 likes and have given 1000 or more likes in return. Wow! You're a model of generosity and mutual love :two_hearts:.
admin_login:
success: "Email Sent"
diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb
index f5ff32d46..e438ac3b4 100644
--- a/spec/models/badge_spec.rb
+++ b/spec/models/badge_spec.rb
@@ -14,5 +14,34 @@ describe Badge do
expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false
end
+ it 'auto translates name' do
+ badge = Badge.find_by_name("Basic User")
+ name_english = badge.name
+
+ I18n.locale = 'fr'
+
+ expect(badge.display_name).not_to eq(name_english)
+ end
+
+ it 'handles changes on badge description and long description correctly for system badges' do
+ badge = Badge.find_by_name("Basic User")
+ badge.description = badge.description.dup
+ badge.long_description = badge.long_description.dup
+ badge.save
+ badge.reload
+
+ expect(badge[:description]).to eq(nil)
+ expect(badge[:long_description]).to eq(nil)
+
+ badge.description = "testing"
+ badge.long_description = "testing it"
+
+ badge.save
+ badge.reload
+
+ expect(badge[:description]).to eq("testing")
+ expect(badge[:long_description]).to eq("testing it")
+ end
+
end
diff --git a/test/javascripts/models/badge-test.js.es6 b/test/javascripts/models/badge-test.js.es6
index a91b49ecd..0b92f88ce 100644
--- a/test/javascripts/models/badge-test.js.es6
+++ b/test/javascripts/models/badge-test.js.es6
@@ -9,32 +9,6 @@ test('newBadge', function() {
ok(!badge2.get('newBadge'), "badges with ids are not new");
});
-test('displayName', function() {
- const badge1 = Badge.create({id: 1, name: "Test Badge 1"});
- equal(badge1.get('displayName'), "Test Badge 1", "falls back to the original name in the absence of a translation");
-
- sandbox.stub(I18n, "t").returnsArg(0);
- const badge2 = Badge.create({id: 2, name: "Test Badge 2"});
- equal(badge2.get('displayName'), "badges.badge.test_badge_2.name", "uses translation when available");
-});
-
-test('translatedDescription', function() {
- const badge1 = Badge.create({id: 1, name: "Test Badge 1", description: "TEST"});
- equal(badge1.get('translatedDescription'), null, "returns null when no translation exists");
-
- const badge2 = Badge.create({id: 2, name: "Test Badge 2 **"});
- sandbox.stub(I18n, "t").returns("description translation");
- equal(badge2.get('translatedDescription'), "description translation", "users translated description");
-});
-
-test('displayDescription', function() {
- const badge1 = Badge.create({id: 1, name: "Test Badge 1", description: "TEST"});
- equal(badge1.get('displayDescription'), "TEST", "returns original description when no translation exists");
-
- const badge2 = Badge.create({id: 2, name: "Test Badge 2 **"});
- sandbox.stub(I18n, "t").returns("description translation");
- equal(badge2.get('displayDescription'), "description translation", "users translated description");
-});
test('createFromJson array', function() {
const badgesJson = {"badge_types":[{"id":6,"name":"Silver 1"}],"badges":[{"id":1126,"name":"Badge 1","description":null,"badge_type_id":6}]};