i18n-tasks 0.9.29 → 0.9.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -5
  3. data/config/locales/en.yml +6 -0
  4. data/config/locales/ru.yml +6 -0
  5. data/i18n-tasks.gemspec +9 -6
  6. data/lib/i18n/tasks/cli.rb +12 -14
  7. data/lib/i18n/tasks/command/commander.rb +1 -1
  8. data/lib/i18n/tasks/command/commands/data.rb +8 -6
  9. data/lib/i18n/tasks/command/commands/eq_base.rb +2 -2
  10. data/lib/i18n/tasks/command/commands/health.rb +7 -6
  11. data/lib/i18n/tasks/command/commands/interpolations.rb +2 -2
  12. data/lib/i18n/tasks/command/commands/meta.rb +1 -1
  13. data/lib/i18n/tasks/command/commands/missing.rb +8 -7
  14. data/lib/i18n/tasks/command/commands/tree.rb +8 -6
  15. data/lib/i18n/tasks/command/commands/usages.rb +7 -6
  16. data/lib/i18n/tasks/command/dsl.rb +4 -4
  17. data/lib/i18n/tasks/command/option_parsers/enum.rb +2 -0
  18. data/lib/i18n/tasks/command/option_parsers/locale.rb +2 -1
  19. data/lib/i18n/tasks/command/options/data.rb +1 -0
  20. data/lib/i18n/tasks/command/options/locales.rb +5 -5
  21. data/lib/i18n/tasks/concurrent/cached_value.rb +2 -0
  22. data/lib/i18n/tasks/configuration.rb +5 -4
  23. data/lib/i18n/tasks/console_context.rb +1 -1
  24. data/lib/i18n/tasks/data/adapter/yaml_adapter.rb +1 -1
  25. data/lib/i18n/tasks/data/file_formats.rb +2 -0
  26. data/lib/i18n/tasks/data/file_system_base.rb +7 -6
  27. data/lib/i18n/tasks/data/router/conservative_router.rb +2 -1
  28. data/lib/i18n/tasks/data/router/pattern_router.rb +2 -0
  29. data/lib/i18n/tasks/data/tree/node.rb +7 -5
  30. data/lib/i18n/tasks/data/tree/nodes.rb +2 -2
  31. data/lib/i18n/tasks/data/tree/siblings.rb +10 -3
  32. data/lib/i18n/tasks/data/tree/traversal.rb +17 -10
  33. data/lib/i18n/tasks/html_keys.rb +2 -4
  34. data/lib/i18n/tasks/ignore_keys.rb +4 -3
  35. data/lib/i18n/tasks/interpolations.rb +4 -2
  36. data/lib/i18n/tasks/key_pattern_matching.rb +3 -2
  37. data/lib/i18n/tasks/missing_keys.rb +33 -7
  38. data/lib/i18n/tasks/plural_keys.rb +6 -1
  39. data/lib/i18n/tasks/references.rb +2 -0
  40. data/lib/i18n/tasks/reports/base.rb +3 -2
  41. data/lib/i18n/tasks/reports/terminal.rb +10 -9
  42. data/lib/i18n/tasks/scanners/file_scanner.rb +4 -3
  43. data/lib/i18n/tasks/scanners/files/caching_file_finder.rb +0 -3
  44. data/lib/i18n/tasks/scanners/files/file_finder.rb +3 -2
  45. data/lib/i18n/tasks/scanners/occurrence_from_position.rb +3 -3
  46. data/lib/i18n/tasks/scanners/pattern_scanner.rb +7 -4
  47. data/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +4 -2
  48. data/lib/i18n/tasks/scanners/relative_keys.rb +1 -0
  49. data/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +18 -15
  50. data/lib/i18n/tasks/scanners/ruby_key_literals.rb +3 -3
  51. data/lib/i18n/tasks/scanners/scanner_multiplexer.rb +2 -0
  52. data/lib/i18n/tasks/split_key.rb +2 -0
  53. data/lib/i18n/tasks/string_interpolation.rb +1 -0
  54. data/lib/i18n/tasks/translation.rb +6 -3
  55. data/lib/i18n/tasks/translators/base_translator.rb +3 -1
  56. data/lib/i18n/tasks/translators/deepl_translator.rb +9 -2
  57. data/lib/i18n/tasks/translators/google_translator.rb +2 -0
  58. data/lib/i18n/tasks/translators/yandex_translator.rb +63 -0
  59. data/lib/i18n/tasks/used_keys.rb +15 -11
  60. data/lib/i18n/tasks/version.rb +1 -1
  61. data/templates/config/i18n-tasks.yml +1 -1
  62. data/templates/rspec/i18n_spec.rb +9 -2
  63. metadata +48 -31
  64. data/lib/i18n/tasks/rainbow_utils.rb +0 -15
