i18n-tasks 0.0.3 → 0.0.4

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: e4a2353a4fb77dc7513547b875f9e22959bf0e65
4
- data.tar.gz: 327f3a171a0991b71aba09799d7e508967f88a63
3
+ metadata.gz: b9ffd7cede573f8a4cee0a811d80345a6e8ebb37
4
+ data.tar.gz: 813300ebfe3b65e3d624c6c67636121f8d874603
5
5
  SHA512:
6
- metadata.gz: cc558aa7656a508ce7fa49a49e3b842bb4922625c6387edef62242b9d40f22fdc1052e2ec06429246ca66e85d583f26afb4fe1ac51c6b01409ad1e9f18fe9af7
7
- data.tar.gz: e2a120d28f080bb114b9fe31749a881224b654e6beeac8fb60494a6c982a8928cf480cc19a9f98d4a21ea56347bb6795d7cbb6763c89d0db99500ccdfcab77bb
6
+ metadata.gz: e205fafc63991aae11c9a7506886b235fe2c5dd612402ebb12de0c9c9954887b97a426a8dbbcb8122251c56c65281516fff37e677b9def315d9975de6f39b8d4
7
+ data.tar.gz: 0991e4295a36944f8545ee25259307f20c239b87d1e968515c1e55895fcf252f52666272f4a1b6e09bb9e2c1b137d24f30fe5ad83ac9480859e1c8cf0bc7ae35
data/.gitignore CHANGED
@@ -23,7 +23,6 @@ Gemfile.lock
23
23
  InstalledFiles
24
24
  _yardoc
25
25
  coverage
26
- doc/
27
26
  lib/bundler/man
28
27
  pkg
29
28
  rdoc
data/README.md CHANGED
@@ -3,6 +3,8 @@ i18n-tasks [![Build Status](https://travis-ci.org/glebm/i18n-tasks.png?branch=m
3
3
 
4
4
  Rails I18n tasks to find missing / unused translations and more. Works with slim / coffee / haml etc.
5
5
 
6
+ ![i18n-missing-screenshot]
7
+
6
8
  Use `rake -T i18n` to get the list of tasks with descriptions. There are 3 tasks available at the moment:
7
9
 
8
10
  * `i18n:missing` task shows all the keys that have not been translated yet *([source](https://github.com/glebm/i18n-tasks/blob/master/lib/i18n/tasks/missing.rb))*
@@ -27,3 +29,5 @@ Configuration
27
29
  -------------
28
30
 
29
31
  Currently i18n-tasks only reports / writes to locale data in `config/locales/{locale_code}.yml`. *PRs making this configurable welcome!*
32
+
33
+ [i18n-missing-screenshot]: https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-missing.png "rake i18n:missing output screenshot"
Binary file
@@ -1,16 +1,44 @@
1
+ # coding: utf-8
1
2
  require 'i18n/tasks/base_task'
2
3
 
3
4
  module I18n
4
5
  module Tasks
5
6
  class Missing < BaseTask
6
- DESC = 'find all missing keys and missing translations'
7
+ DESC = 'Missing keys and translations'
8
+
7
9
  def perform
8
- $stderr.puts DESC
10
+ missing = find_missing
11
+ STDERR.puts bold cyan("= #{DESC} (#{missing.length}) =")
12
+ status_texts = {
13
+ none: red("✗ #{bold 'none'}".ljust(19)),
14
+ blank: yellow(bold '∅ blank'.ljust(11)),
15
+ eq_base: yellow(bold "= #{base_locale.ljust(9)}")
16
+ }
17
+
18
+ missing.sort_by { |m| m[:type] }.reverse_each do |m|
19
+ locale, key, base_value = m[:locale], m[:key], m[:base_value]
20
+ status_text = ' ' + status_texts[m[:type]]
21
+ case m[:type]
22
+ when :none
23
+ puts "#{red p_locale base_locale} #{status_text} #{p_key key}"
24
+ when :blank
25
+ puts "#{p_locale locale} #{status_text} #{p_key key} #{cyan base_value}"
26
+ when :eq_base
27
+ puts "#{p_locale locale} #{status_text} #{p_key key} #{cyan base_value}"
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+
34
+ def find_missing
35
+ missing = []
36
+
9
37
  # missing keys (in the code but not in base locale data)
10
38
  pattern_prefixes = find_source_pattern_prefixes
11
39
  find_source_keys.each do |key|
12
40
  if t(base[base_locale], key).blank? && !pattern_prefixes.any? { |pp| key.start_with?(pp) }
13
- puts "#{red print_locale base_locale} #{red "✗ #{bold 'none'}"}\t #{print_key key}"
41
+ missing << {locale: :en, type: :none, key: key}
14
42
  end
15
43
  end
16
44
 
@@ -19,23 +47,22 @@ module I18n
19
47
  trn = get_locale_data(locale)[locale]
20
48
  traverse base[base_locale] do |key, base_value|
21
49
  translated = t(trn, key)
22
- data = "\t #{print_key key} #{cyan base_value}"
23
- s = if translated.blank?
24
- "#{yellow bold '∅ blank'}#{data}"
50
+ if translated.blank?
51
+ missing << {locale: locale, key: key, type: :blank, base_value: base_value}
25
52
  elsif translated == base_value
26
- "#{yellow bold "= #{base_locale}" }#{data}"
53
+ missing << {locale: locale, key: key, type: :eq_base, base_value: base_value}
27
54
  end
28
- puts "#{print_locale locale} #{s}" if s
29
55
  end
30
56
  end
57
+
58
+ missing
31
59
  end
32
60
 
33
- private
34
- def print_locale(locale)
61
+ def p_locale(locale)
35
62
  ' ' + bold(locale.ljust(5))
36
63
  end
37
64
 
38
- def print_key(key)
65
+ def p_key(key)
39
66
  magenta(key).ljust(50)
40
67
  end
41
68
 
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'open3'
2
3
  require 'term/ansicolor'
3
4
 
@@ -1,16 +1,26 @@
1
+ # coding: utf-8
1
2
  require 'i18n/tasks/base_task'
2
3
 
3
4
  module I18n
4
5
  module Tasks
5
6
  class Unused < BaseTask
7
+ DESC = 'Unused i18n keys'
6
8
  def perform
9
+ unused = find_unused
10
+ STDERR.puts bold cyan("= #{DESC} (#{unused.length}) =")
11
+ unused.each do |(key, value)|
12
+ puts " #{magenta(key).ljust(60)}\t#{cyan value}"
13
+ end
14
+ end
15
+
16
+ def find_unused
7
17
  used_keys = find_source_keys
8
18
  pattern_prefixes = find_source_pattern_prefixes
19
+ r = []
9
20
  traverse base[base_locale] do |key, value|
10
- if !used_keys.include?(key) && !pattern_prefixes.any? { |pp| key.start_with?(pp) }
11
- puts "#{yellow 'unused'.ljust(10)}#{magenta(key).ljust(60)}\t#{cyan value}"
12
- end
21
+ r << [key, value] if !used_keys.include?(key) && !pattern_prefixes.any? { |pp| key.start_with?(pp) }
13
22
  end
23
+ r
14
24
  end
15
25
  end
16
26
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Tasks
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe 'rake i18n' do
@@ -0,0 +1,4 @@
1
+ task :environment do
2
+ I18n.default_locale = 'en'
3
+ I18n.available_locales = %w(en es)
4
+ end
@@ -1,14 +1,24 @@
1
1
  RSpec::Matchers.define :be_i18n_keys do |expected|
2
- match do |actual|
3
- r = actual.split("\n").map { |x|
2
+ locale_re = /^\w{2}\b/
3
+ extract_keys = ->(actual){
4
+ locales = I18n.available_locales.map(&:to_s)
5
+ actual.split("\n").map { |x|
4
6
  x.strip!
5
7
  key = x.gsub(/\s+/, ' ').split(' ').reverse.detect { |p| p && p.include?('.') }
6
- if x =~ /^\w{2}\b/
8
+ if x =~ locale_re && locales.include?(x[0..1]) && !(key =~ locale_re && locales.include(key[0..1]))
7
9
  x.split(' ', 2)[0] + '.' + key
8
10
  else
9
11
  key
10
12
  end
11
13
  }
12
- r.sort == expected.sort
14
+ }
15
+
16
+ match do |actual|
17
+ extract_keys.(actual).sort == expected.sort
18
+ end
19
+
20
+ failure_message_for_should do |actual|
21
+ "Expected #{expected.sort}, but had #{extract_keys.(actual).sort}"
22
+
13
23
  end
14
24
  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.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-28 00:00:00.000000000 Z
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,6 +109,7 @@ files:
109
109
  - LICENSE.txt
110
110
  - README.md
111
111
  - Rakefile
112
+ - doc/img/i18n-missing.png
112
113
  - i18n-tasks.gemspec
113
114
  - lib/i18n/tasks.rb
114
115
  - lib/i18n/tasks/base_task.rb
@@ -121,6 +122,7 @@ files:
121
122
  - lib/tasks/i18n-tasks.rake
122
123
  - spec/i18n_tasks_spec.rb
123
124
  - spec/spec_helper.rb
125
+ - spec/support/0_test_codebase_env.rake
124
126
  - spec/support/i18n_tasks_output_matcher.rb
125
127
  - spec/support/test_codebase.rb
126
128
  - spec/support/test_codebase_env.rake
@@ -151,6 +153,7 @@ summary: Rails I18n tasks to find missing / unused translations and more
151
153
  test_files:
152
154
  - spec/i18n_tasks_spec.rb
153
155
  - spec/spec_helper.rb
156
+ - spec/support/0_test_codebase_env.rake
154
157
  - spec/support/i18n_tasks_output_matcher.rb
155
158
  - spec/support/test_codebase.rb
156
159
  - spec/support/test_codebase_env.rake