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 +4 -4
- data/.gitignore +0 -1
- data/README.md +4 -0
- data/doc/img/i18n-missing.png +0 -0
- data/lib/i18n/tasks/missing.rb +38 -11
- data/lib/i18n/tasks/task_helpers.rb +1 -0
- data/lib/i18n/tasks/unused.rb +13 -3
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/i18n_tasks_spec.rb +1 -0
- data/spec/support/0_test_codebase_env.rake +4 -0
- data/spec/support/i18n_tasks_output_matcher.rb +14 -4
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ffd7cede573f8a4cee0a811d80345a6e8ebb37
|
4
|
+
data.tar.gz: 813300ebfe3b65e3d624c6c67636121f8d874603
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e205fafc63991aae11c9a7506886b235fe2c5dd612402ebb12de0c9c9954887b97a426a8dbbcb8122251c56c65281516fff37e677b9def315d9975de6f39b8d4
|
7
|
+
data.tar.gz: 0991e4295a36944f8545ee25259307f20c239b87d1e968515c1e55895fcf252f52666272f4a1b6e09bb9e2c1b137d24f30fe5ad83ac9480859e1c8cf0bc7ae35
|
data/.gitignore
CHANGED
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
|
data/lib/i18n/tasks/missing.rb
CHANGED
@@ -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 = '
|
7
|
+
DESC = 'Missing keys and translations'
|
8
|
+
|
7
9
|
def perform
|
8
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
34
|
-
def print_locale(locale)
|
61
|
+
def p_locale(locale)
|
35
62
|
' ' + bold(locale.ljust(5))
|
36
63
|
end
|
37
64
|
|
38
|
-
def
|
65
|
+
def p_key(key)
|
39
66
|
magenta(key).ljust(50)
|
40
67
|
end
|
41
68
|
|
data/lib/i18n/tasks/unused.rb
CHANGED
@@ -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
|
data/lib/i18n/tasks/version.rb
CHANGED
data/spec/i18n_tasks_spec.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
RSpec::Matchers.define :be_i18n_keys do |expected|
|
2
|
-
|
3
|
-
|
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 =~
|
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
|
-
|
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.
|
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-
|
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
|