i18n-tasks 0.7.0 → 0.7.1

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
  SHA1:
3
- metadata.gz: b7b2e4af8b66aed1ff33eba3cb802322ceea57db
4
- data.tar.gz: 951337877ce07c613b5765b609dd0c3508742a89
3
+ metadata.gz: 1adbf899220bdaffacd8f8b95f74eb2c102268a6
4
+ data.tar.gz: 028937e7d90a8af43ad66497a0b3f869c52fb599
5
5
  SHA512:
6
- metadata.gz: 8b04b6fbabcd0598b2473162142679e81ef5eec9301c3c9362bc44a81084517fbf8d254c1015b0b5dc5365261730550c1356db3cc7d57e56a78ff3a85be1e471
7
- data.tar.gz: 2ecb5edaa048079936459dc1f8d607aafe441abb352e7ee0e8585c1a5e251336d8206cc0e7840a3a95a84de78963baafd181a46f779120322ef5736466bfbb35
6
+ metadata.gz: 16ee9ac1ea60d4ed1d04881d9c40fdc88478c16c9d0471d8b94d31a77a2a44e915b4236ad8d13a7c3517d40e7179ff9909c5215f828b8d193b19b61b59ee0747
7
+ data.tar.gz: 025e2fee7f5590377e4b8ddfb2cec98256e45ff120ef5219d545064d745a23430b15cd071683edf0aa44618e22cdb3b78073be13c1c64a826e18e958db5cc4b7
data/CHANGES.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## 0.7.1
2
+
3
+ * 1.9.3 compatibility
4
+
5
+ ## 0.7.0
6
+
7
+ New tasks:
8
+
9
+ * `i18n-tasks health` to display missing and unused keys along with other information
10
+ * `i18n-tasks tree-` to manipulate trees
11
+ * `i18n-tasks data-` to look up and manipulate locale data
12
+ * Better `help` for all commands
13
+ * Minor bug fixes
14
+
15
+ Internally:
16
+
17
+ * Refactored commands DSL
18
+ * `add-missing`, `remove-unused` implemented in terms of the new `tree-` commands
19
+
1
20
  ## 0.6.3
2
21
 
3
22
  * Strict mode added for `unused` and `remove-unused`. When passed `-s` or `--strict`, these tasks will not attempt to infer dynamic key usages, such as `t("category.#{category.key}")`.
