refactor(attachment): extract i18n

This commit is contained in:
Colin Darie 2022-11-22 19:25:45 +01:00
parent 2f84346ba3
commit b110e58f2f
22 changed files with 72 additions and 24 deletions

View file

@ -137,9 +137,9 @@ class Attachment::EditComponent < ApplicationComponent
def error_message def error_message
case case
when attachment.virus_scanner.infected? when attachment.virus_scanner.infected?
"Virus détecté, merci denvoyer un autre fichier." t(".errors.virus_infected")
when attachment.virus_scanner.corrupt? when attachment.virus_scanner.corrupt?
"Le fichier est corrompu, merci denvoyer un autre fichier." t(".errors.corrupted_file")
end end
end end

View file

@ -1,3 +1,10 @@
--- ---
en: en:
max_file_size: "File size limit : %{max_file_size}." max_file_size: "File size limit : %{max_file_size}."
allowed_formats: "Supported formats : %{formats}"
retry: Retry
delete: Delete
errors:
uploading: "An error occurred while sending the file."
virus_infected: "Virus detected, please send another file."
corrupted_file: "The file is corrupted, please send another file."

View file

@ -1,3 +1,11 @@
--- ---
fr: fr:
max_file_size: "Taille maximale : %{max_file_size}." max_file_size: "Taille maximale : %{max_file_size}."
allowed_formats: "Formats supportés : %{formats}"
retry: Ré-essayer
delete: Supprimer
errors:
uploading: "Une erreur sest produite pendant lenvoi du fichier."
virus_infected: "Virus détecté, merci denvoyer un autre fichier."
corrupted_file: "Le fichier est corrompu, merci denvoyer un autre fichier."

View file

@ -3,7 +3,7 @@
%div{ id: dom_id(attachment, :persisted_row) } %div{ id: dom_id(attachment, :persisted_row) }
.flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) } .flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) }
- if user_can_destroy? - if user_can_destroy?
= link_to('Supprimer', destroy_attachment_path, **remove_button_options, class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: "Supprimer le fichier #{attachment.filename}") = link_to(t('.delete'), destroy_attachment_path, **remove_button_options, class: "fr-btn fr-btn--tertiary fr-btn--sm fr-icon-delete-line", title: "Supprimer le fichier #{attachment.filename}")
.fr-py-1v .fr-py-1v
- if downloadable? - if downloadable?
@ -21,8 +21,7 @@
- if max_file_size.present? - if max_file_size.present?
= t('.max_file_size', max_file_size: number_to_human_size(max_file_size)) = t('.max_file_size', max_file_size: number_to_human_size(max_file_size))
- if allowed_formats - if allowed_formats
Formats supportés : = t('.allowed_formats', formats: allowed_formats.join(', '))
= allowed_formats.join(', ')
- if !as_multiple? - if !as_multiple?
@ -32,10 +31,10 @@
%div{ data: poll_controller_options } %div{ data: poll_controller_options }
- if attachment.created_at < 30.seconds.ago - if attachment.created_at < 30.seconds.ago
.fr-mt-2w .fr-mt-2w
= render partial: "attachments/pending_refresh", url: attachment_path = render Attachment::LongProcessingRefreshComponent.new(attachment: attachment)
.attachment-error.hidden .attachment-error.hidden
%p.fr-error-text Une erreur sest produite pendant lenvoi du fichier. %p.fr-error-text= t('.errors.uploading')
= button_tag(**retry_button_options) do = button_tag(**retry_button_options) do
Ré-essayer = t(".retry")

View file

@ -0,0 +1,5 @@
class Attachment::LongProcessingRefreshComponent < ApplicationComponent
def initialize(attachment: nil)
@attachment = attachment
end
end

View file

@ -0,0 +1,4 @@
---
en:
reload: Reload
explanation: Scanning for viruses and processing your attachment(s) takes longer than expected.

View file

@ -0,0 +1,4 @@
---
fr:
reload: Recharger
explanation: Lanalyse antivirus et le traitement de votre ou de vos pièces jointes prend plus de temps que prévu.

View file

@ -0,0 +1,5 @@
= render Dsfr::CalloutComponent.new(title: nil) do |c|
- c.with_body do
= t(".explanation")
- c.with_bottom do
= button_tag t(".reload"), type: "button", class: "fr-btn", data: { action: 'click->turbo-poll#refresh' }

View file

