rails_translation_manager 1.3.0 → 1.4.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: 7345dfdb610385c480d9434eda36b6be02c37617046eb0029393fe250a37fe4f
4
- data.tar.gz: c7d42c8eeb4268b289f96377f5dcee785c97c8c67b1895c53cb7a9b4d984f99d
3
+ metadata.gz: 328572b2e2f76e544577abf6e4294fbc18b39324be6804a41107d7961e3545dd
4
+ data.tar.gz: cff1f18b58513f7fc12b8b2473aabf1f24fa5841999935ce4288d1a3bb7bd0ec
5
5
  SHA512:
6
- metadata.gz: 27a9d0906d1fff39bec4c877368c7118a9e95d209251433f2fa3890c270aeb9d58a2479153c768069aaf2834fd28b74b916f4a0ed36d58ec844a53c2a3cedf2f
7
- data.tar.gz: d2ce1ff2d3e9253b2109d4ee6db895ff80476f39b881dc8a9775766936d4b2092429e036d5fe0ed1d9c995a02b2204f06ac6d5fcdfcd064a82fc08b8c3b43a8d
6
+ metadata.gz: 2f3f6c481946426f3be7f562dc63487c5b29d16000b309980f581bf08f8089aa17a909389c0caf72be0a719f787ce4453d3cd91f31987a110b953ea4b7aa8c5f
7
+ data.tar.gz: 4cedacbcb032ca11e17b64bd2c699c7caf802062b768c129d43ef52b0f11e064b7f8990596007f58a020ea053fb5ecb374f99d7980b215f669d3e5673c1e6af5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.4.0
2
+
3
+ Add `skip_validation` parameter to `LocaleChecker`. https://github.com/alphagov/rails_translation_manager/pull/35
4
+
1
5
  ## 1.3.0
2
6
 
3
7
  Add remove-unused task wrapper. https://github.com/alphagov/rails_translation_manager/pull/32
@@ -3,8 +3,9 @@
3
3
  class AllLocales
4
4
  attr_reader :locale_path
5
5
 
6
- def initialize(locale_path)
6
+ def initialize(locale_path, skip_validation = [])
7
7
  @locale_path = locale_path
8
+ @skip_validation = skip_validation
8
9
  end
9
10
 
10
11
  def generate
@@ -15,12 +16,12 @@ class AllLocales
15
16
  paths.flat_map do |locale_group|
16
17
  {
17
18
  locale: locale_group[:locale],
18
- keys: all_keys_for_locale(locale_group)
19
+ keys: all_keys_for_locale(locale_group),
19
20
  }
20
21
  end
21
22
  end
22
23
 
23
- private
24
+ private
24
25
 
25
26
  def locale_file_paths
26
27
  I18n.available_locales.map do |locale|
@@ -43,6 +44,13 @@ class AllLocales
43
44
  def keys_from_file(locale_hash: nil, key_chain: nil, locale_keys: [], file_path: nil)
44
45
  locale_hash ||= YAML.load_file(file_path)
45
46
  keys = locale_hash.keys
47
+
48
+ keys.reject! do |key|
49
+ key_chain && @skip_validation.map { |prefix|
50
+ "#{key_chain}.#{key}".start_with? ".#{key_chain.split('.')[1]}.#{prefix}"
51
+ }.any?
52
+ end
53
+
46
54
  keys.each do |key|
47
55
  if locale_hash.fetch(key).is_a?(Hash)
48
56
  keys_from_file(locale_hash: locale_hash.fetch(key), key_chain: "#{key_chain}.#{key}", locale_keys: locale_keys)
@@ -10,8 +10,9 @@ module RailsTranslationManager
10
10
  MissingForeignLocales,
11
11
  UndeclaredLocaleFiles].freeze
12
12
 
13
- def initialize(locale_path)
13
+ def initialize(locale_path, skip_validation = [])
14
14
  @locale_path = locale_path
15
+ @skip_validation = skip_validation
15
16
  end
16
17
 
17
18
  def validate_locales
@@ -21,7 +22,7 @@ module RailsTranslationManager
21
22
  false
22
23
  end
23
24
 
24
- private
25
+ private
25
26
 
26
27
  def output_result
27
28
  errors = checker_errors.compact
@@ -46,7 +47,7 @@ module RailsTranslationManager
46
47
  end
47
48
 
48
49
  def all_locales
49
- @all_locales ||= AllLocales.new(locale_path).generate
50
+ @all_locales ||= AllLocales.new(locale_path, @skip_validation).generate
50
51
  end
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module RailsTranslationManager
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -21,4 +21,28 @@ RSpec.describe AllLocales do
21
21
  .to raise_error(AllLocales::NoLocaleFilesFound, 'No locale files found for the supplied path')
22
22
  end
23
23
  end
24
+
25
+ context "when some keys are excluded" do
26
+ it "generates an array of hashes without those keys" do
27
+ expect(described_class.new("spec/locales/out_of_sync/*.yml", skip_validation = %w{wrong_plural.one}).generate)
28
+ .to eq(
29
+ [
30
+ { keys: %w[test wrong_plural wrong_plural.zero], locale: :en },
31
+ { keys: %w[other_test], locale: :cy }
32
+ ]
33
+ )
34
+ end
35
+ end
36
+
37
+ context "when a key prefix is excluded" do
38
+ it "generates an array of hashes without those keys" do
39
+ expect(described_class.new("spec/locales/out_of_sync/*.yml", skip_validation = %w{wrong_plural}).generate)
40
+ .to eq(
41
+ [
42
+ { keys: %w[test], locale: :en },
43
+ { keys: %w[other_test], locale: :cy }
44
+ ]
45
+ )
46
+ end
47
+ end
24
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.3.0
4
+ version: 1.4.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-12-15 00:00:00.000000000 Z
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport