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 +4 -4
- data/README.md +27 -1
- data/lib/i18n-js/cli/check_command.rb +37 -3
- data/lib/i18n-js/schema.rb +13 -1
- data/lib/i18n-js/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5b5c71c903af1425bb6d7b12d0e74dc2da41894cf75a428da19bb11715dc371
|
4
|
+
data.tar.gz: 4914b448a0aca280c53412827d11b0148a7ec6393ff875fca78efea84bb68ce2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
91
|
-
|
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)
|
data/lib/i18n-js/schema.rb
CHANGED
@@ -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
|
data/lib/i18n-js/version.rb
CHANGED
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.
|
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-
|
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.
|
204
|
-
changelog_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.
|
205
|
-
documentation_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.
|
206
|
-
license_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.
|
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:
|