data/README.md CHANGED
@@ -25,7 +25,7 @@ i18n-tasks can be used with any project using [i18n][i18n-gem] (default in Rails
25
25
  Add to Gemfile:
26
26
 
27
27
  ```ruby
28
- gem 'i18n-tasks', '~> 0.7.0'
28
+ gem 'i18n-tasks', '~> 0.7.1'
29
29
  ```
30
30
 
31
31
  Copy default [configuration file](#configuration) (optional):
@@ -2,8 +2,6 @@ module I18n::Tasks
2
2
  module Command
3
3
  module Options
4
4
  module EnumOpt
5
- delegate :enum_opt, to: :class
6
-
7
5
  DEFAULT_ENUM_OPT_ERROR = proc { |bad, good|
8
6
  I18n.t('i18n_tasks.cmd.enum_opt.invalid_one', invalid: bad, valid: good * ', ')
9
7
  }
@@ -38,6 +36,10 @@ module I18n::Tasks
38
36
  raise CommandError.new error_msg.call(invalid, valid)
39
37
  end
40
38
  end
39
+
40
+ def enum_opt(*args)
41
+ self.class.enum_opt(*args)
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -9,8 +9,6 @@ module I18n
9
9
  base.extend ClassMethods
10
10
  end
11
11
 
12
- delegate :adapter_for_path, :adapter_by_name, :adapter_name, :adapter_names, to: :class
13
-
14
12
  def adapter_dump(tree, format)
15
13
  adapter_op :dump, format, tree, write_config(format)
16
14
  end
@@ -20,7 +18,7 @@ module I18n
20
18
  end
21
19
 
22
20
  def adapter_op(op, format, tree, config)
23
- adapter_by_name(format).send(op, tree, config)
21
+ self.class.adapter_by_name(format).send(op, tree, config)
24
22
  rescue Exception => e
25
23
  raise CommandError.new("#{format} #{op} error: #{e.message}")
26
24
  end
@@ -36,14 +34,13 @@ module I18n
36
34
  end
37
35
 
38
36
  def load_file(path)
39
- adapter = adapter_for_path(path)
40
- adapter.parse ::File.read(path), read_config(adapter_name(adapter))
37
+ adapter_parse ::File.read(path), self.class.adapter_name_for_path(path)
41
38
  end
42
39
 
43
40
  def write_tree(path, tree)
44
41
  ::FileUtils.mkpath(File.dirname path)
45
42
  ::File.open(path, 'w') { |f|
46
- f.write(adapter_dump(tree.to_hash, adapter_name(adapter_for_path(path))))
43
+ f.write adapter_dump(tree.to_hash, self.class.adapter_name_for_path(path))
47
44
  }
48
45
  end
49
46
 
@@ -54,22 +51,16 @@ module I18n
54
51
  (@fn_patterns ||= []) << [name, pattern, adapter]
55
52
  end
56
53
 
57
- def adapter_for_path(path)
54
+ def adapter_name_for_path(path)
58
55
  @fn_patterns.detect { |(_name, pattern, _adapter)|
59
56
  ::File.fnmatch(pattern, path)
60
- }.try(:last) or raise CommandError.new("Adapter not found for #{path}. Registered adapters: #{@fn_patterns.inspect}")
57
+ }.try(:first) or raise CommandError.new("Adapter not found for #{path}. Registered adapters: #{@fn_patterns.inspect}")
61
58
  end
62
59
 
63
60
  def adapter_names
64
61
  @fn_patterns.map(&:first)
65
62
  end
66
63
 
67
- def adapter_name(adapter)
68
- @fn_patterns.detect { |(adapter_name, _pattern, registered_adapter)|
69
- registered_adapter == adapter
70
- }.try(:first) or raise CommandError.new("Adapter #{adapter.inspect} is not registered. Registered adapters: #{@fn_patterns.inspect}")
71
- end
72
-
73
64
  def adapter_by_name(name)
74
65
  name = name.to_s
75
66
  @fn_patterns.detect { |(adapter_name, _pattern, _adapter)|
@@ -5,12 +5,12 @@ module I18n::Tasks::PluralKeys
5
5
  PLURAL_KEY_RE = /\.(?:#{PLURAL_KEY_SUFFIXES.to_a * '|'})$/
6
6
 
7
7
  def collapse_plural_nodes!(tree)
8
- tree.leaves.select(&:parent?).map(&:parent).uniq.each do |node|
8
+ tree.leaves.map(&:parent).compact.uniq.each do |node|
9
9
  children = node.children
10
- if children.present? && children.all? { |c| PLURAL_KEY_SUFFIXES.include?(c.key) }
10
+ if plural_forms?(children)
11
11
  node.value = children.to_hash
12
- node.data.merge!(children.first.data)
13
12
  node.children = nil
13
+ node.data.merge! children.first.data
14
14
  end
15
15
  end
16
16
  tree
@@ -23,10 +23,18 @@ module I18n::Tasks::PluralKeys
23
23
  return key if key !~ PLURAL_KEY_RE
24
24
  parent_key = split_key(key)[0..-2] * '.'
25
25
  nodes = tree("#{locale}.#{parent_key}").presence || (locale != base_locale && tree("#{base_locale}.#{parent_key}"))
26
- if nodes && nodes.all? { |x| x.leaf? && ".#{x.key}" =~ PLURAL_KEY_RE }
26
+ if nodes && plural_forms?(nodes)
27
27
  parent_key
28
28
  else
29
29
  key
30
30
  end
31
31
  end
32
+
33
+ def plural_forms?(s)
34
+ s.present? && s.all? { |node| node.leaf? && plural_suffix?(node.key) }
35
+ end
36
+
37
+ def plural_suffix?(key)
38
+ PLURAL_KEY_SUFFIXES.include?(key)
39
+ end
32
40
  end
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  module I18n
3
3
  module Tasks
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
6
6
  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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis