From 532cd08b326837688017d93951030f9881d849ac Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Fri, 2 Feb 2024 23:42:52 -0600 Subject: [PATCH] Add i18n-tasks --- Gemfile | 2 ++ Gemfile.lock | 26 ++++++++++++++++++++++++++ config/i18n-tasks.yml | 25 +++++++++++++++++++++++++ test/i18n_test.rb | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 config/i18n-tasks.yml create mode 100644 test/i18n_test.rb diff --git a/Gemfile b/Gemfile index 405f7ed3..da5faeaf 100644 --- a/Gemfile +++ b/Gemfile @@ -60,6 +60,8 @@ group :development, :test do gem "dotenv" gem "letter_opener" + + gem "i18n-tasks" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index c0eb3a73..5f12910a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -112,6 +112,13 @@ GEM ast (2.4.2) base64 (0.2.0) bcrypt (3.1.20) + better_html (2.0.2) + actionview (>= 6.0) + activesupport (>= 6.0) + ast (~> 2.0) + erubi (~> 1.4) + parser (>= 2.4) + smart_properties bigdecimal (3.1.6) bindex (0.8.1) bootsnap (1.18.3) @@ -142,12 +149,24 @@ GEM ffi (1.16.3) globalid (1.2.1) activesupport (>= 6.1) + highline (3.0.1) hotwire-livereload (1.3.1) actioncable (>= 6.0.0) listen (>= 3.0.0) railties (>= 6.0.0) i18n (1.14.1) concurrent-ruby (~> 1.0) + i18n-tasks (1.0.13) + activesupport (>= 4.0.2) + ast (>= 2.1.0) + better_html (>= 1.0, < 3.0) + erubi + highline (>= 2.0.0) + i18n + parser (>= 3.2.2.1) + rails-i18n + rainbow (>= 2.2.2, < 4.0) + terminal-table (>= 1.5.1) importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) @@ -238,6 +257,9 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) + rails-i18n (7.0.8) + i18n (>= 0.7, < 2) + railties (>= 6.0.0, < 8) rainbow (3.1.1) rake (13.1.0) rb-fsevent (0.11.2) @@ -300,6 +322,7 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) + smart_properties (1.17.0) sorbet-runtime (0.5.11226) stimulus-rails (1.3.3) railties (>= 6.0.0) @@ -316,6 +339,8 @@ GEM railties (>= 6.0.0) tailwindcss-rails (2.3.0-x86_64-linux) railties (>= 6.0.0) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) thor (1.3.0) timeout (0.4.1) tzinfo (2.0.6) @@ -352,6 +377,7 @@ DEPENDENCIES debug dotenv hotwire-livereload + i18n-tasks importmap-rails inline_svg jbuilder diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml new file mode 100644 index 00000000..c29ef601 --- /dev/null +++ b/config/i18n-tasks.yml @@ -0,0 +1,25 @@ +base_locale: en +data: + read: + - config/locales/%{locale}.yml + write: + - config/locales/%{locale}.yml + router: conservative_router +search: + paths: + - app/ + relative_roots: + - app/controllers + - app/helpers + - app/mailers + - app/presenters + - app/views + strict: true + ## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting: + ## *.jpg *.jpeg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less + ## *.yml *.json *.zip *.tar.gz *.swf *.flv *.mp3 *.wav *.flac *.webm *.mp4 *.ogg *.opus *.webp *.map *.xlsx + exclude: + - app/assets/images + - app/assets/fonts + - app/assets/videos + - app/assets/builds diff --git a/test/i18n_test.rb b/test/i18n_test.rb new file mode 100644 index 00000000..56f05df7 --- /dev/null +++ b/test/i18n_test.rb @@ -0,0 +1,34 @@ +require "i18n/tasks" + +class I18nTest < ActiveSupport::TestCase + def setup + @i18n = I18n::Tasks::BaseTask.new + end + + def test_no_missing_keys + missing_keys = @i18n.missing_keys + assert_empty missing_keys, + "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them" + end + + def test_no_unused_keys + unused_keys = @i18n.unused_keys + assert_empty unused_keys, + "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them" + end + + def test_files_are_normalized + 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" + assert_empty non_normalized, error_message + end + + def test_no_inconsistent_interpolations + inconsistent_interpolations = @i18n.inconsistent_interpolations + error_message = "#{inconsistent_interpolations.leaves.count} i18n keys have inconsistent interpolations.\n" \ + "Please run `i18n-tasks check-consistent-interpolations' to show them" + assert_empty inconsistent_interpolations, error_message + end +end