i18n-js 4.0.0.alpha4 → 4.0.0.alpha5

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: 3ecf4853a33adc9a67520a585c733a55e7b05e07bdc436830c519213bfc728b6
4
- data.tar.gz: 5a1b68a4182bc30fcc3c57438ab226ba72a97a7f16dd6c29ac938106f4c5e00c
3
+ metadata.gz: a5b5c71c903af1425bb6d7b12d0e74dc2da41894cf75a428da19bb11715dc371
4
+ data.tar.gz: 4914b448a0aca280c53412827d11b0148a7ec6393ff875fca78efea84bb68ce2
5
5
  SHA512:
6
- metadata.gz: f8468f07c440fa8c29c84a6550ef8b7d5914cf08ce93d0b02f77caf65838a4057f8a7653cc221c33a1dfaf1ab0486aa195a368248ca9509af4af7071ab76ddaa
7
- data.tar.gz: cb3822d5fe66aa90b20a4a596869a0adb93c3154d5877f66b1374794961536bc2916c051f8d5ce5f61d2d57c66951c25b477f8b808b7d737b39941875e545afb
6
+ metadata.gz: dd4f1880a36a9bee698766b843b73489517c1e09c86e143f1e5582811275423714c4c4a741cd01e86c7af558a33866738c9235399b309d09b97fd71375af77cb
7
+ data.tar.gz: 47e0d59fb0d12e2203508ff0c1bef534c9e42a77a895d78bea0d811f97ab6e2d2e0cc4461e46a36ba07016d0d77a4ac488b88fabdf71eb94325080b2fe2acd10
data/README.md CHANGED
@@ -24,7 +24,7 @@
24
24
  <a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/:License-MIT-blue.svg" alt="MIT License"></a>
25
25
  </p>
26
26
 
27
- ![This branch contains the code for v4, our next major release.](https://messages-svg.herokuapp.com/warning.svg?message=This%20branch%20contains%20the%20code%20for%20v4%2C%20our%20next%20major%20release.)
27
+ > **Warning**: This branch contains the code for v4, our next major release.
28
28
 
29
29
  ## Installation
30
30
 
@@ -111,6 +111,32 @@ default locale. Here's an example:
111
111
  This command will exist with status 1 whenever there are missing translations.
112
112
  This way you can use it as a CI linting.
113
113
 
114
+ You can ignore keys by adding a list to the config file:
115
+
116
+ ```yml
117
+ ---
118
+ translations:
119
+ - file: app/frontend/locales/en.json
120
+ patterns:
121
+ - "*"
122
+ - "!*.activerecord"
123
+ - "!*.errors"
124
+ - "!*.number.nth"
125
+
126
+ - file: app/frontend/locales/:locale.:digest.json
127
+ patterns:
128
+ - "*"
129
+
130
+ check:
131
+ ignore:
132
+ - en.mailer.login.subject
133
+ - en.mailer.login.body
134
+ ```
135
+
136
+ > **Note**: In order to avoid mistakenly ignoring keys, this configuration
137
+ > option only accepts the full translation scope, rather than accepting a
138
+ > pattern like `pt.ignored.scope.*`.
139
+
114
140
  ## Automatically export translations
115
141
 
116
142
  ### Using watchman
@@ -69,9 +69,14 @@ module I18nJS
69
69
  )
70
70
  end
71
71
 
72
+ config = Glob::SymbolizeKeys.call(YAML.load_file(config_file))
73
+ Schema.validate!(config)
74
+
72
75
  load_require_file!(require_file) if require_file
76
+
73
77
  default_locale = I18n.default_locale
74
78
  available_locales = I18n.available_locales
79
+ ignored_keys = config.dig(:check, :ignore) || []
75
80
 
76
81
  mapping = available_locales.each_with_object({}) do |locale, buffer|
77
82
  buffer[locale] =
@@ -81,21 +86,50 @@ module I18nJS
81
86
 
82
87
  default_locale_keys = mapping.delete(default_locale)
83
88
 
89
+ if ignored_keys.any?
90
+ ui.stdout_print "=> Check #{options[:config_file].inspect} for " \
91
+ "ignored keys."
92
+ end
93
+
84
94
  ui.stdout_print "=> #{default_locale}: #{default_locale_keys.size} " \
