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
This commit is contained in:
chaica 2016-07-05 17:02:14 +02:00 committed by joshua stein
parent a5d880f431
commit 9506b1ce10
5 changed files with 81 additions and 27 deletions

View file

@ -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

View file

@ -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

View file

@ -1,49 +1,49 @@
<div class="box wide">
<div class="legend">
Moderation Log
<%= t('.moderationlogtitle') %>
</div>
<table class="data" width="100%" cellspacing=0>
<tr>
<th style="min-width: 130px;">Date/Time</th>
<th>Moderator</th>
<th>Story/Comment/User, Action, Reason</th>
<th style="min-width: 130px;"><%= t('.datecolumn') %></th>
<th><%= t('.moderatorcolumn') %></th>
<th><%= t('.reasoncolumn') %></th>
</tr>
<% bit = 0 %>
<% @moderations.each do |mod| %>
<tr class="row<%= bit %> nobottom">
<td><%= mod.created_at.strftime("%Y-%m-%d %H:%M:%S") %></td>
<td><%= l mod.created_at %></td>
<td><% if mod.moderator %>
<a href="/messages?to=<%= mod.moderator.try(:username) %>"><%=
mod.moderator.try(:username) %></a>
<% elsif mod.is_from_suggestions? %>
<em>(users)</em>
<em>(<%= t('.users') %>)</em>
<% end %></td>
<td><% if mod.story %>
<a href="<%= mod.story.comments_path %>">Story: <%= mod.story.title
<a href="<%= mod.story.comments_path %>"><%= t('.storyline') %>: <%= mod.story.title
%></a>
<% elsif mod.comment %>
<a href="<%= mod.comment.url %>">Comment by
<a href="<%= mod.comment.url %>"><%= t('.commentline') %>
<%= mod.comment.user.username %>
on
<%= t('.commenton') %>
<%= mod.comment.story.title %></a>
<% elsif mod.user_id %>
<% if mod.user %>
<a href="/u/<%= mod.user.username %>">User
<a href="/u/<%= mod.user.username %>"><%= t('.user') %>
<%= mod.user.username %></a>
<% else %>
User <%= mod.user_id %> (Deleted)
<%= t('.user') %> <%= mod.user_id %> (<%= t('.deleted') %>)
<% end %>
<% end %></td>
</tr>
<tr class="row<%= bit %> <%= mod.reason.present?? "nobottom" : "" %>">
<td colspan=2></td>
<td>Action: <em><%= mod.action %></em></td>
<td><%= t('.actionline') %>: <em><%= mod.action %></em></td>
</tr>
<% if mod.reason.present? %>
<tr class="row<%= bit %>">
<td colspan=2></td>
<td>Reason: <em><%= mod.reason %></em></td>
<td><%= t('.reasonline') %>: <em><%= mod.reason %></em></td>
</tr>
<% end %>
<% bit = (bit == 1 ? 0 : 1) %>
@ -53,7 +53,7 @@
<div class="morelink">
<% if @page > 1 %>
<a href="/moderations/page/<%= @page - 1 %>">&lt;&lt; Page
<a href="/moderations/page/<%= @page - 1 %>">&lt;&lt; <%= t('.page') %>
<%= @page - 1 %></a>
<% end %>
@ -61,7 +61,7 @@
<% if @page > 1 %>
|
<% end %>
<a href="/moderations/page/<%= @page + 1 %>">Page <%= @page + 1
<a href="/moderations/page/<%= @page + 1 %>"><%= t('.page') %> <%= @page + 1
%> &gt;&gt;</a>
<% end %>
</div>

View file

@ -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"

View file

@ -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"