diff --git a/Gemfile.lock b/Gemfile.lock
index eb256b8..8075188 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -78,6 +78,7 @@ GEM
momentjs-rails (~> 2.8)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
+ ast (2.4.2)
autoprefixer-rails (10.2.0.0)
execjs
builder (3.2.4)
@@ -90,8 +91,19 @@ GEM
ffi (1.14.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
+ highline (2.0.3)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
+ i18n-tasks (0.9.34)
+ activesupport (>= 4.0.2)
+ ast (>= 2.1.0)
+ erubi
+ highline (>= 2.0.0)
+ i18n
+ parser (>= 2.2.3.0)
+ rails-i18n
+ rainbow (>= 2.2.2, < 4.0)
+ terminal-table (>= 1.5.1)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
@@ -124,6 +136,10 @@ GEM
nio4r (2.5.4)
nokogiri (1.11.1-x86_64-darwin)
racc (~> 1.4)
+ nokogiri (1.11.1-x86_64-linux)
+ racc (~> 1.4)
+ parser (3.0.0.0)
+ ast (~> 2.4.1)
racc (1.5.2)
rack (2.2.3)
rack-test (1.1.0)
@@ -148,12 +164,16 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
+ rails-i18n (6.0.0)
+ i18n (>= 0.7, < 2)
+ railties (>= 6.0.0, < 7)
railties (6.1.1)
actionpack (= 6.1.1)
activesupport (= 6.1.1)
method_source
rake (>= 0.8.7)
thor (~> 1.0)
+ rainbow (3.0.0)
rake (13.0.3)
sassc (2.4.0)
ffi (~> 1.9)
@@ -172,10 +192,13 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
+ terminal-table (3.0.0)
+ unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.1.0)
tilt (2.0.10)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
+ unicode-display_width (1.7.0)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
@@ -183,10 +206,12 @@ GEM
PLATFORMS
x86_64-darwin-20
+ x86_64-linux
DEPENDENCIES
administrate-field-active_storage!
+ i18n-tasks (~> 0.9.34)
sqlite3 (~> 1.4)
BUNDLED WITH
- 2.2.5
+ 2.2.14
diff --git a/README.md b/README.md
index 6dd3c50..12c6ccb 100644
--- a/README.md
+++ b/README.md
@@ -204,6 +204,10 @@ Defaults to `false`.
Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads). You can use `rails generate administrate:assets:javascripts` to be able to customize Administrate JavaScripts in your application.
+## I18n
+
+You can see translation example [here](https://github.com/Dreamersoul/administrate-field-active_storage/blob/master/config/locales/administrate-field-active_storage.en.yml).
+
## Things To Do:
- [x] upload single file
- [x] adding image support through url_for to support 3rd party cloud storage
diff --git a/administrate-field-active_storage.gemspec b/administrate-field-active_storage.gemspec
index b0291e9..f184a99 100644
--- a/administrate-field-active_storage.gemspec
+++ b/administrate-field-active_storage.gemspec
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
gem.add_dependency "rails", ">= 6.0"
gem.add_development_dependency 'sqlite3', '~> 1.4'
+ gem.add_development_dependency 'i18n-tasks', '~> 0.9.34'
end
diff --git a/app/views/fields/active_storage/_form.html.erb b/app/views/fields/active_storage/_form.html.erb
index 398ca6c..826c6b8 100644
--- a/app/views/fields/active_storage/_form.html.erb
+++ b/app/views/fields/active_storage/_form.html.erb
@@ -25,7 +25,10 @@ By default, the input is a text field for the image's URL.
<% end %>
- <%= field.can_add_attachment? ? "Add:" : "Replace:" %>
+ <%= field.can_add_attachment? ?
+ I18n.t("administrate.fields.active_storage.add", default: 'Add') :
+ I18n.t("administrate.fields.active_storage.replace", default: 'Replace')
+ %>
<%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
diff --git a/app/views/fields/active_storage/_index.html.erb b/app/views/fields/active_storage/_index.html.erb
index 6fb76a3..3cf06c7 100644
--- a/app/views/fields/active_storage/_index.html.erb
+++ b/app/views/fields/active_storage/_index.html.erb
@@ -32,7 +32,10 @@ By default, the attribute is rendered as an image tag.
<% if field.index_display_count? %>
- <%= pluralize(field.attachments.count, 'Attachment') %>
+ <%= pluralize(field.attachments.count,
+ I18n.t("administrate.fields.active_storage.attachment", default: 'Attachment')
+ )
+ %>
<% end %>
<% end %>
diff --git a/app/views/fields/active_storage/_item.html.erb b/app/views/fields/active_storage/_item.html.erb
index d62e584..31837c7 100644
--- a/app/views/fields/active_storage/_item.html.erb
+++ b/app/views/fields/active_storage/_item.html.erb
@@ -36,7 +36,8 @@ controlled via a boolean local variable.
<% if field.destroy_url.present? %>
<% destroy_url = field.destroy_url.call(namespace, field.data.record, attachment) %>
- <%= link_to 'Remove', destroy_url, method: :delete, class: 'remove-attachment-link', data: { confirm: t("administrate.actions.confirm") } %>
+ <%= link_to I18n.t("administrate.fields.active_storage.remove", default: 'Remove'),
+ destroy_url, method: :delete, class: 'remove-attachment-link', data: { confirm: t("administrate.actions.confirm") } %>
<% end %>
diff --git a/app/views/fields/active_storage/_show.html.erb b/app/views/fields/active_storage/_show.html.erb
index 19010f0..a29b4f1 100644
--- a/app/views/fields/active_storage/_show.html.erb
+++ b/app/views/fields/active_storage/_show.html.erb
@@ -18,5 +18,5 @@ By default, the attribute is rendered as an image tag.
<% if field.attached? %>
<%= render partial: 'fields/active_storage/items', locals: { field: field } %>
<% else %>
- No attachment
+ <%= I18n.t("administrate.fields.active_storage.no_attachment", default: 'No attachment') %>
<% end %>
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
new file mode 100644
index 0000000..c3ed79d
--- /dev/null
+++ b/config/i18n-tasks.yml
@@ -0,0 +1,8 @@
+base_locale: en
+
+data:
+ read:
+ - config/locales/administrate-field-active_storage.%{locale}.yml
+
+ignore:
+ - 'administrate.actions.*'
diff --git a/config/locales/administrate-field-active_storage.en.yml b/config/locales/administrate-field-active_storage.en.yml
new file mode 100644
index 0000000..7dfda8f
--- /dev/null
+++ b/config/locales/administrate-field-active_storage.en.yml
@@ -0,0 +1,10 @@
+---
+en:
+ administrate:
+ fields:
+ active_storage:
+ add: Add
+ attachment: Attachment
+ no_attachment: No attachment
+ remove: Remove
+ replace: Replace
diff --git a/config/locales/administrate-field-active_storage.ru.yml b/config/locales/administrate-field-active_storage.ru.yml
new file mode 100644
index 0000000..e8790b6
--- /dev/null
+++ b/config/locales/administrate-field-active_storage.ru.yml
@@ -0,0 +1,10 @@
+---
+ru:
+ administrate:
+ fields:
+ active_storage:
+ add: Добавить
+ attachment: Вложение
+ no_attachment: Нет
+ remove: Удалить
+ replace: Заменить
diff --git a/contribute.md b/contribute.md
index b22d27f..d6cd384 100644
--- a/contribute.md
+++ b/contribute.md
@@ -13,3 +13,4 @@
- Sébastien Dubois [@sedubois](https://github.com/sedubois)
- Jazzy Gasper [@jazzygasper](https://github.com/jazzygasper)
- David Ma [@taikon](https://github.com/taikon)
+- Dmitry Davydov [@haukot](https://github.com/haukot)
diff --git a/spec/i18n_spec.rb b/spec/i18n_spec.rb
new file mode 100644
index 0000000..66da50a
--- /dev/null
+++ b/spec/i18n_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'i18n/tasks'
+
+# Template i18n-tasks test file from https://github.com/glebm/i18n-tasks/blob/main/templates/rspec/i18n_spec.rb
+RSpec.describe I18n do
+ let(:i18n) { I18n::Tasks::BaseTask.new }
+ let(:missing_keys) { i18n.missing_keys }
+ let(:unused_keys) { i18n.unused_keys }
+ let(:inconsistent_interpolations) { i18n.inconsistent_interpolations }
+
+ it 'does not have missing keys' do
+ expect(missing_keys).to be_empty,
+ "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
+ end
+
+ it 'does not have unused keys' do
+ expect(unused_keys).to be_empty,
+ "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them"
+ end
+
+ it 'files are normalized' do
+ non_normalized = i18n.non_normalized_paths
+ error_message = "The following files need to be normalized:\n" \
+ "#{non_normalized.map { |path| " #{path}" }.join("\n")}\n" \
+ "Please run `i18n-tasks normalize' to fix"
+ expect(non_normalized).to be_empty, error_message
+ end
+
+ it 'does not have inconsistent interpolations' do
+ error_message = "#{inconsistent_interpolations.leaves.count} i18n keys have inconsistent interpolations.\n" \
+ "Run `i18n-tasks check-consistent-interpolations' to show them"
+ expect(inconsistent_interpolations).to be_empty, error_message
+ end
+end