From 9506b1ce107f8bca6b4990fe87b02fe109976186 Mon Sep 17 00:00:00 2001 From: chaica Date: Tue, 5 Jul 2016 17:02:14 +0200 Subject: [PATCH] I18n moderations (#301) * translate moderation view, controller and model * support for i18n in the moderation controller * support for i18n in the moderation model - use interpolation for variables inside strings * support for i18n in controller model - localize time and date string format for printing time and date of the moderation action --- app/controllers/moderations_controller.rb | 2 +- app/models/moderation.rb | 19 ++++++-------- app/views/moderations/index.html.erb | 30 +++++++++++------------ config/locales/en.yml | 29 ++++++++++++++++++++++ config/locales/fr.yml | 28 +++++++++++++++++++++ 5 files changed, 81 insertions(+), 27 deletions(-) diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index bd816e5..b15f94e 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -1,6 +1,6 @@ class ModerationsController < ApplicationController def index - @title = "Moderation Log" + @title = t('.moderationlogtitle') @page = params[:page] ? params[:page].to_i : 0 @pages = (Moderation.count / 50).ceil diff --git a/app/models/moderation.rb b/app/models/moderation.rb index 3214daf..49426ee 100644 --- a/app/models/moderation.rb +++ b/app/models/moderation.rb @@ -17,32 +17,29 @@ class Moderation < ActiveRecord::Base if self.story m.recipient_user_id = self.story.user_id - m.subject = "Your story has been edited by " << - (self.is_from_suggestions? ? "user suggestions" : "a moderator") - m.body = "Your story [#{self.story.title}](" << - "#{self.story.comments_url}) has been edited with the following " << - "changes:\n" << + m.subject = I18n.t('models.moderation.storyeditedby') << + (self.is_from_suggestions? ? I18n.t('models.moderation.usersuggestions') : I18n.t('models.moderation.amoderator')) + m.body = I18n.t('models.moderation.storyeditedfor', :title=> "#{self.story.title}", :url=> "#{self.story.comments_url}") << "\n" << "> *#{self.action}*\n" if self.reason.present? m.body << "\n" << - "The reason given:\n" << + I18n.t('models.moderation.reasongiven') << "\n" << "> *#{self.reason}*\n" end elsif self.comment m.recipient_user_id = self.comment.user_id - m.subject = "Your comment has been moderated" - m.body = "Your comment on [#{self.comment.story.title}](" << - "#{self.comment.story.comments_url}) has been moderated:\n" << + m.subject = I18n.t('models.moderation.commentmoderated') + m.body = I18n.t('models.moderation.commentmoderatedwhy', :title=> "#{self.comment.story.title}", :url=> "#{self.comment.story.comments_url}") << "\n" << "> *#{self.comment.comment}*\n" if self.reason.present? m.body << "\n" << - "The reason given:\n" << + I18n.t('models.moderation.reasongiven') << "\n" << "> *#{self.reason}*\n" end @@ -53,7 +50,7 @@ class Moderation < ActiveRecord::Base end m.body << "\n" << - "*This is an automated message.*" + I18n.t('models.moderation.automatedmessage') m.save end diff --git a/app/views/moderations/index.html.erb b/app/views/moderations/index.html.erb index 5f7cd72..002384d 100644 --- a/app/views/moderations/index.html.erb +++ b/app/views/moderations/index.html.erb @@ -1,49 +1,49 @@
- Moderation Log + <%= t('.moderationlogtitle') %>
- - - + + + <% bit = 0 %> <% @moderations.each do |mod| %> - + "> - + <% if mod.reason.present? %> - + <% end %> <% bit = (bit == 1 ? 0 : 1) %> @@ -53,7 +53,7 @@ diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c503fe..9e7ce35 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,19 @@ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: + time: + formats: + default: "%Y-%m-%d %H:%M:%S" + models: + moderation: + storyeditedby: "Your story has been edited by " + usersuggestions: "user suggestions" + amoderator: "a moderator" + storyeditedfor: "Your story [%{title}](%{url}) has been edited with the following changes:\n" + reasongiven: "The reason given:\n" + commentmoderated: "Your comment has been moderated" + commentmoderatedwhy: "Your comment on [%{title}](%{url}) has been moderated:\n" + automatedmessage: "*This is an automated message.*" layouts: application: homelink: "Home" @@ -24,3 +37,19 @@ en: hatrequestlink: "Hat Requests" privacylink: "Privacy" aboutlink: "About" + moderations: + index: + moderationlogtitle: "Moderation Log" + datecolumn: "Date/Time" + moderatorcolumn: "Moderator" + reasoncolumn: "Story/Comment/User, Action, Reason" + storyline: "Story" + commentline: "Comment by" + commenton: "on" + user: "User" + users: "Users" + deleted: "Deleted" + actionline: "Action" + reasonline: "Reason" + page: "Page" + diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b5f1314..36934b0 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -2,6 +2,19 @@ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. fr: + time: + formats: + default: "%d-%m-%Y %H:%M:%S" + models: + moderation: + storyeditedby: "Votre info a été éditée par " + usersuggestions: "suggestions d'utilisateur" + amoderator: "un modérateur" + storyeditedfor: "Votre info [%{title}](%{url}) a été éditée avec les changements suivants :\n" + reasongiven: "La raison donnée :\n" + commentmoderated: "Votre commentaire a été modéré" + commentmoderatedwhy: "Votre commentaire sur [%{title}](%{url}) a été modéré :\n" + automatedmessage: "*Ceci est un message automatique.*" layouts: application: homelink: "Accueil" @@ -24,3 +37,18 @@ fr: hatrequestlink: "Porter le chapeau" privacylink: "Confidentialité" aboutlink: "À propos" + moderations: + index: + moderationlogtitle: "Journal de modération" + datecolumn: "Date/Heure" + moderatorcolumn: "Moderateur" + reasoncolumn: "Histoire/Commentaire/Utilisateur, Action, Raison" + storyline: "Info" + commentline: "Commentaire par" + commenton: "sur" + user: "Utilisateur" + users: "Utilisateurs" + deleted: "Supprimé" + actionline: "Action" + reasonline: "Raison" + page: "Page"
Date/TimeModeratorStory/Comment/User, Action, Reason<%= t('.datecolumn') %><%= t('.moderatorcolumn') %><%= t('.reasoncolumn') %>
<%= mod.created_at.strftime("%Y-%m-%d %H:%M:%S") %><%= l mod.created_at %> <% if mod.moderator %> <%= mod.moderator.try(:username) %> <% elsif mod.is_from_suggestions? %> - (users) + (<%= t('.users') %>) <% end %> <% if mod.story %> - Story: <%= mod.story.title + <%= t('.storyline') %>: <%= mod.story.title %> <% elsif mod.comment %> - Comment by + <%= t('.commentline') %> <%= mod.comment.user.username %> - on + <%= t('.commenton') %> <%= mod.comment.story.title %> <% elsif mod.user_id %> <% if mod.user %> - User + <%= t('.user') %> <%= mod.user.username %> <% else %> - User <%= mod.user_id %> (Deleted) + <%= t('.user') %> <%= mod.user_id %> (<%= t('.deleted') %>) <% end %> <% end %>
Action: <%= mod.action %><%= t('.actionline') %>: <%= mod.action %>
Reason: <%= mod.reason %><%= t('.reasonline') %>: <%= mod.reason %>