i18n-js 4.2.3 → 4.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08fcf5b6b9e3cff755d11708a88e88cc8d30609251cba16f52e396a86014ac85'
4
- data.tar.gz: 90b3fa30d3e6115fe76f81b5621caba070160cf585890f122aa8f646ee10fd2e
3
+ metadata.gz: f067f8059ef5fe37c2fdb9624cf260e00b3eb60a87492aebccb0b13f170ff17d
4
+ data.tar.gz: 73acf779ba9a46921e44e4106e66eab2c5d05b7b1163cb93b2889abf446977e0
5
5
  SHA512:
6
- metadata.gz: 02d7a1a0d46b452727465a35cc9a9c46f4e8fe3d0baee2680e75d70fd6512972c7a28481795f9d0a07295612bd8553b932fb27fae2e86f83adc39e4d8aec5209
7
- data.tar.gz: 9987a9679a3aa39f50f70e4b7b67469c2c7549b61b738f3104b837119a1afeb253e932119f24bdb39f29ffdb9b1840aa4f9b20035d1a70f71e51cfc8f0310b03
6
+ metadata.gz: a71ec7995b41c9e9c56168dccd1a87e1e872c3bfa98075c135aa9d6f4f0259fef6da8e8db81fd1fa63966775b5bd28185ee086a6206c0600b113827938b73412
7
+ data.tar.gz: be12ef7d7665f61d40abd05849cb25dc303c1679c08e6ed535123e9389cb5d968946b4d716d541bc5e10f8d1384040b7935e56aa0c84d682d0964a0698683d50
@@ -16,8 +16,8 @@ jobs:
16
16
  strategy:
17
17
  fail-fast: false
18
18
  matrix:
19
- ruby: ["2.7", "3.0", "3.1"]
20
- node: ["16", "18"]
19
+ ruby: ["3.3", "3.4"]
20
+ node: ["22", "24"]
21
21
  gemfile:
22
22
  - Gemfile
23
23
  if: |
@@ -25,9 +25,9 @@ jobs:
25
25
  github.actor != 'dependabot[bot]'
26
26
 
27
27
  steps:
28
- - uses: actions/checkout@v3
28
+ - uses: actions/checkout@v4
29
29
 
30
- - uses: actions/cache@v3
30
+ - uses: actions/cache@v4
31
31
  id: bundler-cache
32
32
  with:
33
33
  path: vendor/bundle
@@ -35,7 +35,7 @@ jobs:
35
35
  ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
36
36
  hashFiles(matrix.gemfile) }}
37
37
 
38
- - uses: actions/cache@v3
38
+ - uses: actions/cache@v4
39
39
  id: npm-cache
40
40
  with:
41
41
  path: vendor/bundle
@@ -44,7 +44,7 @@ jobs:
44
44
  hashFiles('package.json') }}
45
45
 
46
46
  - name: Set up Node
47
- uses: actions/setup-node@v3.6.0
47
+ uses: actions/setup-node@v4.0.2
48
48
  with:
49
49
  node-version: ${{ matrix.node }}
50
50
 
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 3.2
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - tmp/**/*
@@ -17,3 +17,9 @@ Naming/FileName:
17
17
 
18
18
  Style/PerlBackrefs:
19
19
  Enabled: false
20
+
21
+ Gemspec/DevelopmentDependencies:
22
+ Enabled: false
23
+
24
+ Gemspec/AttributeAssignment:
25
+ Enabled: false
data/README.md CHANGED
@@ -36,6 +36,12 @@ Or add the following line to your project's Gemfile:
36
36
  gem "i18n-js"
37
37
  ```
38
38
 
39
+ Create a default configuration file in ./config/i18n.yml
40
+
41
+ ```bash
42
+ i18n init
43
+ ```
44
+
39
45
  ## Usage
40
46
 
41
47
  About patterns:
@@ -73,8 +79,11 @@ translations:
73
79
 
74
80
  The output path can use the following placeholders:
75
81
 
76
- - `:locale`: the language that's being exported.
77
- - `:digest`: the MD5 hex digest of the exported file.
82
+ - `:locale` - the language that's being exported.
83
+ - `:digest` - the MD5 hex digest of the exported file.
84
+
85
+ The example above could generate a file named
86
+ `app/frontend/locales/en.7bdc958e33231eafb96b81e3d108eff3.json`.
78
87
 
79
88
  The config file is processed as erb, so you can have dynamic content on it if
80
89
  you want. The following example shows how to use groups from a variable.
@@ -92,13 +101,28 @@ translations:
92
101
  - "!<%= group %>.number.nth"
93
102
  ```
