rails_translation_manager 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbbde3519b97f6c9881189908af474ef24b5ad5dae1a3c6e3a590df8ca4b9885
4
- data.tar.gz: f6ad0e6bf5584f6fa9db3b39d3a7d52c1b04786368c9297090a480690e2cf1e7
3
+ metadata.gz: 1698a9fc00bbc68d6a07e11ab9a61fa009cdf11ab0556c1634e6586ea7f8043f
4
+ data.tar.gz: b93eba9d7309f7e7184a548487592a684bc508afd87af84a6270a4abaa66f624
5
5
  SHA512:
6
- metadata.gz: befae5c31f13ce323a367033180d58d7969220cde8eded8dd213a0de5405fd82246f0b775c3761d45e2412b25699630538896d6b2ec9692a4f030ea751f9282c
7
- data.tar.gz: 25979414b9918d47b58e3f87caa2ba967dcca0bc233c37854f270b8e93f0f95940b3c0f54b7f658ea4ed144b463b740569bebe4c0dfd98907a8e82d02c10fd6f
6
+ metadata.gz: e8877d5f9a8b3baff02a1f62df4b5b8645297774cbb6fc583ff04b3c23c41298d093f8455253f803f7d21fbdbdf4a832b93d5b0582dda96df0a67eff49041be5
7
+ data.tar.gz: bd9f568b8f7c330c005b9c897179d3a37d0f4a88dd718af7135544fd47cd7719329139799c4d050f2a85de20a134b62bb85ad771017002f408faac92a3097e34
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.2.0
2
+
3
+ Add two new checker classes. https://github.com/alphagov/rails_translation_manager/pull/30
4
+
1
5
  ## 1.1.3
2
6
 
