i18n-tasks 0.9.28 → 0.9.29

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: daf654e97c52cba1413c10e69c12510ed9ce438e2fabf089bdb05b38ac944c5c
4
- data.tar.gz: 7d3d264ca3a630497da4c7c5fc48907cf22c55bd0f16ac51bffed22febb540f4
3
+ metadata.gz: 955b0b27ee0885fa2860b00848054c1367098e38905fce60ece6f67f35051f78
4
+ data.tar.gz: f2e2cd7f950bad6420f831e598a2004f280cf214caf8eab4f046963df47a1ab0
5
5
  SHA512:
6
- metadata.gz: 2fd90385cd85755fcb9ef3f53a1a21f09a6ac217d8f9153871ade1cd38a155dbd2eb585a2ac0b059938b07b50578949c2291012fb97b4c1169a470b1ee59d84c
7
- data.tar.gz: de5ee6c4256599189f4934b97595364d39b242e4645ac017c59ea2f2a172296628340b53bbcd2b54df0657bbddd92fe0e8bee69f980e915b1a286a025eff8b78
6
+ metadata.gz: 71b276f4b5f20d6c111d1a3078d793d61a22bb4695362c1efbda80c4cb92f93fc59a221e6d5ee6fe48d1601b9eebbf74bc94e66bc8f84dd0549dc92af37ac16e
7
+ data.tar.gz: 5a17f8014105c81d9dfe858c5d7f64735e00617455d339cccfbd9fe3a28eca71c2fb527c9117794563be89252260d365b9e4bb09a1f1dde591b00cefca60d849
data/README.md CHANGED
@@ -22,7 +22,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
22
22
  Add i18n-tasks to the Gemfile:
23
23
 
24
24
  ```ruby
25
- gem 'i18n-tasks', '~> 0.9.28'
25
+ gem 'i18n-tasks', '~> 0.9.29'
26
26
  ```
27
27
 