@@ -2,15 +2,13 @@
2
2
 
3
3
  module I18n::Tasks
4
4
  module HtmlKeys
5
- HTML_KEY_PATTERN = /[.\-_]html\z/
6
- MAYBE_PLURAL_HTML_KEY_PATTERN = /[.\-_]html\.[^.]+\z/
5
+ HTML_KEY_PATTERN = /[.\-_]html\z/.freeze
6
+ MAYBE_PLURAL_HTML_KEY_PATTERN = /[.\-_]html\.[^.]+\z/.freeze
7
7
 
8
8
  def html_key?(full_key, locale)
9
- # rubocop:disable Style/DoubleNegation
10
9
  !!(full_key =~ HTML_KEY_PATTERN ||
11
10
  full_key =~ MAYBE_PLURAL_HTML_KEY_PATTERN &&
12
11
  depluralize_key(split_key(full_key, 2)[1], locale) =~ HTML_KEY_PATTERN)
13
- # rubocop:enable Style/DoubleNegation
14
12
  end
15
13
  end
16
14
  end
@@ -17,12 +17,13 @@ module I18n::Tasks::IgnoreKeys
17
17
  @ignore_patterns[type][locale] ||= begin
18
18
  global = ignore_config.presence || []
19
19
  type_ignore = ignore_config(type).presence || []
20
- patterns = if type_ignore.is_a?(Array)
20
+ patterns = case type_ignore
21
+ when Array
21
22
  global + type_ignore
22
- elsif type_ignore.is_a?(Hash)
23
+ when Hash
23
24
  # ignore per locale
24
25
  global + (type_ignore['all'] || []) +
25
- type_ignore.select { |k, _v| k.to_s =~ /\b#{locale}\b/ }.values.flatten(1).compact
26
+ type_ignore.select { |k, _v| k.to_s =~ /\b#{locale}\b/ }.values.flatten(1).compact
26
27
  end
27
28
  compile_patterns_re patterns
28
29
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module I18n::Tasks
4
4
  module Interpolations
5
- VARIABLE_REGEX = /%{[^}]+}/
5
+ VARIABLE_REGEX = /%{[^}]+}/.freeze
6
6
 
7
7
  def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize
8
8
  locales ||= self.locales
@@ -11,10 +11,12 @@ module I18n::Tasks
11
11
 
12
12
  data[base_locale].key_values.each do |key, value|
13
13
  next if !value.is_a?(String) || ignore_key?(key, :inconsistent_interpolations)
14
+
14
15
  base_vars = Set.new(value.scan(VARIABLE_REGEX))
15
16
  (locales - [base_locale]).each do |current_locale|
16
17
  node = data[current_locale].first.children[key]
17
- next unless node&.value&.is_a?(String)
18
+ next unless node&.value.is_a?(String)
19
+
18
20
  if base_vars != Set.new(node.value.scan(VARIABLE_REGEX))
19
21
  result.merge!(node.walk_to_root.reduce(nil) { |c, p| [p.derive(children: c)] })
20
22
  end
@@ -5,7 +5,7 @@ require 'strscan'
5
5
  module I18n::Tasks::KeyPatternMatching
6
6
  extend self # rubocop:disable Style/ModuleFunction
7
7
 
8
- MATCH_NOTHING = /\z\A/
8
+ MATCH_NOTHING = /\z\A/.freeze
9
9
 
10
10
  # one regex to match any
11
11
  def compile_patterns_re(key_patterns)
@@ -13,7 +13,7 @@ module I18n::Tasks::KeyPatternMatching
13
13
  # match nothing
14
14
  MATCH_NOTHING
15
15
  else
