From 00cca370ad97fc7a7a88e926ae6bcee64097317f Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 1 Mar 2011 11:03:58 -0800 Subject: [PATCH] Add translation key method, should be replaced with separate partials. --- app/helpers/notifications_helper.rb | 14 ++++++-------- app/models/notifications/also_commented.rb | 3 +++ app/models/notifications/comment_on_post.rb | 3 +++ app/models/notifications/mentioned.rb | 3 +++ app/models/notifications/new_request.rb | 3 +++ app/models/notifications/request_accepted.rb | 3 +++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index b98db63be..788d7ab03 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -1,33 +1,31 @@ module NotificationsHelper def object_link(note) - target_type = note.class - case target_type - when Notifications::Mentioned + target_type = note.translation_key + if note.instance_of?(Notifications::Mentioned) post = Mention.find(note.target_id).post if post "#{translation(target_type)} #{link_to t('notifications.post'), object_path(post)}".html_safe else "#{translation(target_type)} #{t('notifications.deleted')} #{t('notifications.post')}" end - when Notifications::RequestAccepted + elsif note.instance_of?(Notifications::RequestAccepted) translation(target_type) - when Notifications::NewRequest + elsif note.instance_of?(Notifications::NewRequest) translation(target_type) - when Notifications::CommentOnPost + elsif note.instance_of?(Notifications::CommentOnPost) post = Post.where(:id => note.target_id).first if post "#{translation(target_type)} #{link_to t('notifications.post'), object_path(post)}".html_safe else "#{translation(target_type)} #{t('notifications.deleted')} #{t('notifications.post')}" end - when Notifications::AlsoCommented + elsif note.instance_of?(Notifications::AlsoCommented) post = Post.where(:id => note.target_id).first if post "#{translation(target_type, post.person.name)} #{link_to t('notifications.post'), object_path(post)}".html_safe else t('notifications.also_commented_deleted') end - else end end diff --git a/app/models/notifications/also_commented.rb b/app/models/notifications/also_commented.rb index 16d568013..f31341cf5 100644 --- a/app/models/notifications/also_commented.rb +++ b/app/models/notifications/also_commented.rb @@ -2,4 +2,7 @@ class Notifications::AlsoCommented < Notification def mail_job Job::MailAlsoCommented end + def translation_key + 'also_commented' + end end diff --git a/app/models/notifications/comment_on_post.rb b/app/models/notifications/comment_on_post.rb index cbadc7813..096b9d885 100644 --- a/app/models/notifications/comment_on_post.rb +++ b/app/models/notifications/comment_on_post.rb @@ -2,4 +2,7 @@ class Notifications::CommentOnPost < Notification def mail_job Job::MailCommentOnPost end + def translation_key + 'comment_on_post' + end end diff --git a/app/models/notifications/mentioned.rb b/app/models/notifications/mentioned.rb index 471b3f028..34cdb44c0 100644 --- a/app/models/notifications/mentioned.rb +++ b/app/models/notifications/mentioned.rb @@ -2,4 +2,7 @@ class Notifications::Mentioned < Notification def mail_job Job::MailMentioned end + def translation_key + 'mentioned' + end end diff --git a/app/models/notifications/new_request.rb b/app/models/notifications/new_request.rb index 3a5ed14f8..0f80bd656 100644 --- a/app/models/notifications/new_request.rb +++ b/app/models/notifications/new_request.rb @@ -2,4 +2,7 @@ class Notifications::NewRequest < Notification def mail_job Job::MailRequestReceived end + def translation_key + 'new_request' + end end diff --git a/app/models/notifications/request_accepted.rb b/app/models/notifications/request_accepted.rb index 0ed74560c..226c57f7a 100644 --- a/app/models/notifications/request_accepted.rb +++ b/app/models/notifications/request_accepted.rb @@ -2,4 +2,7 @@ class Notifications::RequestAccepted < Notification def mail_job Job::MailRequestAcceptance end + def translation_key + 'request_accepted' + end end