28
28
  Copy the default [configuration file](#configuration):
@@ -45,7 +45,7 @@ $ cp $(i18n-tasks gem-path)/templates/minitest/i18n_test.rb test/
45
45
 
46
46
  ## Usage
47
47
 
48
- Run `i18n-tasks` to get the list of all the tasks with short descriptions.
48
+ Run `bundle exec i18n-tasks` to get the list of all the tasks with short descriptions.
49
49
 
50
50
  ### Check health
51
51
 
@@ -324,6 +324,16 @@ A special syntax similar to file glob patterns is used throughout i18n-tasks to
324
324
  | `:` | matches a single key |
325
325
  | `{a, b.c}` | match any in set, can use `:` and `*`, match is captured |
326
326
 
327
+ Example of usage:
328
+
329
+ ```sh
330
+ $ bundle exec i18n-tasks mv "{:}.contents.{*}_body" "\1.attributes.\2.body"
331
+
332
+ car.contents.name_body ⮕ car.attributes.name.body
333
+ car.contents.description_body ⮕ car.attributes.description.body
334
+ truck.contents.name_body ⮕ truck.attributes.name.body
335
+ truck.contents.description_body ⮕ truck.attributes.description.body
336
+ ```
327
337
 
328
338
  #### Custom adapters
329
339
 
@@ -19,9 +19,9 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
19
19
  TEXT
20
20
  s.post_install_message = <<~TEXT
21
21
  # Install default configuration:
22
- cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
22
+ cp $(bundle exec i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
23
23
  # Add an RSpec for missing and unused keys:
24
- cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
24
+ cp $(bundle exec i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
25
25
  TEXT
26
26
  s.homepage = 'https://github.com/glebm/i18n-tasks'
27
27
  s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' } if s.respond_to?(:metadata=)
@@ -43,7 +43,7 @@ TEXT
43
43
  s.add_dependency 'rainbow', '>= 2.2.2', '< 4.0'
44
44
  s.add_dependency 'terminal-table', '>= 1.5.1'
45
45
  s.add_development_dependency 'axlsx', '~> 2.0'
46
- s.add_development_dependency 'bundler', '~> 1.3'
46
+ s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
47
47
  s.add_development_dependency 'deepl-rb', '>= 2.1.0'
48
48
  s.add_development_dependency 'easy_translate', '>= 0.5.1'
49
49
  s.add_development_dependency 'rake'
@@ -68,8 +68,3 @@ require 'i18n'
68
68
  Dir[File.join(I18n::Tasks.gem_path, 'config', 'locales', '*.yml')].each do |locale_file|
69
69
  I18n.config.load_path << locale_file
70
70
  end
71
-
72
- # Load pluralization data
73
- require 'rails-i18n'
74
- I18n.enforce_available_locales = false
75
- RailsI18n::Railtie.add('rails/pluralization/*.rb')
@@ -40,10 +40,16 @@ module I18n::Tasks
40
40
  cmd :remove_unused,
41
41
  pos: '[locale ...]',
42
42
  desc: t('i18n_tasks.cmd.desc.remove_unused'),
43
- args: %i[locales out_format strict keep_order confirm]
43
+ args: %i[locales out_format strict keep_order confirm pattern]
44
44
 
45
- def remove_unused(opt = {})
45
+ def remove_unused(opt = {}) # rubocop:disable Metrics/AbcSize
46
46
  unused_keys = i18n.unused_keys(opt.slice(:locales, :strict))
47
+
48
+ if opt[:pattern]
49
+ pattern_re = i18n.compile_key_pattern(opt[:pattern])
50
+ unused_keys = unused_keys.select_keys { |full_key, _node| full_key =~ pattern_re }
51
+ end
52
+
47
53
  if unused_keys.present?
48
54
  terminal_report.unused_keys(unused_keys)
49
55
  confirm_remove_unused!(unused_keys, opt)
@@ -11,6 +11,7 @@ module I18n::Tasks::Data::Tree
11
11
  # siblings' keys are unique
12
12
  class Siblings < Nodes # rubocop:disable Metrics/ClassLength
13
13
  include ::I18n::Tasks::SplitKey
14
+ include ::I18n::Tasks::PluralKeys
14
15
 
15
16
  attr_reader :parent, :key_to_node
16
17
 
@@ -100,12 +101,12 @@ module I18n::Tasks::Data::Tree
100
101
  key: key_part,
101
102
  parent: parent,
102
103
  children: [],
103
- warn_about_add_children_to_leaf: @warn_add_children_to_leaf
104
+ warn_about_add_children_to_leaf: @warn_about_add_children_to_leaf
104
105
  )
105
106
  append! child
106
107
  end
107
108
  unless child.children
108
- warn_add_children_to_leaf child if @warn_about_add_children_to_leaf
109
+ conditionally_warn_add_children_to_leaf(child, [])
109
110
  child.children = []
110
111
  end
111
112
  child.children.set rest, node
@@ -187,7 +188,7 @@ module I18n::Tasks::Data::Tree
187
188
  if our.children
188
189
  our.children.merge!(node.children)
189
190
  else
190
- warn_add_children_to_leaf our
191
+ conditionally_warn_add_children_to_leaf(our, node.children)
191
192
  our.children = node.children
192
193
  end
193
194
  elsif on_leaves_merge
@@ -228,6 +229,13 @@ module I18n::Tasks::Data::Tree
228
229
  end
229
230
  end
230
231
 
232
+ def conditionally_warn_add_children_to_leaf(node, children)
233
+ return unless @warn_about_add_children_to_leaf
234
+ return if plural_forms?(children)
235
+
236
+ warn_add_children_to_leaf(node)
237
+ end
238
+
231
239
  def warn_add_children_to_leaf(node)
232
240
  ::I18n::Tasks::Logging.log_warn "'#{node.full_key}' was a leaf, now has children (value <- scope conflict)"
233
241
  end
@@ -58,8 +58,8 @@ module I18n::Tasks
58
58
 
59
59
  def missing_plural_forest(locales, _base = base_locale)
60
60
  locales.each_with_object(empty_forest) do |locale, forest|
61
- next unless I18n.exists?(:'i18n.plural.keys', locale)
62
- required_keys = Set.new(I18n.t(:'i18n.plural.keys', locale: locale, resolve: false))
61
+ required_keys = required_plural_keys_for_locale(locale)
62
+ next if required_keys.empty?
63
63
  tree = empty_forest
64
64
  plural_nodes data[locale] do |node|
65
65
  children = node.children
@@ -76,6 +76,23 @@ module I18n::Tasks
76
76
  end
77
77
  end
78
78
 
79
+ def required_plural_keys_for_locale(locale)
80
+ @plural_keys_for_locale ||= {}
81
+ return @plural_keys_for_locale[locale] if @plural_keys_for_locale.key?(locale)
82
+ @plural_keys_for_locale[locale] =
83
+ begin
84
+ Set.new(load_rails_i18n_pluralization!(locale)[locale.to_sym][:i18n][:plural][:keys])
85
+ rescue SystemCallError, IOError
86
+ Set.new
87
+ end
88
+ end
89
+
90
+ # Loads rails-i18n pluralization config for the given locale.
91
+ def load_rails_i18n_pluralization!(locale)
92
+ path = File.join(Gem::Specification.find_by_name('rails-i18n').gem_dir, 'rails', 'pluralization', "#{locale}.rb")
93
+ eval(File.read(path), binding, path) # rubocop:disable Security/Eval
94
+ end
95
+
79
96
  # keys present in compared_to, but not in locale
80
97
  def missing_diff_tree(locale, compared_to = base_locale)
81
98
  data[compared_to].select_keys do |key, _node|
@@ -2,8 +2,10 @@
2
2
 
3
3
  require 'set'
4
4
  module I18n::Tasks::PluralKeys
5
- PLURAL_KEY_SUFFIXES = Set.new %w[zero one two few many other]
6
- PLURAL_KEY_RE = /\.(?:#{PLURAL_KEY_SUFFIXES.to_a * '|'})$/
5
+ # Ref: http://cldr.unicode.org/index/cldr-spec/plural-rules
6
+ CLDR_CATEGORY_KEYS = %w[zero one two few many other].freeze
7
+ PLURAL_KEY_SUFFIXES = Set.new CLDR_CATEGORY_KEYS
8
+ PLURAL_KEY_RE = /\.(?:#{CLDR_CATEGORY_KEYS * '|'})$/
7
9
 
8
10
  def collapse_plural_nodes!(tree)
9
11
  tree.leaves.map(&:parent).compact.uniq.each do |node|
@@ -14,11 +14,13 @@ module I18n::Tasks::Scanners
14
14
 
15
15
  TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:ranslate)?/
16
16
  IGNORE_LINES = {
17
- 'opal' => /^\s*#(?!\si18n-tasks-use)/,
18
- 'haml' => /^\s*-\s*#(?!\si18n-tasks-use)/,
19
- 'slim' => %r{^\s*(?:-#|/)(?!\si18n-tasks-use)},
20
17
  'coffee' => /^\s*#(?!\si18n-tasks-use)/,
21
- 'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/
18
+ 'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/,
19
+ 'es6' => %r{^\s*//(?!\si18n-tasks-use)},
20
+ 'haml' => /^\s*-\s*#(?!\si18n-tasks-use)/,
21
+ 'js' => %r{^\s*//(?!\si18n-tasks-use)},
22
+ 'opal' => /^\s*#(?!\si18n-tasks-use)/,
23
+ 'slim' => %r{^\s*(?:-#|/)(?!\si18n-tasks-use)}
22
24
  }.freeze
23
25
 
24
26
  def initialize(**args)
@@ -25,7 +25,7 @@ module I18n::Tasks
25
25
  }.freeze
26
26
 
27
27
  ALWAYS_EXCLUDE = %w[*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
28
- *.yml *.json *.zip *.tar.gz *.swf *.flv].freeze
28
+ *.yml *.json *.zip *.tar.gz *.swf *.flv *.mp3 *.wav *.flac *.webm *.mp4 *.ogg *.opus].freeze
29
29
 
30
30
  # Find all keys in the source and return a forest with the keys in absolute form and their occurrences.
31
31
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = '0.9.28'
5
+ VERSION = '0.9.29'
6
6
  end
7
7
  end
@@ -23,7 +23,14 @@ class I18nTest < ActiveSupport::TestCase
23
23
  non_normalized = @i18n.non_normalized_paths
24
24
  error_message = "The following files need to be normalized:\n" \
25
25
  "#{non_normalized.map { |path| " #{path}" }.join("\n")}\n" \
26
- 'Please run `i18n-tasks normalize` to fix'
26
+ "Please run `i18n-tasks normalize' to fix"
27
27
  assert_empty non_normalized, error_message
28
28
  end
29
+
30
+ def test_no_inconsistent_interpolations
31
+ inconsistent_interpolations = @i18n.inconsistent_interpolations
32
+ error_message = "#{inconsistent_interpolations.leaves.count} i18n keys have inconsistent interpolations.\n" \
33
+ "Please run `i18n-tasks check-consistent-interpolations' to show them"
34
+ assert_empty inconsistent_interpolations, error_message
35
+ end
29
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.28
4
+ version: 0.9.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-29 00:00:00.000000000 Z
11
+ date: 2019-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -162,14 +162,20 @@ dependencies:
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '1.3'
165
+ version: '2.0'
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.0.1
166
169
  type: :development
167
170
  prerelease: false
168
171
  version_requirements: !ruby/object:Gem::Requirement
169
172
  requirements:
170
173
  - - "~>"
171
174
  - !ruby/object:Gem::Version
172
- version: '1.3'
175
+ version: '2.0'
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: 2.0.1
173
179
  - !ruby/object:Gem::Dependency
174
180
  name: deepl-rb
175
181
  requirement: !ruby/object:Gem::Requirement
@@ -376,9 +382,9 @@ metadata:
376
382
  issue_tracker: https://github.com/glebm/i18n-tasks
377
383
  post_install_message: |
378
384
  # Install default configuration:
379
- cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
385
+ cp $(bundle exec i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
380
386
  # Add an RSpec for missing and unused keys:
381
- cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
387
+ cp $(bundle exec i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
382
388
  rdoc_options: []
383
389
  require_paths:
384
390
  - lib
@@ -393,8 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
399
  - !ruby/object:Gem::Version
394
400
  version: '0'
395
401
  requirements: []
396
- rubyforge_project:
397
- rubygems_version: 2.7.7
402
+ rubygems_version: 3.0.2
398
403
  signing_key:
399
404
  specification_version: 4
400
405
  summary: Manage localization and translation with the awesome power of static analysis