94
103
 
104
+ ### Exporting locale.yml to locale.json
105
+
106
+ Your i18n yaml file can be exported to JSON using the Ruby API or the command
107
+ line utility. Examples of both approaches are provided below:
108
+
95
109
  The Ruby API:
96
110
 
97
111
  ```ruby
98
112
  require "i18n-js"
99
113
 
114
+ # The following call performs the same task as the CLI `i18n export` command
100
115
  I18nJS.call(config_file: "config/i18n.yml")
116
+
117
+ # You can provide the config directly using the following
118
+ config = {
119
+ "translations"=>[
120
+ {"file"=>"app/javascript/locales/:locale.json", "patterns"=>["*"]}
121
+ ]
122
+ }
123
+
101
124
  I18nJS.call(config: config)
125
+ #=> ["app/javascript/locales/de.json", "app/javascript/locales/en.json"]
102
126
  ```
103
127
 
104
128
  The CLI API:
@@ -136,6 +160,7 @@ the default locale together with the target locale.
136
160
  To use it, add the following to your configuration file:
137
161
 
138
162
  ```yaml
163
+ ---
139
164
  embed_fallback_translations:
140
165
  enabled: true
141
166
  ```
@@ -147,6 +172,7 @@ plugin allows exporting other file formats. To use it, add the following to your
147
172
  configuration file:
148
173
 
149
174
  ```yaml
175
+ ---
150
176
  export_files:
151
177
  enabled: true
152
178
  files:
@@ -154,7 +180,7 @@ export_files:
154
180
  output: "%{dir}/%{base_name}.ts"
155
181
  ```
156
182
 
157
- You can export multiple files by define more entries.
183
+ You can export multiple files by defining more entries.
158
184
 
159
185
  The output name can use the following placeholders:
160
186
 