3
7
  Handle importing files that contain rows with a blank "key". https://github.com/alphagov/rails_translation_manager/pull/28
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MissingDeclaredLocales < BaseChecker
4
+ include LocaleCheckerHelper
5
+
6
+ def report
7
+ diff = compare
8
+ format_error_message(diff) unless diff.empty?
9
+ end
10
+
11
+ private
12
+
13
+ def format_error_message(locales)
14
+ <<~OUTPUT.chomp
15
+ \e[31m[ERROR]\e[0m No locale files detected for:
16
+
17
+ #{locales.join("\n\n")}
18
+
19
+ \e[1mEither create these locale files or remove these locales from your I18n `available_locales` config.\e[22m
20
+ OUTPUT
21
+ end
22
+
23
+ def actual_locales
24
+ all_locales.map { |l| l[:locale] }
25
+ end
26
+
27
+ def compare
28
+ I18n.available_locales - actual_locales
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UndeclaredLocaleFiles < BaseChecker
4
+ include LocaleCheckerHelper
5
+
6
+ def report
7
+ diff = compare
8
+ format_error_message(diff) unless diff.empty?
9
+ end
10
+
11
+ private
12
+
13
+ def format_error_message(locales)
14
+ <<~OUTPUT.chomp
15
+ \e[31m[ERROR]\e[0m Undeclared locale file(s) detected for:
16
+
17
+ #{locales.join("\n\n")}
18
+
19
+ \e[1mEither declare these locale files or remove them from your locale files directory.\e[22m
20
+ OUTPUT
21
+ end
22
+
23
+ def actual_locales
24
+ all_locales.map { |l| l[:locale] }
25
+ end
26
+
27
+ def compare
28
+ actual_locales - I18n.available_locales
29
+ end
30
+ end
@@ -4,9 +4,11 @@ module RailsTranslationManager
4
4
  class LocaleChecker
5
5
  attr_reader :locale_path
6
6
 
7
- CHECKER_CLASSES = [MissingEnglishLocales,
7
+ CHECKER_CLASSES = [IncompatiblePlurals,
8
+ MissingDeclaredLocales,
9
+ MissingEnglishLocales,
8
10
  MissingForeignLocales,
9
- IncompatiblePlurals].freeze
11
+ UndeclaredLocaleFiles].freeze
10
12
 
11
13
  def initialize(locale_path)
12
14
  @locale_path = locale_path
@@ -1,3 +1,3 @@
1
1
  module RailsTranslationManager
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -6,10 +6,12 @@ require "rails-i18n"
6
6
 
7
7
  require "rails_translation_manager/locale_checker/base_checker"
8
8
  require "rails_translation_manager/locale_checker/locale_checker_helper"
9
+ require "rails_translation_manager/locale_checker/missing_declared_locales"
9
10
  require "rails_translation_manager/locale_checker/missing_foreign_locales"
10
11
  require "rails_translation_manager/locale_checker/missing_english_locales"
11
12
  require "rails_translation_manager/locale_checker/plural_forms"
12
13
  require "rails_translation_manager/locale_checker/incompatible_plurals"
14
+ require "rails_translation_manager/locale_checker/undeclared_locale_files"
13
15
  require "rails_translation_manager/locale_checker/all_locales"
14
16
  require "rails_translation_manager/locale_checker"
15
17
  require "rails_translation_manager/cleaner"
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe MissingDeclaredLocales do
6
+ let(:all_locales) do
7
+ [
8
+ {
9
+ locale: :en,
10
+ keys: %w[browse.same_key]
11
+ },
12
+ {
13
+ locale: :cy,
14
+ keys: %w[browse.same_key]
15
+ }
16
+ ]
17
+ end
18
+
19
+ context "when there are missing locales" do
20
+ before do
21
+ I18n.available_locales = [:en, :cy, :pt]
22
+ end
23
+
24
+ it "outputs the missing locales" do
25
+ expect(described_class.new(all_locales).report)
26
+ .to eq(
27
+ <<~OUTPUT.chomp
28
+ \e[31m[ERROR]\e[0m No locale files detected for:
29
+
30
+ pt
31
+
32
+ \e[1mEither create these locale files or remove these locales from your I18n `available_locales` config.\e[22m
33
+ OUTPUT
34
+ )
35
+ end
36
+ end
37
+
38
+ context "when there aren't missing locales" do
39
+ before do
40
+ I18n.available_locales = [:en, :cy]
41
+ end
42
+
43
+ it "outputs nil" do
44
+ expect(described_class.new(all_locales).report)
45
+ .to be_nil
46
+ end
47
+ end
48
+ end
@@ -44,7 +44,7 @@ RSpec.describe MissingEnglishLocales do
44
44
  ]
45
45
  end
46
46
 
47
- it 'outputs nil' do
47
+ it "outputs nil" do
48
48
  expect(described_class.new(all_locales).report)
49
49
  .to be_nil
50
50
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe UndeclaredLocaleFiles do
6
+ let(:all_locales) do
7
+ [
8
+ {
9
+ locale: :en,
10
+ keys: %w[browse.same_key]
11
+ },
12
+ {
13
+ locale: :cy,
14
+ keys: %w[browse.same_key]
15
+ }
16
+ ]
17
+ end
18
+
19
+ context "when there are undeclared locales" do
20
+ before do
21
+ I18n.available_locales = [:en]
22
+ end
23
+
24
+ it "outputs the missing locales" do
25
+ expect(described_class.new(all_locales).report)
26
+ .to eq(
27
+ <<~OUTPUT.chomp
28
+ \e[31m[ERROR]\e[0m Undeclared locale file(s) detected for:
29
+
30
+ cy
31
+
32
+ \e[1mEither declare these locale files or remove them from your locale files directory.\e[22m
33
+ OUTPUT
34
+ )
35
+ end
36
+ end
37
+
38
+ context "when there aren't undeclared locales" do
39
+ before do
40
+ I18n.available_locales = [:en, :cy]
41
+ end
42
+
43
+ it "outputs nil" do
44
+ expect(described_class.new(all_locales).report)
45
+ .to be_nil
46
+ end
47
+ end
48
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_translation_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edd Sowden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-10 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,9 +164,11 @@ files:
164
164
  - lib/rails_translation_manager/locale_checker/base_checker.rb
165
165
  - lib/rails_translation_manager/locale_checker/incompatible_plurals.rb
166
166
  - lib/rails_translation_manager/locale_checker/locale_checker_helper.rb
167
+ - lib/rails_translation_manager/locale_checker/missing_declared_locales.rb
167
168
  - lib/rails_translation_manager/locale_checker/missing_english_locales.rb
168
169
  - lib/rails_translation_manager/locale_checker/missing_foreign_locales.rb
169
170
  - lib/rails_translation_manager/locale_checker/plural_forms.rb
171
+ - lib/rails_translation_manager/locale_checker/undeclared_locale_files.rb
170
172
  - lib/rails_translation_manager/railtie.rb
171
173
  - lib/rails_translation_manager/version.rb
172
174
  - lib/rails_translation_manager/yaml_writer.rb
@@ -185,9 +187,11 @@ files:
185
187
  - spec/rails_translation_manager/locale_checker/all_locales_spec.rb
186
188
  - spec/rails_translation_manager/locale_checker/incompatible_plurals_spec.rb
187
189
  - spec/rails_translation_manager/locale_checker/locale_checker_helper_spec.rb
190
+ - spec/rails_translation_manager/locale_checker/missing_declared_locales_spec.rb
188
191
  - spec/rails_translation_manager/locale_checker/missing_english_locales_spec.rb
189
192
  - spec/rails_translation_manager/locale_checker/missing_foreign_locales_spec.rb
190
193
  - spec/rails_translation_manager/locale_checker/plural_forms_spec.rb
194
+ - spec/rails_translation_manager/locale_checker/undeclared_locale_files_spec.rb
191
195
  - spec/rails_translation_manager/locale_checker_spec.rb
192
196
  - spec/spec_helper.rb
193
197
  - spec/support/tasks.rb
@@ -233,9 +237,11 @@ test_files:
233
237
  - spec/rails_translation_manager/locale_checker/all_locales_spec.rb
234
238
  - spec/rails_translation_manager/locale_checker/incompatible_plurals_spec.rb
235
239
  - spec/rails_translation_manager/locale_checker/locale_checker_helper_spec.rb
240
+ - spec/rails_translation_manager/locale_checker/missing_declared_locales_spec.rb
236
241
  - spec/rails_translation_manager/locale_checker/missing_english_locales_spec.rb
237
242
  - spec/rails_translation_manager/locale_checker/missing_foreign_locales_spec.rb
238
243
  - spec/rails_translation_manager/locale_checker/plural_forms_spec.rb
244
+ - spec/rails_translation_manager/locale_checker/undeclared_locale_files_spec.rb
239
245
  - spec/rails_translation_manager/locale_checker_spec.rb
240
246
  - spec/spec_helper.rb
241
247
  - spec/support/tasks.rb