i18n-tasks 0.9.13 → 0.9.14

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: 414af08a4707037cdb353bba1ed426fd44852906
4
- data.tar.gz: 986fd27c576e0763f1980ba70fa45e7cad81ce95
3
+ metadata.gz: 4f6dc7facc584ec90bee3fd89b5222c645c0207d
4
+ data.tar.gz: 0c09aea76d0b9c8494f6544c99e7b698374887dc
5
5
  SHA512:
6
- metadata.gz: 9cd51331aa6e088f79d0d06d28c88b1b32b5321c25af2821c638639ebf40ea28b121ad1ac056f37d1ace4e702589282df29957d9e0be9877fc444b97e31daa39
7
- data.tar.gz: 46339dd43fcb62d8630bb348df8ceee774d90ced3eab072f0565e66df1ae426228ad81e5584b28e3d346e5bac81f2f4988c04879ca594d63c74175d3e8b59e38
6
+ metadata.gz: b1f5f755ef3f26541331ecf6aaee38bf68958018b28bd22d94b8aa2b6e930277789d36186debb785fb7a139ec68fdf1024df8e18d5145a263a99d8c4d91f8237
7
+ data.tar.gz: 976c51c8ad42d3c538713d353172b7db8bc0b519fc50cf37e613b03e665b9a19d535352138fd484aa9534a9c51e65a1a18091440b32fbc03cf21f1cbbe053553
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.13'
27
+ gem 'i18n-tasks', '~> 0.9.14'
28
28
  ```
29
29
 
30
30
  Copy the default [configuration file](#configuration):
data/i18n-tasks.gemspec CHANGED
@@ -30,8 +30,8 @@ TEXT
30
30
  s.required_ruby_version = '~> 2.1' if s.respond_to?(:required_ruby_version=)
31
31
 
32
32
  s.files = `git ls-files`.split($/)
33
- s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w(CHANGES.md config/i18n-tasks.yml Gemfile)
34
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } - %w(i18n-tasks.cmd)
33
+ s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md config/i18n-tasks.yml Gemfile]
34
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } - %w[i18n-tasks.cmd]
35
35
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
36
36
  s.require_paths = ['lib']
37
37
 
@@ -101,7 +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?('-')
104
+ if %w[-h --help].include?(argv[0]) && argv[1] && !argv[1].start_with?('-')
105
105
  argv[0], argv[1] = argv[1], argv[0]
106
106
  end
107
107
  end
@@ -14,7 +14,7 @@ module I18n::Tasks
14
14
  cmd :normalize,
15
15
  pos: '[locale ...]',
16
16
  desc: t('i18n_tasks.cmd.desc.normalize'),
17
- args: %i(locales pattern_router)
17
+ args: %i[locales pattern_router]
18
18
 
19
19
  def normalize(opt = {})
20
20
  i18n.normalize_store! opt[:locales], opt[:pattern_router]
@@ -49,7 +49,7 @@ module I18n::Tasks
49
49
  cmd :data,
50
50
  pos: '[locale ...]',
51
51
  desc: t('i18n_tasks.cmd.desc.data'),
52
- args: %i(locales out_format)
52
+ args: %i[locales out_format]
53
53
 
54
54
  def data(opt = {})
55
55
  print_forest i18n.data_forest(opt[:locales]), opt
@@ -58,7 +58,7 @@ module I18n::Tasks
58
58
  cmd :data_merge,
59
59
  pos: '[tree ...]',
60
60
  desc: t('i18n_tasks.cmd.desc.data_merge'),
61
- args: %i(data_format nostdin)
61
+ args: %i[data_format nostdin]
62
62
 
63
63
  def data_merge(opt = {})
64
64
  forest = merge_forests_stdin_and_pos!(opt)
@@ -69,7 +69,7 @@ module I18n::Tasks
69
69
  cmd :data_write,
70
70
  pos: '[tree]',
71
71
  desc: t('i18n_tasks.cmd.desc.data_write'),
72
- args: %i(data_format nostdin)
72
+ args: %i[data_format nostdin]
73
73
 
74
74
  def data_write(opt = {})
75
75
  forest = forest_pos_or_stdin!(opt)
@@ -80,7 +80,7 @@ module I18n::Tasks
80
80
  cmd :data_remove,
81
81
  pos: '[tree]',
82
82
  desc: t('i18n_tasks.cmd.desc.data_remove'),
83
- args: %i(data_format nostdin)
83
+ args: %i[data_format nostdin]
84
84
 
85
85
  def data_remove(opt = {})
86
86
  removed = i18n.data.remove_by_key!(forest_pos_or_stdin!(opt))
@@ -9,7 +9,7 @@ module I18n::Tasks
9
9
  cmd :eq_base,
10
10
  pos: '[locale ...]',
11
11
  desc: t('i18n_tasks.cmd.desc.eq_base'),
12
- args: %i(locales out_format)
12
+ args: %i[locales out_format]
13
13
 
14
14
  def eq_base(opt = {})
15
15
  print_forest i18n.eq_base_keys(opt), opt, :eq_base_keys
@@ -9,7 +9,7 @@ module I18n::Tasks
9
9
  cmd :health,
10
10
  pos: '[locale ...]',
11
11
  desc: t('i18n_tasks.cmd.desc.health'),
12
- args: %i(locales out_format)
12
+ args: %i[locales out_format]
13
13
 
14
14
  def health(opt = {})
15
15
  forest = i18n.data_forest(opt[:locales])
@@ -25,7 +25,7 @@ module I18n::Tasks
25
25
  cmd :missing,
26
26
  pos: '[locale ...]',
27
27
  desc: t('i18n_tasks.cmd.desc.missing'),
28
- args: %i(locales out_format missing_types)
28
+ args: %i[locales out_format missing_types]
29
29
 
30
30
  def missing(opt = {})
31
31
  forest = i18n.missing_keys(opt.slice(:locales, :base_locale, :missing_types))
@@ -20,7 +20,7 @@ module I18n::Tasks
20
20
  cmd :tree_merge,
21
21
  pos: '[[tree] [tree] ... (or stdin)]',
22
22
  desc: t('i18n_tasks.cmd.desc.tree_merge'),
23
- args: %i(data_format nostdin)
23
+ args: %i[data_format nostdin]
24
24
 
25
25
  def tree_merge(opts = {})
26
26
  print_forest merge_forests_stdin_and_pos!(opts), opts
@@ -29,7 +29,7 @@ module I18n::Tasks
29
29
  cmd :tree_filter,
30
30
  pos: '[pattern] [tree (or stdin)]',
31
31
  desc: t('i18n_tasks.cmd.desc.tree_filter'),
32
- args: %i(data_format pattern)
32
+ args: %i[data_format pattern]
33
33
 
34
34
  def tree_filter(opts = {})
35
35
  pattern = arg_or_pos! :pattern, opts
@@ -75,7 +75,7 @@ module I18n::Tasks
75
75
  cmd :tree_subtract,
76
76
  pos: '[[tree] [tree] ... (or stdin)]',
77
77
  desc: t('i18n_tasks.cmd.desc.tree_subtract'),
78
- args: %i(data_format nostdin)
78
+ args: %i[data_format nostdin]
79
79
 
80
80
  def tree_subtract(opt = {})
81
81
  forests = forests_stdin_and_pos! opt, 2
@@ -86,7 +86,7 @@ module I18n::Tasks
86
86
  cmd :tree_set_value,
87
87
  pos: '[VALUE] [tree (or stdin)]',
88
88
  desc: t('i18n_tasks.cmd.desc.tree_set_value'),
89
- args: %i(value data_format nostdin pattern)
89
+ args: %i[value data_format nostdin pattern]
90
90
 
91
91
  def tree_set_value(opt = {})
92
92
  value = arg_or_pos! :value, opt
@@ -13,7 +13,7 @@ module I18n::Tasks
13
13
  cmd :find,
14
14
  pos: '[pattern]',
15
15
  desc: t('i18n_tasks.cmd.desc.find'),
16
- args: %i(out_format pattern strict)
16
+ args: %i[out_format pattern strict]
17
17
 
18
18
  def find(opt = {})
19
19
  opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
@@ -24,7 +24,7 @@ module I18n::Tasks
24
24
  cmd :unused,
25
25
  pos: '[locale ...]',
26
26
  desc: t('i18n_tasks.cmd.desc.unused'),
27
- args: %i(locales out_format strict)
27
+ args: %i[locales out_format strict]
28
28
 
29
29
  def unused(opt = {})
30
30
  forest = i18n.unused_keys(opt.slice(:locales, :strict))
@@ -35,7 +35,7 @@ module I18n::Tasks
35
35
  cmd :remove_unused,
36
36
  pos: '[locale ...]',
37
37
  desc: t('i18n_tasks.cmd.desc.remove_unused'),
38
- args: %i(locales out_format strict confirm)
38
+ args: %i[locales out_format strict confirm]
39
39
 
40
40
  def remove_unused(opt = {})
41
41
  unused_keys = i18n.unused_keys(opt.slice(:locales, :strict))
@@ -36,7 +36,7 @@ module I18n::Tasks
36
36
 
37
37
  def call(values, *)
38
38
  values = Array(values)
39
- return @valid if values == %w(all)
39
+ return @valid if values == %w[all]
40
40
  invalid = values - @valid
41
41
  if invalid.empty?
42
42
  if values.empty?
@@ -37,7 +37,7 @@ module I18n::Tasks
37
37
 
38
38
  # @param [#base_locale,#locales] context
39
39
  def call(vals, context)
40
- if vals == %w(all) || vals.blank?
40
+ if vals == %w[all] || vals.blank?
41
41
  context.locales
42
42
  else
43
43
  move_base_locale_to_front!(vals.map { |v| v == 'base' ? context.base_locale : v }, context.base_locale)
@@ -8,7 +8,7 @@ module I18n::Tasks
8
8
  module Data
9
9
  include Command::DSL
10
10
 
11
- DATA_FORMATS = %w(yaml json keys).freeze
11
+ DATA_FORMATS = %w[yaml json keys].freeze
12
12
  OUT_FORMATS = ['terminal-table', *DATA_FORMATS, 'inspect'].freeze
13
13
 
14
14
  format_arg = proc do |type, values|
@@ -14,10 +14,10 @@ module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength
14
14
  @config || (self.config = {})
15
15
  end
16
16
 
17
- CONFIG_FILES = %w(
17
+ CONFIG_FILES = %w[
18
18
  config/i18n-tasks.yml config/i18n-tasks.yml.erb
19
19
  i18n-tasks.yml i18n-tasks.yml.erb
20
- ).freeze
20
+ ].freeze
21
21
 
22
22
  def file_config
23
23
  file = CONFIG_FILES.detect { |f| File.exist?(f) }
@@ -160,7 +160,7 @@ Skipping a nil key found in #{path.inspect}:
160
160
  value: #{value.inspect}
161
161
  Nil keys are not supported by i18n.
162
162
  The following unquoted YAML keys result in a nil key:
163
- #{%w(null Null NULL ~).join(', ')}
163
+ #{%w[null Null NULL ~].join(', ')}
164
164
  See http://yaml.org/type/null.html
165
165
  TEXT
166
166
  elsif value.is_a?(Hash)
@@ -2,7 +2,7 @@
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)
5
+ PLURAL_KEY_SUFFIXES = Set.new %w[zero one two few many other]
6
6
  PLURAL_KEY_RE = /\.(?:#{PLURAL_KEY_SUFFIXES.to_a * '|'})$/
7
7
 
8
8
  def collapse_plural_nodes!(tree)
@@ -36,7 +36,7 @@ module I18n::Tasks::Scanners::Files
36
36
  log_warn "None of the search.paths exist #{@paths.inspect}" if paths.empty?
37
37
  Find.find(*paths) do |path|
38
38
  is_dir = File.directory?(path)
39
- hidden = File.basename(path).start_with?('.') && !%w(. ./).include?(path)
39
+ hidden = File.basename(path).start_with?('.') && !%w[. ./].include?(path)
40
40
  not_incl = @include && !path_fnmatch_any?(path, @include)
41
41
  excl = path_fnmatch_any?(path, @exclude)
42
42
  if is_dir || hidden || not_incl || excl
@@ -6,12 +6,12 @@ module I18n::Tasks::Scanners
6
6
  class RubyAstCallFinder
7
7
  include AST::Processor::Mixin
8
8
 
9
- # @param messages [Array<Symbol>] method names to intercept.
10
- # @param receivers [Array<nil, AST::Node>] receivers of the `messages` to intercept.
11
- def initialize(messages:, receivers:)
9
+ # @param receiver_messages [Set<Pair<[nil, AST::Node>, Symbol>>] The receiver-message pairs to look for.
10
+ def initialize(receiver_messages:)
12
11
  super()
13
- @messages = Set.new(messages).freeze
14
- @receivers = Set.new(receivers).freeze
12
+ @message_receivers = receiver_messages.each_with_object({}) do |(receiver, message), t|
13
+ (t[message] ||= []) << receiver
14
+ end
15
15
  end
16
16
 
17
17
  # @param root_node [Parser::AST:Node]
@@ -46,13 +46,13 @@ module I18n::Tasks::Scanners
46
46
  def on_send(send_node)
47
47
  receiver = send_node.children[0]
48
48
  message = send_node.children[1]
49
- if @messages.include?(message) &&
50
- # use `any?` because `include?` checks type equality, but the receiver is a Parser::AST::Node != AST::Node.
51
- @receivers.any? { |r| r == receiver }
49
+ valid_receivers = @message_receivers[message]
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
52
  @callback.call(send_node, @method_name)
53
- else
54
- handler_missing send_node
55
53
  end
54
+ # always invoke handler_missing to get nested translations in children
55
+ handler_missing send_node
56
56
  nil
57
57
  end
58
58
 
@@ -15,12 +15,13 @@ module I18n::Tasks::Scanners
15
15
  include AST::Sexp
16
16
 
17
17
  MAGIC_COMMENT_PREFIX = /\A.\s*i18n-tasks-use\s+/
18
+ RECEIVER_MESSAGES = [nil, AST::Node.new(:const, [nil, :I18n])].product(%i[t translate])
18
19
 
19
- def initialize(messages: %i(t translate), receivers: [nil, s(:const, nil, :I18n)], **args)
20
+ def initialize(receiver_messages: RECEIVER_MESSAGES, **args)
20
21
  super(args)
21
22
  @parser = ::Parser::CurrentRuby.new
22
23
  @magic_comment_parser = ::Parser::CurrentRuby.new
23
- @call_finder = RubyAstCallFinder.new(messages: messages, receivers: receivers)
24
+ @call_finder = RubyAstCallFinder.new(receiver_messages: receiver_messages)
24
25
  end
25
26
 
26
27
  protected
@@ -93,7 +94,7 @@ module I18n::Tasks::Scanners
93
94
  node.children.detect do |child|
94
95
  next unless child.type == :pair
95
96
  key_node = child.children[0]
96
- %i(sym str).include?(key_node.type) && key_node.children[0].to_s == key
97
+ %i[sym str].include?(key_node.type) && key_node.children[0].to_s == key
97
98
  end
98
99
  end
99
100
 
@@ -110,9 +111,9 @@ module I18n::Tasks::Scanners
110
111
  # @return [String, nil] `nil` is returned only when a dynamic value is encountered in strict mode
111
112
  # or the node type is not supported.
112
113
  def extract_string(node, array_join_with: nil, array_flatten: false, array_reject_blank: false)
113
- if %i(sym str int).include?(node.type)
114
+ if %i[sym str int].include?(node.type)
114
115
  node.children[0].to_s
115
- elsif %i(true false).include?(node.type)
116
+ elsif %i[true false].include?(node.type)
116
117
  node.type.to_s
117
118
  elsif :nil == node.type
118
119
  ''
@@ -126,9 +127,9 @@ module I18n::Tasks::Scanners
126
127
  # `nil` is returned when a dynamic value is encountered in strict mode. Propagate:
127
128
  return nil if str.nil?
128
129
  end
129
- elsif !config[:strict] && %i(dsym dstr).include?(node.type)
130
+ elsif !config[:strict] && %i[dsym dstr].include?(node.type)
130
131
  node.children.map do |child|
131
- if %i(sym str).include?(child.type)
132
+ if %i[sym str].include?(child.type)
132
133
  child.children[0].to_s
133
134
  else
134
135
  child.loc.expression.source
@@ -146,12 +147,12 @@ module I18n::Tasks::Scanners
146
147
  # @return [String, nil] `nil` is returned only when a dynamic value is encountered in strict mode.
147
148
  def extract_array_as_string(node, array_join_with:, array_flatten: false, array_reject_blank: false)
148
149
  children_strings = node.children.map do |child|
149
- if %i(sym str int true false).include?(child.type)
150
+ if %i[sym str int true false].include?(child.type)
150
151
  extract_string child
151
152
  else
152
153
  # ignore dynamic argument in strict mode
153
154
  return nil if config[:strict]
154
- if %i(dsym dstr).include?(child.type) || (:array == child.type && array_flatten)
155
+ if %i[dsym dstr].include?(child.type) || (:array == child.type && array_flatten)
155
156
  extract_string(child, array_join_with: array_join_with)
156
157
  else
157
158
  "\#{#{child.loc.expression.source}}"
@@ -15,9 +15,9 @@ require 'i18n/tasks/scanners/pattern_mapper'
15
15
  module I18n::Tasks
16
16
  module UsedKeys # rubocop:disable Metrics/ModuleLength
17
17
  SEARCH_DEFAULTS = {
18
- paths: %w(app/).freeze,
19
- relative_roots: %w(app/controllers app/helpers app/mailers app/presenters app/views).freeze,
20
- scanners: [['::I18n::Tasks::Scanners::RubyAstScanner', only: %w(*.rb)]],
18
+ paths: %w[app/].freeze,
19
+ relative_roots: %w[app/controllers app/helpers app/mailers app/presenters app/views].freeze,
20
+ scanners: [['::I18n::Tasks::Scanners::RubyAstScanner', only: %w[*.rb]]],
21
21
  strict: true
22
22
  }.tap do |defaults|
23
23
  defaults[:scanners] << ['::I18n::Tasks::Scanners::PatternWithScopeScanner',
@@ -29,8 +29,8 @@ module I18n::Tasks
29
29
  'erb' => %q(^\s*<%\s*#(?!\si18n-tasks-use)) }.freeze]
30
30
  end
31
31
 
32
- ALWAYS_EXCLUDE = %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
33
- *.yml *.json *.zip *.tar.gz).freeze
32
+ ALWAYS_EXCLUDE = %w[*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
33
+ *.yml *.json *.zip *.tar.gz *.swf *.flv].freeze
34
34
 
35
35
  # Find all keys in the source and return a forest with the keys in absolute form and their occurrences.
36
36
  #
@@ -109,10 +109,10 @@ module I18n::Tasks
109
109
 
110
110
  def merge_scanner_configs(a, b)
111
111
  a.deep_merge(b).tap do |c|
112
- %i(scanners paths relative_roots).each do |key|
112
+ %i[scanners paths relative_roots].each do |key|
113
113
  c[key] = a[key] if b[key].blank?
114
114
  end
115
- %i(exclude).each do |key|
115
+ %i[exclude].each do |key|
116
116
  merged = Array(a[key]) + Array(b[key])
117
117
  c[key] = merged unless merged.empty?
118
118
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Tasks
5
- VERSION = '0.9.13'
5
+ VERSION = '0.9.14'
6
6
  end
7
7
  end
@@ -31,7 +31,7 @@ data:
31
31
  # - config/locales/%{locale}.yml
32
32
 
33
33
  ## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
34
- # router: convervative_router
34
+ # router: conservative_router
35
35
 
36
36
  yaml:
37
37
  write:
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.13
4
+ version: 0.9.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport