i18n-tasks 0.9.19 → 0.9.20

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
  SHA1:
3
- metadata.gz: a645618f76025d6f6c0e9c1e82d19cf049aa5f7a
4
- data.tar.gz: b5d360c72ce14d141757a177c3f4a906ad84588d
3
+ metadata.gz: 3a681c4a39649fe7ca79db081a601cc2f5bb07bf
4
+ data.tar.gz: f515693226f21bbf07166f9087dbb5e6f8558eca
5
5
  SHA512:
6
- metadata.gz: 2ec7dd16adc0fe0aba80ea32f4ba7f60d665646be16f0c58fd7f5b34a6b8e5412a55678068f1e1daf5be5c660e4a2baf9216e80be6a8bef6e8dcc000fd425d6c
7
- data.tar.gz: b4f7c9a678a51534a5fdc15c3efc09e8e3ccec18de6b08246b4ae456a412c4190db148a621e6b933b6228db6193146aa9b3bbfd809500e0219c0d81280c26ed2
6
+ metadata.gz: adf7878cfb47362d5997d34870cb2a66c75e1487074b803ef7655d34d1f01343d4f2567150390d2155f8e061e0e9602ed3cd7778b1cd424138090bb400a24c84
7
+ data.tar.gz: eac041f710bdff5bd664e880bfed31ded2f6d90db6e2b53c17d3f67f4ae2fa55d40441624039c11e648da0569e8d02f3d008a377f12f7fd3162f5babcb21aa7a
data/README.md CHANGED
@@ -24,7 +24,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
24
24
  Add i18n-tasks to the Gemfile:
25
25
 
26
26
  ```ruby
27
- gem 'i18n-tasks', '~> 0.9.19'
27
+ gem 'i18n-tasks', '~> 0.9.20'
28
28
  ```
29
29
 
30
30
  Copy the default [configuration file](#configuration):
@@ -189,7 +189,7 @@ $ i18n-tasks unused -f yaml | i18n-tasks data-remove
189
189
 
190
190
  Remove all keys in `fr` but not `en` from `fr`:
191
191
  ```console
192
- $ i18n-tasks missing -t diff -f yaml en | i18n-tasks tree-rename-key en fr | i18n-tasks data-remove
192
+ $ i18n-tasks missing -t diff -f yaml en | i18n-tasks tree-mv en fr | i18n-tasks data-remove
193
193
  ```
194
194
 
195
195
  See the full list of tasks with `i18n-tasks --help`.
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- if ENV['I18N_TASKS_BIN_SIMPLECOV_COVERAGE']
5
- require_relative '../spec/bin_simplecov_helper'
6
- end
4
+ require_relative '../spec/bin_simplecov_helper' if ENV['I18N_TASKS_BIN_SIMPLECOV_COVERAGE']
7
5
 
8
6
  # prevent i18n gem warning
9
7
  require 'i18n'
@@ -9,6 +9,8 @@ en:
9
9
  args:
10
10
  default_text: 'Default: %{value}'
11
11
  desc:
12
+ all_locales: Do not expect key patterns to start with a locale, instead apply them to all
13
+ locales implicitly.
12
14
  confirm: Confirm automatically
13
15
  data_format: 'Data format: %{valid_text}.'
14
16
  key_pattern: Filter by key pattern (e.g. 'common.*')
@@ -7,6 +7,7 @@ ru:
7
7
  args:
8
8
  default_text: 'По умолчанию: %{value}'
9
9
  desc:
10
+ all_locales: Не ожидать, что маски ключа начинаются с локали. Применять маски ко всем локалям.
10
11
  confirm: Подтвердить автоматом
11
12
  data_format: 'Формат данных: %{valid_text}. %{default_text}.'
12
13
  key_pattern: Маска ключа (например, common.*)
@@ -24,10 +24,10 @@ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
24
24
  cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
25
25
  TEXT
26
26
  s.homepage = 'https://github.com/glebm/i18n-tasks'
27
- if s.respond_to?(:metadata=)
28
- s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' }
29
- end
27
+ s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' } if s.respond_to?(:metadata=)
28
+ # rubocop:disable Gemspec/RequiredRubyVersion
30
29
  s.required_ruby_version = '~> 2.1' if s.respond_to?(:required_ruby_version=)
30
+ # rubocop:enable Gemspec/RequiredRubyVersion
31
31
 
32
32
  s.files = `git ls-files`.split($/)
33
33
  s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md config/i18n-tasks.yml Gemfile]
@@ -37,7 +37,7 @@ TEXT
37
37
 
38
38
  s.add_dependency 'activesupport', '>= 4.0.2'
39
39
  s.add_dependency 'ast', '>= 2.1.0'
40
- s.add_dependency 'easy_translate', '>= 0.5.0'
40
+ s.add_dependency 'easy_translate', '>= 0.5.1'
41
41
  s.add_dependency 'erubi'
42
42
  s.add_dependency 'highline', '>= 1.7.3'
43
43
  s.add_dependency 'i18n'
@@ -101,9 +101,7 @@ class I18n::Tasks::CLI
101
101
 
102
102
  def allow_help_arg_first!(argv)
103
103
  # allow `i18n-tasks --help command` in addition to `i18n-tasks command --help`
104
- if %w[-h --help].include?(argv[0]) && argv[1] && !argv[1].start_with?('-')
105
- argv[0], argv[1] = argv[1], argv[0]
106
- end
104
+ argv[0], argv[1] = argv[1], argv[0] if %w[-h --help].include?(argv[0]) && argv[1] && !argv[1].start_with?('-')
107
105
  end
108
106
 
109
107
  def parse_command!(argv)
@@ -14,9 +14,7 @@ module I18n::Tasks
14
14
  def health(opt = {})
15
15
  forest = i18n.data_forest(opt[:locales])
16
16
  stats = i18n.forest_stats(forest)
17
- if stats[:key_count].zero?
18
- fail CommandError, t('i18n_tasks.health.no_keys_detected')
19
- end
17
+ fail CommandError, t('i18n_tasks.health.no_keys_detected') if stats[:key_count].zero?
20
18
  terminal_report.forest_stats forest, stats
21
19
  [missing(opt), unused(opt), check_normalized(opt)].detect { |result| result == :exit_1 }
22
20
  end
@@ -28,7 +28,7 @@ module I18n::Tasks
28
28
  args: %i[locales out_format missing_types]
29
29
 
30
30
  def missing(opt = {})
31
- forest = i18n.missing_keys(opt.slice(:locales, :base_locale, :missing_types))
31
+ forest = i18n.missing_keys(opt.slice(:locales, :base_locale, :types))
32
32
  print_forest forest, opt, :missing_keys
33
33
  :exit_1 unless forest.empty?
34
34
  end
@@ -59,16 +59,21 @@ module I18n::Tasks
59
59
  print_forest forest, opt
60
60
  end
61
61
 
62
+ arg :all_locales,
63
+ '-a',
64
+ '--all-locales',
65
+ t('i18n_tasks.cmd.args.desc.all_locales')
66
+
62
67
  cmd :tree_mv,
63
68
  pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN [tree (or stdin)]',
64
69
  desc: t('i18n_tasks.cmd.desc.tree_mv_key'),
65
- args: [:data_format]
70
+ args: %i[data_format all_locales]
66
71
  def tree_mv(opt = {})
67
72
  fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
68
73
  from_pattern = opt[:arguments].shift
69
74
  to_pattern = opt[:arguments].shift
70
75
  forest = forest_pos_or_stdin!(opt)
71
- forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: false)
76
+ forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: !opt[:'all-locales'])
72
77
  print_forest forest, opt
73
78
  end
74
79
 
@@ -63,9 +63,7 @@ module I18n::Tasks
63
63
 
64
64
  # @return [I18n::Tasks::Data::Tree::Siblings]
65
65
  def parse_forest(src, format)
66
- unless src
67
- fail CommandError, I18n.t('i18n_tasks.cmd.errors.pass_forest')
68
- end
66
+ fail CommandError, I18n.t('i18n_tasks.cmd.errors.pass_forest') unless src
69
67
  if format == 'keys'
70
68
  ::I18n::Tasks::Data::Tree::Siblings.from_key_names parse_keys(src)
71
69
  else
@@ -75,8 +75,12 @@ module I18n::Tasks::Data::Tree
75
75
  # TODO: support nested references better
76
76
  nodes do |node|
77
77
  next unless node.reference?
78
- new_target = old_key_to_new_key[node.value.to_s]
79
- node.value = new_target.to_sym if new_target
78
+ old_target = [(node.root.key if root), node.value.to_s].compact.join('.')
79
+ new_target = old_key_to_new_key[old_target]
80
+ if new_target
81
+ new_target = new_target.sub(/\A[^.]*\./, '') if root
82
+ node.value = new_target.to_sym
83
+ end
80
84
  end
81
85
  remove_nodes_and_emptied_ancestors! moved_nodes
82
86
  merge! moved_forest
@@ -315,12 +319,8 @@ module I18n::Tasks::Data::Tree
315
319
  private
316
320
 
317
321
  def parse_parent_opt!(opts)
318
- if opts[:parent_key]
319
- opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(key: opts[:parent_key])
320
- end
321
- if opts[:parent_attr]
322
- opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(opts[:parent_attr])
323
- end
322
+ opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(key: opts[:parent_key]) if opts[:parent_key]
323
+ opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(opts[:parent_attr]) if opts[:parent_attr]
324
324
  if opts[:parent_locale]
325
325
  opts[:parent] = ::I18n::Tasks::Data::Tree::Node.new(
326
326
  key: opts[:parent_locale], data: { locale: opts[:parent_locale] }
@@ -178,9 +178,7 @@ module I18n::Tasks
178
178
  value_or_default_or_human_key: node_value.presence || default || human_key
179
179
  )
180
180
  end
181
- if key_pattern.present?
182
- pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(key_pattern)
183
- end
181
+ pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(key_pattern) if key_pattern.present?
184
182
  keys.each do |key, node| # rubocop:disable Performance/HashEachMethods
185
183
  next if pattern_re && key !~ pattern_re
186
184
  node.value = value_proc.call(node)
@@ -38,18 +38,14 @@ module I18n::Tasks
38
38
  # @return [Array<[String, Object]>] translated list
39
39
  def fetch_google_translations(list, opts)
40
40
  from_values(list, EasyTranslate.translate(to_values(list), opts)).tap do |result|
41
- if result.blank?
42
- fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_results')
43
- end
41
+ fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_results') if result.blank?
44
42
  end
45
43
  end
46
44
 
47
45
  private
48
46
 
49
47
  def validate_google_translate_api_key!(key)
50
- if key.blank?
51
- fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_api_key')
52
- end
48
+ fail CommandError, I18n.t('i18n_tasks.google_translate.errors.no_api_key') if key.blank?
53
49
  end
54
50
 
55
51
  # @param [Array<[String, Object]>] list of key-value pairs
@@ -16,7 +16,7 @@ module I18n::Tasks
16
16
  MissingKeys.missing_keys_types
17
17
  end
18
18
 
19
- # @param types [:missing_used, :missing_diff] all if `nil`.
19
+ # @param types [:used, :diff] all if `nil`.
20
20
  # @return [Siblings]
21
21
  def missing_keys(locales: nil, types: nil, base_locale: nil)
22
22
  locales ||= self.locales
@@ -7,7 +7,7 @@ module I18n
7
7
  module Tasks
8
8
  module Reports
9
9
  class Terminal < Base # rubocop:disable Metrics/ClassLength
10
- def missing_keys(forest = task.missing_keys) # rubocop:disable Metrics/AbcSize
10
+ def missing_keys(forest = task.missing_keys)
11
11
  forest = collapse_missing_tree! forest
12
12
  if forest.present?
13
13
  print_title missing_title(forest)
@@ -45,6 +45,7 @@ module I18n::Tasks
45
45
  @raw_key = raw_key
46
46
  @default_arg = default_arg
47
47
  end
48
+ # rubocop:enable Metrics/ParameterLists
48
49
 
49
50
  def inspect
50
51
  "Occurrence(#{@path}:#{@line_num}:#{@line_pos}:#{@pos}:#{@raw_key}:#{@default_arg})"
@@ -48,9 +48,7 @@ module I18n::Tasks::Scanners
48
48
  message = send_node.children[1]
49
49
  valid_receivers = @message_receivers[message]
50
50
  # use `any?` because `include?` checks type equality, but the receiver is a Parser::AST::Node != AST::Node.
51
- if valid_receivers && valid_receivers.any? { |r| r == receiver }
52
- @callback.call(send_node, @method_name)
53
- end
51
+ @callback.call(send_node, @method_name) if valid_receivers && valid_receivers.any? { |r| r == receiver }
54
52
  # always invoke handler_missing to get nested translations in children
55
53
  handler_missing send_node
56
54
  nil
@@ -72,7 +72,6 @@ module I18n::Tasks
72
72
  if args && args[:strict]
73
73
  fail CommandError, 'the strict option is global and cannot be applied on the scanner level'
74
74
  end
75
-
76
75
  ActiveSupport::Inflector.constantize(class_name).new(
77
76
  config: merge_scanner_configs(shared_options, args || {}),
78
77
  file_finder_provider: caching_file_finder_provider,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = '0.9.19'
5
+ VERSION = '0.9.20'
6
6
  end
7
7
  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.19
4
+ version: 0.9.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-01 00:00:00.000000000 Z
11
+ date: 2018-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.5.0
47
+ version: 0.5.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.0
54
+ version: 0.5.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: erubi
57
57
  requirement: !ruby/object:Gem::Requirement