16
- /(?:#{ key_patterns.map { |p| compile_key_pattern p } * '|' })/m
16
+ /(?:#{key_patterns.map { |p| compile_key_pattern p } * '|'})/m
17
17
  end
18
18
  end
19
19
 
@@ -24,6 +24,7 @@ module I18n::Tasks::KeyPatternMatching
24
24
  # { a, b.c } match any in set, can use : and *, match is captured
25
25
  def compile_key_pattern(key_pattern)
26
26
  return key_pattern if key_pattern.is_a?(Regexp)
27
+
27
28
  /\A#{key_pattern_re_body(key_pattern)}\z/
28
29
  end
29
30
 
@@ -60,11 +60,13 @@ module I18n::Tasks
60
60
  locales.each_with_object(empty_forest) do |locale, forest|
61
61
  required_keys = required_plural_keys_for_locale(locale)
62
62
  next if required_keys.empty?
63
+
63
64
  tree = empty_forest
64
65
  plural_nodes data[locale] do |node|
65
66
  children = node.children
66
67
  present_keys = Set.new(children.map { |c| c.key.to_sym })
67
68
  next if present_keys.superset?(required_keys)
69
+
68
70
  tree[node.full_key] = node.derive(
69
71
  value: children.to_hash,
70
72
  children: nil,
@@ -79,12 +81,8 @@ module I18n::Tasks
79
81
  def required_plural_keys_for_locale(locale)
80
82
  @plural_keys_for_locale ||= {}
81
83
  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
84
+
85
+ @plural_keys_for_locale[locale] = plural_keys_for_locale(locale)
88
86
  end
89
87
 
90
88
  # Loads rails-i18n pluralization config for the given locale.
@@ -123,7 +121,7 @@ module I18n::Tasks
123
121
  end
124
122
 
125
123
  def locale_key_missing?(locale, key)
126
- !key_value?(key, locale) && !external_key?(key) && !ignore_key?(key, :missing)
124
+ !key_value?(key, locale) && !external_key?(key, locale) && !ignore_key?(key, :missing)
127
125
  end
128
126
 
129
127
  # @param [::I18n::Tasks::Data::Tree::Siblings] forest
@@ -136,6 +134,7 @@ module I18n::Tasks
136
134
  locale = root.key
137
135
  root.keys do |key, node|
138
136
  next unless yield node
137
+
139
138
  if locales_and_node_by_key.key?(key)
140
139
  locales_and_node_by_key[key][0] << locale
141
140
  else
@@ -154,5 +153,32 @@ module I18n::Tasks
154
153
  end
155
154
  forest
156
155
  end
156
+
157
+ private
158
+
159
+ def plural_keys_for_locale(locale)
160
+ configuration = load_rails_i18n_pluralization!(locale)
161
+ if configuration[locale.to_sym].nil?
162
+ alternate_locale = alternate_locale_from(locale)
163
+ return Set.new if configuration[alternate_locale.to_sym].nil?
164
+
165
+ return set_from_rails_i18n_pluralization(configuration, alternate_locale)
166
+ end
167
+ set_from_rails_i18n_pluralization(configuration, locale)
168
+ rescue SystemCallError, IOError
169
+ Set.new
170
+ end
171
+
172
+ def alternate_locale_from(locale)
173
+ re = /(\w{2})-*(\w{2,3})*/
174
+ match = locale.match(re)
175
+ language_code = match[1]
176
+ country_code = match[2]
177
+ "#{language_code}-#{country_code.upcase}"
178
+ end
179
+
180
+ def set_from_rails_i18n_pluralization(configuration, locale)
181
+ Set.new(configuration[locale.to_sym][:i18n][:plural][:keys])
182
+ end
157
183
  end
158
184
  end
@@ -5,12 +5,13 @@ module I18n::Tasks::PluralKeys
5
5
  # Ref: http://cldr.unicode.org/index/cldr-spec/plural-rules
6
6
  CLDR_CATEGORY_KEYS = %w[zero one two few many other].freeze
7
7
  PLURAL_KEY_SUFFIXES = Set.new CLDR_CATEGORY_KEYS
8
- PLURAL_KEY_RE = /\.(?:#{CLDR_CATEGORY_KEYS * '|'})$/
8
+ PLURAL_KEY_RE = /\.(?:#{CLDR_CATEGORY_KEYS * '|'})$/.freeze
9
9
 
10
10
  def collapse_plural_nodes!(tree)
11
11
  tree.leaves.map(&:parent).compact.uniq.each do |node|
12
12
  children = node.children
13
13
  next unless plural_forms?(children)
14
+
14
15
  node.value = children.to_hash
15
16
  node.children = nil
16
17
  node.data.merge! children.first.data
@@ -23,6 +24,7 @@ module I18n::Tasks::PluralKeys
23
24
  # @return [String] the base form if the key is a specific plural form (e.g. apple for apple.many), the key otherwise.
24
25
  def depluralize_key(key, locale = base_locale)
25
26
  return key if key !~ PLURAL_KEY_RE
27
+
26
28
  key_name = last_key_part(key)
27
29
  parent_key = key[0..- (key_name.length + 2)]
28
30
  nodes = tree("#{locale}.#{parent_key}").presence || (locale != base_locale && tree("#{base_locale}.#{parent_key}"))
@@ -37,10 +39,12 @@ module I18n::Tasks::PluralKeys
37
39
  # @yieldparam node [::I18n::Tasks::Data::Tree::Node] plural node
38
40
  def plural_nodes(tree)
39
41
  return to_enum(:plural_nodes, tree) unless block_given?
42
+
40
43
  visited = Set.new
41
44
  tree.leaves do |node|
42
45
  parent = node.parent
43
46
  next if !parent || visited.include?(parent)
47
+
44
48
  yield parent if plural_forms?(parent.children)
45
49
  visited.add(parent)
46
50
  end
@@ -49,6 +53,7 @@ module I18n::Tasks::PluralKeys
49
53
 
50
54
  def plural_forms?(s)
51
55
  return false if non_plural_other?(s)
56
+
52
57
  s.present? && s.all? { |node| node.leaf? && plural_suffix?(node.key) }
53
58
  end
54
59
 
@@ -10,12 +10,14 @@ module I18n::Tasks
10
10
  data_refs = merge_reference_trees(data_forest.select_keys { |_, node| node.reference? }))
11
11
  fail ArgumentError, 'usages must be a Data::Tree::Instance' unless usages.is_a?(Data::Tree::Siblings)
12
12
  fail ArgumentError, 'all_references must be a Data::Tree::Instance' unless data_refs.is_a?(Data::Tree::Siblings)
13
+
13
14
  raw_refs = empty_forest
14
15
  resolved_refs = empty_forest
15
16
  refs = empty_forest
16
17
  data_refs.key_to_node.each do |ref_key_part, ref_node|
17
18
  usages.each do |usage_node|
18
19
  next unless usage_node.key == ref_key_part
20
+
19
21
  if ref_node.leaf?
20
22
  process_leaf!(ref_node, usage_node, raw_refs, resolved_refs, refs)
21
23
  else
@@ -9,6 +9,7 @@ module I18n::Tasks::Reports
9
9
  end
10
10
 
11
11
  attr_reader :task
12
+
12
13
  delegate :base_locale, :locales, to: :task
13
14
 
14
15
  protected
@@ -58,6 +59,7 @@ module I18n::Tasks::Reports
58
59
 
59
60
  def format_locale(locale)
60
61
  return '' unless locale
62
+
61
63
  if locale.split('+') == task.locales.sort
62
64
  'all'
63
65
  else
@@ -67,8 +69,7 @@ module I18n::Tasks::Reports
67
69
 
68
70
  def collapse_missing_tree!(forest)
69
71
  forest = task.collapse_plural_nodes!(forest)
70
- forest = task.collapse_same_key_in_locales!(forest) { |node| node.data[:type] == :missing_used }
71
- forest
72
+ task.collapse_same_key_in_locales!(forest) { |node| node.data[:type] == :missing_used }
72
73
  end
73
74
  end
74
75
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'i18n/tasks/reports/base'
4
- require 'i18n/tasks/rainbow_utils'
5
4
  require 'terminal-table'
6
5
  module I18n
7
6
  module Tasks
@@ -76,11 +75,11 @@ module I18n
76
75
 
77
76
  def forest_stats(forest, stats = task.forest_stats(forest))
78
77
  text = if stats[:locale_count] == 1
79
- I18n.t('i18n_tasks.data_stats.text_single_locale', stats)
78
+ I18n.t('i18n_tasks.data_stats.text_single_locale', **stats)
80
79
  else
81
- I18n.t('i18n_tasks.data_stats.text', stats)
80
+ I18n.t('i18n_tasks.data_stats.text', **stats)
82
81
  end
83
- title = Rainbow(I18n.t('i18n_tasks.data_stats.title', stats.slice(:locales))).bright
82
+ title = Rainbow(I18n.t('i18n_tasks.data_stats.title', **stats.slice(:locales))).bright
84
83
  print_info "#{Rainbow(title).cyan} #{Rainbow(text).cyan}"
85
84
  end
86
85
 
@@ -107,9 +106,10 @@ module I18n
107
106
  private
108
107
 
109
108
  def missing_key_info(leaf)
110
- if leaf[:type] == :missing_used
109
+ case leaf[:type]
110
+ when :missing_used
111
111
  first_occurrence leaf
112
- elsif leaf[:type] == :missing_plural
112
+ when :missing_plural
113
113
  leaf[:data][:missing_keys].join(', ')
114
114
  else
115
115
  "#{Rainbow(leaf[:data][:missing_diff_locale]).cyan} "\
@@ -135,6 +135,7 @@ module I18n
135
135
 
136
136
  def format_reference_desc(node_data)
137
137
  return nil unless node_data
138
+
138
139
  case node_data[:ref_type]
139
140
  when :reference_usage
140
141
  Rainbow('(ref)').yellow.bright
@@ -160,9 +161,9 @@ module I18n
160
161
  print_table headings: [Rainbow(I18n.t('i18n_tasks.common.locale')).cyan.bright,
161
162
  Rainbow(I18n.t('i18n_tasks.common.key')).cyan.bright,
162
163
  I18n.t('i18n_tasks.common.value')] do |t|
163
- t.rows = locale_key_value_datas.map { |(locale, k, v, data)|
164
+ t.rows = locale_key_value_datas.map do |(locale, k, v, data)|
164
165
  [{ value: Rainbow(locale).cyan, alignment: :center }, format_key(k, data), format_value(v)]
165
- }
166
+ end
166
167
  end
167
168
  else
168
169
  puts 'ø'
@@ -170,7 +171,7 @@ module I18n
170
171
  end
171
172
 
172
173
  def print_title(title)
173
- log_stderr "#{Rainbow(title.strip).bright} #{I18n::Tasks::RainbowUtils.faint_color('|')} " \
174
+ log_stderr "#{Rainbow(title.strip).bright} #{Rainbow('|').faint} " \
174
175
  "#{"i18n-tasks v#{I18n::Tasks::VERSION}"}"
175
176
  end
176
177
 
@@ -11,10 +11,11 @@ module I18n::Tasks::Scanners
11
11
  attr_reader :config
12
12
 
13
13
  def initialize(
14
- config: {},
15
- file_finder_provider: Files::CachingFileFinderProvider.new,
16
- file_reader: Files::CachingFileReader.new
14
+ config: {},
15
+ file_finder_provider: Files::CachingFileFinderProvider.new,
16
+ file_reader: Files::CachingFileReader.new
17
17
  )
18
+ super()
18
19
  @config = config
19
20
  @file_reader = file_reader
20
21
  @file_finder = file_finder_provider.get(**config.slice(:paths, :only, :exclude))
@@ -22,9 +22,6 @@ module I18n::Tasks::Scanners::Files
22
22
  # @param (see FileFinder#traverse_files)
23
23
  # @yieldparam (see FileFinder#traverse_files)
24
24
  # @return (see FileFinder#traverse_files)
25
- def traverse_files
26
- super
27
- end
28
25
 
29
26
  alias uncached_find_files find_files
30
27
  private :uncached_find_files
@@ -15,6 +15,7 @@ module I18n::Tasks::Scanners::Files
15
15
  # Files matching any of the exclusion patterns will be excluded even if they match an inclusion pattern.
16
16
  def initialize(paths: ['.'], only: nil, exclude: [])
17
17
  fail 'paths argument is required' if paths.nil?
18
+
18
19
  @paths = paths
19
20
  @include = only
20
21
  @exclude = exclude || []
@@ -25,8 +26,8 @@ module I18n::Tasks::Scanners::Files
25
26
  # @yield [path]
26
27
  # @yieldparam path [String] the path of the found file.
27
28
  # @return [Array<of block results>]
28
- def traverse_files
29
- find_files.map { |path| yield path }
29
+ def traverse_files(&block)
30
+ find_files.map(&block)
30
31
  end
31
32
 
32
33
  # @return [Array<String>] found files
@@ -15,11 +15,11 @@ module I18n
15
15
  line_begin = contents.rindex(/^/, position - 1)
16
16
  line_end = contents.index(/.(?=\r?\n|$)/, position)
17
17
  Results::Occurrence.new(
18
- path: path,
19
- pos: position,
18
+ path: path,
19
+ pos: position,
20
20
  line_num: contents[0..position].count("\n") + 1,
21
21
  line_pos: position - line_begin + 1,
22
- line: contents[line_begin..line_end],
22
+ line: contents[line_begin..line_end],
23
23
  raw_key: raw_key
24
24
  )
25
25
  end
@@ -12,7 +12,7 @@ module I18n::Tasks::Scanners
12
12
  include OccurrenceFromPosition
13
13
  include RubyKeyLiterals
14
14
 
15
- TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:ranslate)?/
15
+ TRANSLATE_CALL_RE = /(?<=^|[^\w'\-.]|[^\w'\-]I18n\.|I18n\.)t(?:!|ranslate!?)?/.freeze
16
16
  IGNORE_LINES = {
17
17
  'coffee' => /^\s*#(?!\si18n-tasks-use)/,
18
18
  'erb' => /^\s*<%\s*#(?!\si18n-tasks-use)/,
@@ -43,10 +43,13 @@ module I18n::Tasks::Scanners
43
43
  src_pos = Regexp.last_match.offset(0).first
44
44
  location = occurrence_from_position(path, text, src_pos, raw_key: strip_literal(match[0]))
45
45
  next if exclude_line?(location.line, path)
46
+
46
47
  key = match_to_key(match, path, location)
47
48
  next unless key
49
+
48
50
  key += ':' if key.end_with?('.')
49
51
  next unless valid_key?(key)
52
+
50
53
  keys << [key, location]
51
54
  end
52
55
  keys
@@ -67,7 +70,7 @@ module I18n::Tasks::Scanners
67
70
  re && re =~ line
68
71
  end
69
72
 
70
- VALID_KEY_RE_DYNAMIC = /^(#{VALID_KEY_CHARS}|[:\#{@}\[\]])+$/
73
+ VALID_KEY_RE_DYNAMIC = /^(#{VALID_KEY_CHARS}|[:\#{@}\[\]])+$/.freeze
71
74
 
72
75
  def valid_key?(key)
73
76
  if @config[:strict]
@@ -84,7 +87,7 @@ module I18n::Tasks::Scanners
84
87
  def closest_method(occurrence)
85
88
  method = File.readlines(occurrence.path, encoding: 'UTF-8')
86
89
  .first(occurrence.line_num - 1).reverse_each.find { |x| x =~ /\bdef\b/ }
87
- method && method.strip.sub(/^def\s*/, '').sub(/[\(\s;].*$/, '')
90
+ method && method.strip.sub(/^def\s*/, '').sub(/[(\s;].*$/, '')
88
91
  end
89
92
 
90
93
  # This method only exists for backwards compatibility with monkey-patches and plugins
@@ -93,7 +96,7 @@ module I18n::Tasks::Scanners
93
96
  def default_pattern
94
97
  # capture only the first argument
95
98
  /
96
- #{translate_call_re} [\( ] \s* (?# fn call begin )
99
+ #{translate_call_re} [( ] \s* (?# fn call begin )
97
100
  (#{first_argument_re}) (?# capture the first argument)
98
101
  /x
99
102
  end
@@ -26,6 +26,7 @@ module I18n::Tasks::Scanners
26
26
  if scope
27
27
  scope_parts = extract_literal_or_array_of_literals(scope)
28
28
  return nil if scope_parts.nil? || scope_parts.empty?
29
+
29
30
  "#{scope_parts.join('.')}.#{key}"
30
31
  else
31
32
  key unless match[0] =~ /\A\w/
@@ -61,7 +62,7 @@ module I18n::Tasks::Scanners
61
62
 
62
63
  # extract literal or array of literals
63
64
  # returns nil on any other input
64
- # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
65
+ # rubocop:disable Metrics/MethodLength,Metrics/PerceivedComplexity
65
66
  def extract_literal_or_array_of_literals(s)
66
67
  literals = []
67
68
  braces_stack = []
@@ -78,6 +79,7 @@ module I18n::Tasks::Scanners
78
79
  s.each_char.with_index do |c, i|
79
80
  if c == '['
80
81
  return nil unless braces_stack.empty?
82
+
81
83
  braces_stack.push(i)
82
84
  elsif c == ']'
83
85
  break
@@ -93,6 +95,6 @@ module I18n::Tasks::Scanners
93
95
  consume_literal.call unless acc.empty?
94
96
  literals
95
97
  end
96
- # rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
98
+ # rubocop:enable Metrics/MethodLength,Metrics/PerceivedComplexity
97
99
  end
98
100
  end