Skip to content

Commit

Permalink
Feature/traduction (#30)
Browse files Browse the repository at this point in the history
* Add translation for mailers

* Add translation in bo

* adapt translations

* Fix locales

Co-authored-by: virgile-dev <[email protected]>
  • Loading branch information
armandfardeau and virgile-dev authored Feb 24, 2022
1 parent a3a0e3c commit 105b6d4
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 32 deletions.
20 changes: 20 additions & 0 deletions app/mailers/decidim/spam_detection/spam_detection_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Decidim
module SpamDetection
class SpamDetectionMailer < Decidim::ApplicationMailer
helper_method :blocked_users_url, :reported_users_url

def notify_detection(user, results)
with_user(user) do
@reported_count = results[:reported_user]
Expand All @@ -14,6 +16,24 @@ def notify_detection(user, results)
mail(to: @user.email, subject: subject)
end
end

private

def blocked_users_url
decidim_admin.moderated_users_url(blocked: true, host: root_url)
end

def reported_users_url
decidim_admin.moderated_users_url(blocked: false, host: root_url)
end

def decidim_admin
Decidim::Admin::Engine.routes.url_helpers
end

def root_url
decidim.root_url(host: @user.organization.host)[0..-2]
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
<p>
<%= t(".reported_count", count: @reported_count) %>
</p>
<p><%= link_to(t(".reported_link"), reported_users_url ) %></p>
<% end %>

<% if @blocked_count.present? %>
<p>
<%= t(".blocked_count", count: @blocked_count) %>
</p>
<p><%= link_to(t(".blocked_link"), blocked_users_url ) %></p>
<% end %>
2 changes: 2 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ locales: [en, fr, es, ca]

ignore_unused:
- "decidim.components.spam_detection.name"
- blocked_user.*
- reported_user.*

ignore_missing:
- decidim.participatory_processes.scopes.global
21 changes: 15 additions & 6 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
---
ca:
blocked_user:
reason: L'usuari ha estat bloquejat a causa d'una alta probabilitat de spam per
la tasca de detecció automàtica de spam de Decidim amb una probabilitat de %{probability}%
decidim:
components:
spam_detection:
name: SpamDetection
name: DeteccioSpam
spam_detection:
spam_detection_mailer:
notify_detection:
blocked_count: blocked_count %{count}
hello: Hello %{name}
intro: Aquí teniu l'informe de la tasca de detecció de correu brossa
reported_count: reported_count %{count}
blocked_count: Comptes de spam bloquejats %{count}
blocked_link: Consulteu la llista de tots els comptes bloquejats
hello: Hola %{name}
intro: Aquí teniu l'informe de la tasca de detecció de spam
reported_count: Comptes blocs de %{count}
reported_link: Consulteu la llista de tots els comptes reportats al lloc
spam_detection_mailer:
notify_detection:
subject: Resum de detecció de correu brossa
subject: Informe de la tasca automàtica detecció de spam
reported_user:
details: L'usuari s'ha marcat com spam a causa d'una alta probabilitat de spam
per la tasca de detecció automàtica de spam de Decidim amb una probabilitat
de %{probability}%
16 changes: 12 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
en:
blocked_user:
reason: The user was blocked because of a high spam probability by the automated
spam detection task with a probability of %{probability}%
decidim:
components:
spam_detection:
name: SpamDetection
spam_detection:
spam_detection_mailer:
notify_detection:
blocked_count: 'Blocked users count: %{count}'
blocked_count: 'Spam accounts blocked: %{count}'
blocked_link: See the list of all blocked accounts
hello: Hello %{name}
intro: Here is the report of the spam detection task
reported_count: 'Reported users count: %{count}'
intro: Here is the report of the automated spam detection task.
reported_count: 'Spam accounts reported: %{count}'
reported_link: See the list of all reported accounts
spam_detection_mailer:
notify_detection:
subject: Spam detection digest
subject: Automated spam detection task digest
reported_user:
details: The user was reported because of a high spam probability by the automated
spam detection task with a probability of %{probability}%
20 changes: 14 additions & 6 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
es:
blocked_user:
reason: El usuario fue bloqueado debido a una alta probabilidad de spam por la
tarea de detección automática de spam con una probabilidad de %{probability}%
decidim:
components:
spam_detection:
name: SpamDetection
name: DeteccionSpam
spam_detection:
spam_detection_mailer:
notify_detection:
blocked_count: blocked_count %{count}
hello: Hello %{name}
intro: Here is the report of the spam detection task
reported_count: reported_count %{count}
blocked_count: 'Cuentas de spam bloqueadas : %{count}'
blocked_link: Ver la lista de todas las cuentas bloqueadas
hello: Hola %{name}
intro: Aquí está el informe de la tarea de detección automática de spam.
reported_count: Cuentas de spam señaladas %{count}
reported_link: Ver la lista de cuentas señaladas
spam_detection_mailer:
notify_detection:
subject: Subject
subject: Informe de la tarea automática detección de spam
reported_user:
details: El usuario fue señalado debido a una alta probabilidad de spam por la
tarea de detección automática de spam con una probabilidad de %{probability}%
20 changes: 14 additions & 6 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
fr:
blocked_user:
reason: L'utilisateur a été bloqué en raison d'une forte probabilité de spam par
la tâche de détection automatique de spam avec une probabilité de %{probability}%
decidim:
components:
spam_detection:
name: SpamDetection
name: DetectionSpam
spam_detection:
spam_detection_mailer:
notify_detection:
blocked_count: blocked_count %{count}
hello: Hello %{name}
intro: Here is the report of the spam detection task
reported_count: reported_count %{count}
blocked_count: 'Comptes spam bloqués : %{count}'
blocked_link: Voir la liste de tous les comptes bloqués du site
hello: Bonjour %{name}
intro: Voici le rapport de la tâche de détection automatisée des spams.
reported_count: 'Comptes spam signalés : %{count}'
reported_link: Voir la liste de tous les comptes signalés
spam_detection_mailer:
notify_detection:
subject: Subject
subject: Rapport de la tâche de détection automatique de spam
reported_user:
details: L'utilisateur a été signalé en raison d'une forte probabilité de spam
par la tâche de détection automatique de spam avec une probabilité de %{probability}%
2 changes: 1 addition & 1 deletion lib/decidim/spam_detection/block_spam_user_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def block!
end

def reason
"The user was blocked because of a high spam probability by Decidim spam detection bot with a probability of #{@probability}%"
I18n.t("blocked_user.reason", probability: @probability)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/spam_detection/report_spam_user_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def reason
end

def details
"The user was marked as spam by Decidim spam detection bot with a probability of #{@probability}%"
I18n.t("reported_user.details", probability: @probability)
end

def find_or_create_moderation!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module SpamDetection

it "creates a log" do
expect { subject }.to change(Decidim::ActionLog, :count)
expect(Decidim::ActionLog.last.extra.dig("extra", "current_justification")).to eq("The user was blocked because of a high spam probability by Decidim spam detection bot with a probability of #{spam_probabilty}%")
expect(Decidim::ActionLog.last.extra.dig("extra", "current_justification")).to eq("The user was blocked because of a high spam probability by the automated spam detection task with a probability of #{spam_probabilty}%")
end

it "create a moderation entry" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module SpamDetection
it "reports the user" do
expect { subject }.to change(Decidim::UserReport, :count)
expect(Decidim::UserReport.last.moderation.user).to eq(user)
expect(Decidim::UserReport.last.details).to eq("The user was marked as spam by Decidim spam detection bot with a probability of #{spam_probabilty}%")
expect(Decidim::UserReport.last.details).to eq("The user was reported because of a high spam probability by the automated spam detection task with a probability of #{spam_probabilty}%")
end

it "#add spam detection metadata" do
Expand Down
20 changes: 14 additions & 6 deletions spec/mailers/decidim/spam_detection/spam_detection_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ module SpamDetection
let(:mail) { described_class.notify_detection(user, results) }

describe "localisation" do
let(:subject) { "Resum de detecció de correu brossa" }
let(:default_subject) { "Spam detection digest" }
let(:subject) { "Informe de la tasca automàtica detecció de spam" }
let(:default_subject) { "Automated spam detection task digest" }

let(:body) { "Aquí teniu l&#39;informe de la tasca de detecció de correu brossa" }
let(:default_body) { "Here is the report of the spam detection task" }
let(:body) { "Aquí teniu l&#39;informe de la tasca de detecció de spam" }
let(:default_body) { "Here is the report of the automated spam detection task." }

include_examples "localised email"
end

describe "email body" do
it "includes reported_user count" do
expect(email_body(mail)).to include("Reported users count: #{results[:reported_user]}")
expect(email_body(mail)).to include("Spam accounts reported: #{results[:reported_user]}")
end

it "includes reported_user link" do
expect(email_body(mail)).to include("<a href=\"http://#{user.organization.host}/admin/moderated_users?blocked=false\">See the list of all reported accounts</a>")
end

it "includes blocked_user count" do
expect(email_body(mail)).to include("Blocked users count: #{results[:blocked_user]}")
expect(email_body(mail)).to include("Spam accounts blocked: #{results[:blocked_user]}")
end

it "includes blocked_user link" do
expect(email_body(mail)).to include("<a href=\"http://#{user.organization.host}/admin/moderated_users?blocked=true\">See the list of all blocked accounts</a>")
end
end
end
Expand Down

0 comments on commit 105b6d4

Please sign in to comment.