@ -12,4 +12,4 @@
- if in_progress? - if in_progress?
%div{ data: poll_controller_options } %div{ data: poll_controller_options }
- if in_progress_long? - if in_progress_long?
= render "attachments/pending_refresh", url: auto_attach_url = render Attachment::LongProcessingRefreshComponent.new

View file

@ -8,9 +8,9 @@ class Attachment::ProgressComponent < ApplicationComponent
def progress_label def progress_label
case case
when attachment.virus_scanner.pending? when attachment.virus_scanner.pending?
"Analyse antivirus en cours…" t(".antivirus_pending")
when attachment.watermark_pending? when attachment.watermark_pending?
"Traitement en cours…" t(".watermark_pending")
end end
end end

View file

@ -0,0 +1,4 @@
---
en:
antivirus_pending: "Antivirus scanning in progress…"
watermark_pending: "Processing in progress…"

View file

@ -0,0 +1,4 @@
---
fr:
antivirus_pending: "Analyse antivirus en cours…"
watermark_pending: "Traitement en cours…"

View file

@ -12,9 +12,9 @@ class Attachment::ShowComponent < ApplicationComponent
def error_message def error_message
case case
when attachment.virus_scanner.infected? when attachment.virus_scanner.infected?
"Virus détecté, le téléchargement est bloqué." t(".errors.virus_infected")
when attachment.virus_scanner.corrupt? when attachment.virus_scanner.corrupt?
"Le fichier est corrompu, le téléchargement est bloqué." t(".errors.corrupted_file")
end end
end end

View file

@ -1,2 +1,6 @@
--- ---
en: en:
virus_not_analyzed: this file has not been scanned by our antivirus, download it with care
errors:
virus_infected: Virus detected, download is blocked.
corrupted_file: The file is corrupted, the download is blocked.

View file

@ -1,2 +1,6 @@
--- ---
fr: fr:
virus_not_analyzed: ce fichier na pas été analysé par notre antivirus, téléchargez-le avec précaution
errors:
virus_infected: "Virus détecté, le téléchargement est bloqué."
corrupted_file: "Le fichier est corrompu, le téléchargement est bloqué."

View file

@ -3,7 +3,7 @@
= render Dsfr::DownloadComponent.new(attachment: attachment) do |c| = render Dsfr::DownloadComponent.new(attachment: attachment) do |c|
- if !attachment.virus_scanner.started? - if !attachment.virus_scanner.started?
- c.right do - c.right do
(ce fichier na pas été analysé par notre antivirus, téléchargez-le avec précaution) = "(#{t(".virus_not_analyzed")})"
- else - else
.attachment-filename.fr-mb-1w.fr-mr-1w= attachment.filename.to_s .attachment-filename.fr-mb-1w.fr-mr-1w= attachment.filename.to_s

View file

@ -11,6 +11,6 @@ class Dsfr::DownloadComponent < ApplicationComponent
end end
def title def title
"Télécharger le fichier #{attachment.filename}" t(".title", filename: attachment.filename.to_s)
end end
end end

View file

@ -0,0 +1,3 @@
---
en:
title: "Download file %{filename}"

View file

@ -0,0 +1,3 @@
---
fr:
title: "Télécharger le fichier %{filename}"

View file

@ -1,6 +0,0 @@
= render Dsfr::CalloutComponent.new(title: nil) do |c|
- c.with_body do
Lanalyse antivirus de votre ou de vos pièces jointes prend plus de temps que prévu.
- c.with_bottom do
= button_tag "Rafraîchir le traitement", type: "button", class: "fr-btn", data: { action: 'click->turbo-poll#refresh' }

View file

@ -28,7 +28,7 @@ RSpec.describe Attachment::EditComponent, type: :component do
end end
it 'renders allowed formats' do it 'renders allowed formats' do
expect(subject).to have_content(/Formats supportés :\s+jpeg, png/) expect(subject).to have_content(/Formats supportés : jpeg, png/)
end end
end end
@ -128,7 +128,7 @@ RSpec.describe Attachment::EditComponent, type: :component do
end end
it 'renders a refresh button' do it 'renders a refresh button' do
expect(subject).to have_button("Rafraîchir") expect(subject).to have_button("Recharger")
end end
end end

View file

@ -101,7 +101,7 @@ RSpec.describe Attachment::MultipleComponent, type: :component do
context "process is taking longer than expected" do context "process is taking longer than expected" do
let(:created_at) { 5.minutes.ago } let(:created_at) { 5.minutes.ago }
it 'renders a refresh button' do it 'renders a refresh button' do
expect(subject).to have_button("Rafraîchir") expect(subject).to have_button("Recharger")
end end
end end
end end