85
95
  "translations"
86
96
 
87
97
  total_missing_count = 0
88
98
 
89
99
  mapping.each do |locale, partial_keys|
90
- extraneous = partial_keys - default_locale_keys
91
- missing = default_locale_keys - (partial_keys - extraneous)
100
+ ignored_count = 0
101
+
102
+ # Compute list of filtered keys (i.e. keys not ignored)
103
+ filtered_keys = partial_keys.reject do |key|
104
+ key = "#{locale}.#{key}"
105
+
106
+ ignored = ignored_keys.include?(key)
107
+ ignored_count += 1 if ignored
108
+ ignored
109
+ end
110
+
111
+ extraneous = (partial_keys - default_locale_keys).reject do |key|
112
+ key = "#{locale}.#{key}"
113
+ ignored = ignored_keys.include?(key)
114
+ ignored_count += 1 if ignored
115
+ ignored
116
+ end
117
+
118
+ missing = (default_locale_keys - (filtered_keys - extraneous))
119
+ .reject {|key| ignored_keys.include?("#{locale}.#{key}") }
120
+
121
+ ignored_count += extraneous.size
92
122
  total_missing_count += missing.size
123
+
93
124
  ui.stdout_print "=> #{locale}: #{missing.size} missing, " \
94
- "#{extraneous.size} extraneous"
125
+ "#{extraneous.size} extraneous, " \
126
+ "#{ignored_count} ignored"
95
127
 
96
128
  all_keys = (default_locale_keys + extraneous + missing).uniq.sort
97
129
 
98
130
  all_keys.each do |key|
131
+ next if ignored_keys.include?("#{locale}.#{key}")
132
+
99
133
  label = if extraneous.include?(key)
100
134
  ui.yellow("extraneous")
101
135
  elsif missing.include?(key)
@@ -4,8 +4,9 @@ module I18nJS
4
4
  class Schema
5
5
  InvalidError = Class.new(StandardError)
6
6
 
7
- ROOT_KEYS = %i[translations].freeze
7
+ ROOT_KEYS = %i[translations check].freeze
8
8
  REQUIRED_ROOT_KEYS = %i[translations].freeze
9
+ REQUIRED_CHECK_KEYS = %i[ignore].freeze
9
10
  REQUIRED_TRANSLATION_KEYS = %i[file patterns].freeze
10
11
  TRANSLATION_KEYS = %i[file patterns].freeze
11
12
 
@@ -25,6 +26,17 @@ module I18nJS
25
26
  expect_required_keys(REQUIRED_ROOT_KEYS, target)
26
27
  reject_extraneous_keys(ROOT_KEYS, target)
27
28
  validate_translations
29
+ validate_check
30
+ end
31
+
32
+ def validate_check
33
+ return unless target.key?(:check)
34
+
35
+ check = target[:check]
36
+
37
+ expect_type(:check, check, Hash, target)
38
+ expect_required_keys(REQUIRED_CHECK_KEYS, check)
39
+ expect_type(:ignore, check[:ignore], Array, check)
28
40
  end
29
41
 
30
42
  def validate_translations
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nJS
4
- VERSION = "4.0.0.alpha4"
4
+ VERSION = "4.0.0.alpha5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha4
4
+ version: 4.0.0.alpha5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-21 00:00:00.000000000 Z
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glob
@@ -200,10 +200,10 @@ metadata:
200
200
  rubygems_mfa_required: 'true'
201
201
  homepage_uri: https://github.com/fnando/i18n-js
202
202
  bug_tracker_uri: https://github.com/fnando/i18n-js/issues
203
- source_code_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha4
204
- changelog_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha4/CHANGELOG.md
205
- documentation_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha4/README.md
206
- license_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha4/LICENSE.md
203
+ source_code_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha5
204
+ changelog_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha5/CHANGELOG.md
205
+ documentation_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha5/README.md
206
+ license_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha5/LICENSE.md
207
207
  post_install_message:
208
208
  rdoc_options: []
209
209
  require_paths: