i18n-js 4.0.0 → 4.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tests.yml +22 -1
- data/.gitignore +2 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +48 -1
- data/MIGRATING_FROM_V3_TO_V4.md +192 -0
- data/README.md +322 -25
- data/bin/release +81 -0
- data/i18n-js.gemspec +5 -2
- data/lib/guard/i18n-js.rb +21 -4
- data/lib/i18n-js/clean_hash.rb +13 -0
- data/lib/i18n-js/cli/check_command.rb +7 -147
- data/lib/i18n-js/cli/command.rb +10 -0
- data/lib/i18n-js/cli/export_command.rb +17 -3
- data/lib/i18n-js/cli/lint_scripts_command.rb +159 -0
- data/lib/i18n-js/cli/lint_translations_command.rb +157 -0
- data/lib/i18n-js/cli/plugins_command.rb +67 -0
- data/lib/i18n-js/cli.rb +12 -1
- data/lib/i18n-js/embed_fallback_translations_plugin.rb +70 -0
- data/lib/i18n-js/export_files_plugin.rb +103 -0
- data/lib/i18n-js/lint.js +150645 -0
- data/lib/i18n-js/lint.ts +196 -0
- data/lib/i18n-js/listen.rb +25 -10
- data/lib/i18n-js/plugin.rb +103 -0
- data/lib/i18n-js/schema.rb +153 -41
- data/lib/i18n-js/sort_hash.rb +12 -0
- data/lib/i18n-js/version.rb +1 -1
- data/lib/i18n-js.rb +37 -3
- data/package.json +10 -0
- metadata +36 -11
- data/i18njs.png +0 -0
- data/images/i18njs-check.gif +0 -0
data/lib/i18n-js.rb
CHANGED
|
@@ -6,9 +6,15 @@ require "yaml"
|
|
|
6
6
|
require "glob"
|
|
7
7
|
require "fileutils"
|
|
8
8
|
require "optparse"
|
|
9
|
+
require "erb"
|
|
10
|
+
require "set"
|
|
11
|
+
require "digest/md5"
|
|
9
12
|
|
|
10
13
|
require_relative "i18n-js/schema"
|
|
11
14
|
require_relative "i18n-js/version"
|
|
15
|
+
require_relative "i18n-js/plugin"
|
|
16
|
+
require_relative "i18n-js/sort_hash"
|
|
17
|
+
require_relative "i18n-js/clean_hash"
|
|
12
18
|
|
|
13
19
|
module I18nJS
|
|
14
20
|
MissingConfigError = Class.new(StandardError)
|
|
@@ -19,12 +25,18 @@ module I18nJS
|
|
|
19
25
|
"you must set either `config_file` or `config`"
|
|
20
26
|
end
|
|
21
27
|
|
|
22
|
-
config = Glob::SymbolizeKeys.call(config ||
|
|
28
|
+
config = Glob::SymbolizeKeys.call(config || load_config_file(config_file))
|
|
29
|
+
|
|
30
|
+
load_plugins!
|
|
31
|
+
initialize_plugins!(config: config)
|
|
23
32
|
Schema.validate!(config)
|
|
33
|
+
|
|
24
34
|
exported_files = []
|
|
25
35
|
|
|
26
|
-
config[:translations].each
|
|
27
|
-
|
|
36
|
+
config[:translations].each {|group| exported_files += export_group(group) }
|
|
37
|
+
|
|
38
|
+
plugins.each do |plugin|
|
|
39
|
+
plugin.after_export(files: exported_files.dup) if plugin.enabled?
|
|
28
40
|
end
|
|
29
41
|
|
|
30
42
|
exported_files
|
|
@@ -32,6 +44,16 @@ module I18nJS
|
|
|
32
44
|
|
|
33
45
|
def self.export_group(group)
|
|
34
46
|
filtered_translations = Glob.filter(translations, group[:patterns])
|
|
47
|
+
filtered_translations =
|
|
48
|
+
plugins.reduce(filtered_translations) do |buffer, plugin|
|
|
49
|
+
if plugin.enabled?
|
|
50
|
+
plugin.transform(translations: buffer)
|
|
51
|
+
else
|
|
52
|
+
buffer
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
filtered_translations = sort_hash(clean_hash(filtered_translations))
|
|
35
57
|
output_file_path = File.expand_path(group[:file])
|
|
36
58
|
exported_files = []
|
|
37
59
|
|
|
@@ -55,6 +77,13 @@ module I18nJS
|
|
|
55
77
|
digest = Digest::MD5.hexdigest(contents)
|
|
56
78
|
file_path = file_path.gsub(/:digest/, digest)
|
|
57
79
|
|
|
80
|
+
# Don't rewrite the file if it already exists and has the same content.
|
|
81
|
+
# It helps the asset pipeline or webpack understand that file wasn't
|
|
82
|
+
# changed.
|
|
83
|
+
if File.exist?(file_path) && File.read(file_path) == contents
|
|
84
|
+
return file_path
|
|
85
|
+
end
|
|
86
|
+
|
|
58
87
|
File.open(file_path, "w") do |file|
|
|
59
88
|
file << contents
|
|
60
89
|
end
|
|
@@ -70,4 +99,9 @@ module I18nJS
|
|
|
70
99
|
translations
|
|
71
100
|
end
|
|
72
101
|
end
|
|
102
|
+
|
|
103
|
+
def self.load_config_file(config_file)
|
|
104
|
+
erb = ERB.new(File.read(config_file))
|
|
105
|
+
YAML.safe_load(erb.result(binding))
|
|
106
|
+
end
|
|
73
107
|
end
|
data/package.json
ADDED
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.
|
|
4
|
+
version: 4.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nando Vieira
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: glob
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 0.4.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: 0.4.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: i18n
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: mocha
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: pry-meta
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -173,26 +187,37 @@ files:
|
|
|
173
187
|
- CONTRIBUTING.md
|
|
174
188
|
- Gemfile
|
|
175
189
|
- LICENSE.md
|
|
190
|
+
- MIGRATING_FROM_V3_TO_V4.md
|
|
176
191
|
- README.md
|
|
177
192
|
- Rakefile
|
|
193
|
+
- bin/release
|
|
178
194
|
- exe/i18n
|
|
179
195
|
- i18n-js.gemspec
|
|
180
|
-
- i18njs.png
|
|
181
|
-
- images/i18njs-check.gif
|
|
182
196
|
- lib/guard/i18n-js.rb
|
|
183
197
|
- lib/guard/i18n-js/templates/Guardfile
|
|
184
198
|
- lib/guard/i18n-js/version.rb
|
|
185
199
|
- lib/i18n-js.rb
|
|
200
|
+
- lib/i18n-js/clean_hash.rb
|
|
186
201
|
- lib/i18n-js/cli.rb
|
|
187
202
|
- lib/i18n-js/cli/check_command.rb
|
|
188
203
|
- lib/i18n-js/cli/command.rb
|
|
189
204
|
- lib/i18n-js/cli/export_command.rb
|
|
190
205
|
- lib/i18n-js/cli/init_command.rb
|
|
206
|
+
- lib/i18n-js/cli/lint_scripts_command.rb
|
|
207
|
+
- lib/i18n-js/cli/lint_translations_command.rb
|
|
208
|
+
- lib/i18n-js/cli/plugins_command.rb
|
|
191
209
|
- lib/i18n-js/cli/ui.rb
|
|
192
210
|
- lib/i18n-js/cli/version_command.rb
|
|
211
|
+
- lib/i18n-js/embed_fallback_translations_plugin.rb
|
|
212
|
+
- lib/i18n-js/export_files_plugin.rb
|
|
213
|
+
- lib/i18n-js/lint.js
|
|
214
|
+
- lib/i18n-js/lint.ts
|
|
193
215
|
- lib/i18n-js/listen.rb
|
|
216
|
+
- lib/i18n-js/plugin.rb
|
|
194
217
|
- lib/i18n-js/schema.rb
|
|
218
|
+
- lib/i18n-js/sort_hash.rb
|
|
195
219
|
- lib/i18n-js/version.rb
|
|
220
|
+
- package.json
|
|
196
221
|
homepage: https://github.com/fnando/i18n-js
|
|
197
222
|
licenses:
|
|
198
223
|
- MIT
|
|
@@ -200,10 +225,10 @@ metadata:
|
|
|
200
225
|
rubygems_mfa_required: 'true'
|
|
201
226
|
homepage_uri: https://github.com/fnando/i18n-js
|
|
202
227
|
bug_tracker_uri: https://github.com/fnando/i18n-js/issues
|
|
203
|
-
source_code_uri: https://github.com/fnando/i18n-js/tree/v4.
|
|
204
|
-
changelog_uri: https://github.com/fnando/i18n-js/tree/v4.
|
|
205
|
-
documentation_uri: https://github.com/fnando/i18n-js/tree/v4.
|
|
206
|
-
license_uri: https://github.com/fnando/i18n-js/tree/v4.
|
|
228
|
+
source_code_uri: https://github.com/fnando/i18n-js/tree/v4.2.3
|
|
229
|
+
changelog_uri: https://github.com/fnando/i18n-js/tree/v4.2.3/CHANGELOG.md
|
|
230
|
+
documentation_uri: https://github.com/fnando/i18n-js/tree/v4.2.3/README.md
|
|
231
|
+
license_uri: https://github.com/fnando/i18n-js/tree/v4.2.3/LICENSE.md
|
|
207
232
|
post_install_message:
|
|
208
233
|
rdoc_options: []
|
|
209
234
|
require_paths:
|
|
@@ -219,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
244
|
- !ruby/object:Gem::Version
|
|
220
245
|
version: '0'
|
|
221
246
|
requirements: []
|
|
222
|
-
rubygems_version: 3.
|
|
247
|
+
rubygems_version: 3.4.6
|
|
223
248
|
signing_key:
|
|
224
249
|
specification_version: 4
|
|
225
250
|
summary: Export i18n translations and use them on JavaScript.
|
data/i18njs.png
DELETED
|
Binary file
|
data/images/i18njs-check.gif
DELETED
|
Binary file
|