Skip to content

Commit

Permalink
Merge pull request #1868 from zz9pzza/issue_4100
Browse files Browse the repository at this point in the history
Issue 4100 i18n infrastructure for email
  • Loading branch information
ariana-paris committed May 12, 2015
2 parents b0c5942 + 6448930 commit 4bb9f9a
Show file tree
Hide file tree
Showing 18 changed files with 436 additions and 155 deletions.
2 changes: 1 addition & 1 deletion app/helpers/mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ def to_plain_text(html)
)
end

end # end of MailerHelper
end # end of MailerHelper
2 changes: 1 addition & 1 deletion app/mailers/collection_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def item_added_notification(creation_id, collection_id, item_type)
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] #{@item_type.capitalize} added to " + @collection.title.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
end
end
42 changes: 28 additions & 14 deletions app/mailers/comment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@ class CommentMailer < ActionMailer::Base
def comment_notification(user_id, comment_id)
user = User.find(user_id)
@comment = Comment.find(comment_id)
mail(
:to => user.email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
ensure
I18n.locale = I18n.default_locale
end

# Sends email to an owner of the top-level commentable when a comment is edited
def edited_comment_notification(user_id, comment_id)
user = User.find(user_id)
@comment = Comment.find(comment_id)
mail(
:to => user.email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Edited comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Edited comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
ensure
I18n.locale = I18n.default_locale
end

# Sends email to commenter when a reply is posted to their comment
Expand All @@ -31,9 +39,11 @@ def comment_reply_notification(your_comment_id, comment_id)
@your_comment = Comment.find(your_comment_id)
@comment = Comment.find(comment_id)
mail(
:to => @your_comment.comment_owner_email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Reply to your comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
to: @your_comment.comment_owner_email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Reply to your comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
ensure
I18n.locale = I18n.default_locale
end

# Sends email to commenter when a reply to their comment is edited
Expand All @@ -42,19 +52,23 @@ def edited_comment_reply_notification(your_comment_id, edited_comment_id)
@your_comment = Comment.find(your_comment_id)
@comment = Comment.find(edited_comment_id)
mail(
:to => @your_comment.comment_owner_email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Edited reply to your comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
to: @your_comment.comment_owner_email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Edited reply to your comment on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
ensure
I18n.locale = I18n.default_locale
end

# Sends email to the poster of a comment
def comment_sent_notification(comment_id)
@comment = Comment.find(comment_id)
@noreply = true # don't give reply link to your own comment
mail(
:to => @comment.comment_owner_email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Comment you left on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
to: @comment.comment_owner_email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Comment you left on " + (@comment.ultimate_parent.is_a?(Tag) ? "the tag " : "") + @comment.ultimate_parent.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
ensure
I18n.locale = I18n.default_locale
end

end
24 changes: 16 additions & 8 deletions app/mailers/kudo_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ def kudo_notification(user_id, kudo_id)
kudo = Kudo.find(kudo_id)
@pseud = kudo.pseud
@commentable = kudo.commentable
mail(
:to => user.email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] Kudos on " + @commentable.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] Kudos on " + @commentable.commentable_name.gsub("&gt;", ">").gsub("&lt;", "<")
)
end
ensure
I18n.locale = I18n.default_locale
end

# send a batched-up notification
Expand All @@ -31,10 +35,14 @@ def batch_kudo_notification(user_id, user_kudos)
@commentables << commentable
@kudo_givers[commentable_info] = kudo_givers
end
mail(
:to => user.email,
:subject => "[#{ArchiveConfig.APP_SHORT_NAME}] You've got kudos!"
)
I18n.with_locale(Locale.find(user.preference.preferred_locale).iso) do
mail(
to: user.email,
subject: "[#{ArchiveConfig.APP_SHORT_NAME}] You've got kudos!"
)
end
ensure
I18n.locale = I18n.default_locale
end

end
Loading

0 comments on commit 4bb9f9a

Please sign in to comment.