@@ -210,7 +236,10 @@ i18n.store({
210
236
 
211
237
  You can transform the exported translations by adding plugins. A plugin must
212
238
  inherit from `I18nJS::Plugin` and can have 4 class methods (they're all optional
213
- and will default to a noop implementation). For real examples, see [lib/i18n-js/embed_fallback_translations_plugin.rb](https://github.com/fnando/i18n-js/blob/main/lib/i18n-js/embed_fallback_translations_plugin.rb) and [lib/i18n-js/export_files_plugin.rb](https://github.com/fnando/i18n-js/blob/main/lib/i18n-js/export_files_plugin.rb)
239
+ and will default to a noop implementation). For real examples, see
240
+ [lib/i18n-js/embed_fallback_translations_plugin.rb](https://github.com/fnando/i18n-js/blob/main/lib/i18n-js/embed_fallback_translations_plugin.rb)
241
+ and
242
+ [lib/i18n-js/export_files_plugin.rb](https://github.com/fnando/i18n-js/blob/main/lib/i18n-js/export_files_plugin.rb)
214
243
 
215
244
  ```ruby
216
245
  # frozen_string_literal: true
@@ -299,8 +328,8 @@ $ i18n lint:translations
299
328
  - pt-BR.github.repository (extraneous)
300
329
  ```
301
330
 
302
- This command will exist with status 1 whenever there are missing translations.
303
- This way you can use it as a CI linting.
331
+ This command will exit with status 1 whenever there are missing translations.
332
+ This way you can use it as a CI linting tool.
304
333
 
305
334
  You can ignore keys by adding a list to the config file:
306
335
 
@@ -375,8 +404,9 @@ $ i18n lint:scripts
375
404
  - test/scripts/lint/file.js:6:1: es.another_ignore_scope
376
405
  ```
377
406
 
378
- This command will list all locales and their missing translations. Avoid listing
379
- a particular translation, you can set `lint.ignore` on your config file.
407
+ This command will list all locales and their missing translations. To avoid
408
+ listing a particular translation, you can set `lint_scripts.ignore` or
409
+ `lint_translations.ignore` in your config file.
380
410
 
381
411
  ```yaml
382
412
  ---
@@ -401,7 +431,7 @@ translations:
401
431
  patterns:
402
432
  - "*"
403
433
 
404
- lint:
434
+ lint_scripts:
405
435
  patterns:
406
436
  - "app/assets/**/*.ts"
407
437
  ```
@@ -438,7 +468,7 @@ watchman -j <<-JSON
438
468
  JSON
439
469
 
440
470
  # If you're running this through Foreman,
441
- # the uncomment the following lines:
471
+ # then uncomment the following lines:
442
472
  # while true; do
443
473
  # sleep 1
444
474
  # done
@@ -520,7 +550,7 @@ that loads all the exported translation.
520
550
  [There's a document](https://github.com/fnando/i18n-js/tree/main/MIGRATING_FROM_V3_TO_V4.md)
521
551
  outlining some of the things you need to do to migrate from v3 to v4. It may not
522
552
  be as complete as we'd like it to be, so let us know if you face any issues
523
- during the migration is not outline is that document.
553
+ during the migration that is not outlined in that document.
524
554
 
525
555
  #### How can I export translations without having a database around?
526
556
 
@@ -543,9 +573,9 @@ I18n.load_path += Dir["./config/locales/**/*.yml"]
543
573
 
544
574
  > **Note**:
545
575
  >
546
- > You may not need to load ActiveSupport and ActionView lines, or even may need
547
- > to add additional requires for other libs. With this approach you have full
548
- > control on what's going to be loaded.
576
+ > You may not need to load the ActiveSupport and ActionView lines, or you may
577
+ > need to add additional requires for other libs. With this approach you have
578
+ > full control on what's going to be loaded.
549
579
 
550
580
  ## Maintainer
551
581
 
data/i18n-js.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./lib/i18n-js/version"
3
+ require_relative "lib/i18n-js/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "i18n-js"
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Export i18n translations and use them on JavaScript."
12
12
  spec.description = spec.summary
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.2.0")
15
15
  spec.metadata = {"rubygems_mfa_required" => "true"}
16
16
 
17
17
  github_url = "https://github.com/fnando/i18n-js"
data/lib/guard/i18n-js.rb CHANGED
@@ -77,7 +77,7 @@ module Guard
77
77
  $stdout = original
78
78
  end
79
79
 
80
- def validate_file(key, file)
80
+ def validate_file(key, file) # rubocop:disable Naming/PredicateMethod
81
81
  return true if file && File.file?(file)
82
82
 
83
83
  error("#{key.inspect} must be a file")
@@ -21,8 +21,8 @@ module I18nJS
21
21
  end
22
22
  end
23
23
 
24
- def self.command(&block)
25
- define_method(:command, &block)
24
+ def self.command(&)
25
+ define_method(:command, &)
26
26
  end
27
27
 
28
28
  def initialize(argv:, ui:)
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "benchmark"
4
-
5
3
  module I18nJS
6
4
  class CLI
7
5
  class ExportCommand < Command
@@ -30,7 +28,7 @@ module I18nJS
30
28
  opts.on(
31
29
  "-q",
32
30
  "--quiet",
33
- "A Ruby file that must be loaded"
31
+ "Suppress non-error output"
34
32
  ) do |quiet|
35
33
  options[:quiet] = quiet
36
34
  end
@@ -69,18 +67,18 @@ module I18nJS
69
67
  )
70
68
  end
71
69
 
72
- time = Benchmark.realtime do
70
+ time = benchmark_realtime do
73
71
  load_require_file!(require_file) if require_file
74
- I18nJS.call(config_file: config_file)
72
+ I18nJS.call(config_file:)
75
73
  end
76
74
 
77
75
  log("=> Done in #{time.round(2)}s")
78
76
  end
79
77
 
80
- private def log(*args)
78
+ private def log(*)
81
79
  return if options[:quiet]
82
80
 
83
- ui.stdout_print(*args)
81
+ ui.stdout_print(*)
84
82
  end
85
83
 
86
84
  private def set_defaults!
@@ -90,6 +88,12 @@ module I18nJS
90
88
  options[:config_file] ||= config_file if File.file?(config_file)
91
89
  options[:require_file] ||= require_file if File.file?(require_file)
92
90
  end
91
+
92
+ private def benchmark_realtime
93
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
94
+ yield
95
+ Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
96
+ end
93
97
  end
94
98
  end
95
99
  end
@@ -81,7 +81,7 @@ module I18nJS
81
81
 
82
82
  config = load_config_file(config_file)
83
83
  I18nJS.load_plugins!
84
- I18nJS.initialize_plugins!(config: config)
84
+ I18nJS.initialize_plugins!(config:)
85
85
  Schema.validate!(config)
86
86
 
87
87
  load_require_file!(require_file) if require_file
@@ -91,7 +91,7 @@ module I18nJS
91
91
 
92
92
  ui.stdout_print "=> Available locales: #{available_locales.inspect}"
93
93
 
94
- exported_files = I18nJS.call(config_file: config_file)
94
+ exported_files = I18nJS.call(config_file:)
95
95
  data = exported_files.each_with_object({}) do |file, buffer|
96
96
  buffer.merge!(JSON.load_file(file, symbolize_names: true))
97
97
  end
@@ -69,7 +69,7 @@ module I18nJS
69
69
 
70
70
  config = load_config_file(config_file)
71
71
  I18nJS.load_plugins!
72
- I18nJS.initialize_plugins!(config: config)
72
+ I18nJS.initialize_plugins!(config:)
73
73
  Schema.validate!(config)
74
74
 
75
75
  load_require_file!(require_file) if require_file
data/lib/i18n-js/cli.rb CHANGED
@@ -17,7 +17,7 @@ module I18nJS
17
17
 
18
18
  def initialize(argv:, stdout:, stderr:, colored: stdout.tty?)
19
19
  @argv = argv.dup
20
- @ui = UI.new(stdout: stdout, stderr: stderr, colored: colored)
20
+ @ui = UI.new(stdout:, stderr:, colored:)
21
21
  end
22
22
 
23
23
  def call
@@ -43,7 +43,7 @@ module I18nJS
43
43
 
44
44
  private def commands
45
45
  command_classes.map do |command_class|
46
- command_class.new(argv: @argv, ui: ui)
46
+ command_class.new(argv: @argv, ui:)
47
47
  end
48
48
  end
49
49
 
@@ -54,8 +54,8 @@ module I18nJS
54
54
  config[:files].each do |export|
55
55
  translations = JSON.load_file(file)
56
56
  template = Template.new(
57
- file: file,
58
- translations: translations,
57
+ file:,
58
+ translations:,
59
59
  template: export[:template]
60
60
  )
61
61
 
@@ -63,11 +63,11 @@ module I18nJS
63
63
 
64
64
  output = format(
65
65
  export[:output],
66
- dir: dir,
67
- name: name,
68
- extension: extension,
66
+ dir:,
67
+ name:,
68
+ extension:,
69
69
  digest: Digest::MD5.hexdigest(contents),
70
- base_name: base_name
70
+ base_name:
71
71
  )
72
72
 
73
73
  File.open(output, "w") do |io|
@@ -82,7 +82,7 @@ module I18nJS
82
82
 
83
83
  def initialize(**kwargs)
84
84
  kwargs.each do |key, value|
85
- public_send("#{key}=", value)
85
+ public_send(:"#{key}=", value)
86
86
  end
87
87
  end
88
88
 
@@ -28,7 +28,7 @@ module I18nJS
28
28
  debug("Watching #{relative_paths.inspect}")
29
29
 
30
30
  listener(config_file, locales_dirs.map(&:to_s), options).start
31
- I18nJS.call(config_file: config_file) if run_on_start
31
+ I18nJS.call(config_file:) if run_on_start
32
32
  end
33
33
 
34
34
  def self.relative_path(path)
@@ -27,7 +27,7 @@ module I18nJS
27
27
 
28
28
  def self.initialize_plugins!(config:)
29
29
  @plugins = available_plugins.map do |plugin|
30
- plugin.new(config: config).tap(&:setup)
30
+ plugin.new(config:).tap(&:setup)
31
31
  end
32
32
  end
33
33
 
@@ -133,8 +133,8 @@ module I18nJS
133
133
  end
134
134
 
135
135
  def expect_type(path:, types:)
136
- path = prepare_path(path: path)
137
- value = value_for(path: path)
136
+ path = prepare_path(path:)
137
+ value = value_for(path:)
138
138
  types = Array(types)
139
139
 
140
140
  return if types.any? {|type| value.is_a?(type) }
@@ -156,10 +156,10 @@ module I18nJS
156
156
  end
157
157
 
158
158
  def expect_array_with_items(path:)
159
- expect_type(path: path, types: Array)
159
+ expect_type(path:, types: Array)
160
160
 
161
- path = prepare_path(path: path)
162
- value = value_for(path: path)
161
+ path = prepare_path(path:)
162
+ value = value_for(path:)
163
163
 
164
164
  return unless value.empty?
165
165
 
@@ -168,8 +168,8 @@ module I18nJS
168
168
  end
169
169
 
170
170
  def expect_required_keys(keys:, path:)
171
- path = prepare_path(path: path)
172
- value = value_for(path: path)
171
+ path = prepare_path(path:)
172
+ value = value_for(path:)
173
173
  actual_keys = value.keys.map(&:to_sym)
174
174
 
175
175
  keys.each do |key|
@@ -186,8 +186,8 @@ module I18nJS
186
186
  end
187
187
 
188
188
  def reject_extraneous_keys(keys:, path:)
189
- path = prepare_path(path: path)
190
- value = value_for(path: path)
189
+ path = prepare_path(path:)
190
+ value = value_for(path:)
191
191
 
192
192
  actual_keys = value.keys.map(&:to_sym)
193
193
  extraneous = actual_keys.to_a - keys.to_a
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nJS
4
- VERSION = "4.2.3"
4
+ VERSION = "4.2.4"
5
5
  end
data/lib/i18n-js.rb CHANGED
@@ -7,7 +7,6 @@ require "glob"
7
7
  require "fileutils"
8
8
  require "optparse"
9
9
  require "erb"
10
- require "set"
11
10
  require "digest/md5"
12
11
 
13
12
  require_relative "i18n-js/schema"
@@ -28,7 +27,7 @@ module I18nJS
28
27
  config = Glob::SymbolizeKeys.call(config || load_config_file(config_file))
29
28
 
30
29
  load_plugins!
31
- initialize_plugins!(config: config)
30
+ initialize_plugins!(config:)
32
31
  Schema.validate!(config)
33
32
 
34
33
  exported_files = []
@@ -59,7 +58,7 @@ module I18nJS
59
58
 
60
59
  if output_file_path.include?(":locale")
61
60
  filtered_translations.each_key do |locale|
62
- locale_file_path = output_file_path.gsub(/:locale/, locale.to_s)
61
+ locale_file_path = output_file_path.gsub(":locale", locale.to_s)
63
62
  exported_files << write_file(locale_file_path,
64
63
  locale => filtered_translations[locale])
65
64
  end
@@ -75,7 +74,7 @@ module I18nJS
75
74
 
76
75
  contents = ::JSON.pretty_generate(translations)
77
76
  digest = Digest::MD5.hexdigest(contents)
78
- file_path = file_path.gsub(/:digest/, digest)
77
+ file_path = file_path.gsub(":digest", digest)
79
78
 
80
79
  # Don't rewrite the file if it already exists and has the same content.
81
80
  # It helps the asset pipeline or webpack understand that file wasn't
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 4.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: glob
@@ -225,11 +224,10 @@ metadata:
225
224
  rubygems_mfa_required: 'true'
226
225
  homepage_uri: https://github.com/fnando/i18n-js
227
226
  bug_tracker_uri: https://github.com/fnando/i18n-js/issues
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
232
- post_install_message:
227
+ source_code_uri: https://github.com/fnando/i18n-js/tree/v4.2.4
228
+ changelog_uri: https://github.com/fnando/i18n-js/tree/v4.2.4/CHANGELOG.md
229
+ documentation_uri: https://github.com/fnando/i18n-js/tree/v4.2.4/README.md
230
+ license_uri: https://github.com/fnando/i18n-js/tree/v4.2.4/LICENSE.md
233
231
  rdoc_options: []
234
232
  require_paths:
235
233
  - lib
@@ -237,15 +235,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
237
235
  requirements:
238
236
  - - ">="
239
237
  - !ruby/object:Gem::Version
240
- version: 2.6.0
238
+ version: 3.2.0
241
239
  required_rubygems_version: !ruby/object:Gem::Requirement
242
240
  requirements:
243
241
  - - ">="
244
242
  - !ruby/object:Gem::Version
245
243
  version: '0'
246
244
  requirements: []
247
- rubygems_version: 3.4.6
248
- signing_key:
245
+ rubygems_version: 3.6.9
249
246
  specification_version: 4
250
247
  summary: Export i18n translations and use them on JavaScript.
251
248
  test_files: []