i18n-tasks 0.0.4 → 0.0.5
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 +4 -4
- data/README.md +7 -1
- data/doc/img/i18n-missing.png +0 -0
- data/lib/i18n/tasks/base_task.rb +80 -2
- data/lib/i18n/tasks/missing.rb +5 -3
- data/lib/i18n/tasks/task_helpers.rb +1 -57
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/i18n_tasks_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a588b5fcc4c85ab519a9cf45074cbc8d5f77511e
|
|
4
|
+
data.tar.gz: b9d6327dfce3a34fe6c5621cc3075c121533786b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 345f4b4255b47573f1ab42d02414bae76223d9c7e6978106701ccc325417aa5203275863b6f8b927a572ebfd64d1d07241a79932a7b53f65c3d34a780e90b535
|
|
7
|
+
data.tar.gz: 8a612fad25cf93919596ffba6f1fe9d07a80f91b52267872ac6d85bd1c4f21fce36b89141725f0051cd1aa3a525e86fd30ff8e74c37a199edfc7c06e3b9cb7fc
|
data/README.md
CHANGED
|
@@ -16,6 +16,12 @@ Use `rake -T i18n` to get the list of tasks with descriptions. There are 3 tasks
|
|
|
16
16
|
t 'category.' + category.key # 'category.arts_and_crafts' considered used
|
|
17
17
|
t "category.#{category.key}" # also works
|
|
18
18
|
|
|
19
|
+
`i18n:missing` may incorrectly show framework i18n keys as missing, to work around this use `.i18nignore` file in project root:
|
|
20
|
+
|
|
21
|
+
devise.errors.unauthorized # ignore this key
|
|
22
|
+
pagination.views. # ignore the whole pattern (note the .)
|
|
23
|
+
|
|
24
|
+
|
|
19
25
|
For more examples see [the tests](https://github.com/glebm/i18n-tasks/blob/master/spec/i18n_tasks_spec.rb#L43-L59).
|
|
20
26
|
|
|
21
27
|
Installation
|
|
@@ -23,7 +29,7 @@ Installation
|
|
|
23
29
|
|
|
24
30
|
Simply add to Gemfile:
|
|
25
31
|
|
|
26
|
-
gem 'i18n-tasks', '~> 0.0.
|
|
32
|
+
gem 'i18n-tasks', '~> 0.0.5'
|
|
27
33
|
|
|
28
34
|
Configuration
|
|
29
35
|
-------------
|
data/doc/img/i18n-missing.png
CHANGED
|
Binary file
|
data/lib/i18n/tasks/base_task.rb
CHANGED
|
@@ -1,9 +1,87 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'open3'
|
|
2
|
+
require 'term/ansicolor'
|
|
2
3
|
|
|
3
4
|
module I18n
|
|
4
5
|
module Tasks
|
|
5
6
|
class BaseTask
|
|
6
|
-
include
|
|
7
|
+
include Term::ANSIColor
|
|
8
|
+
|
|
9
|
+
def run_command(*args)
|
|
10
|
+
_in, out, _err = Open3.popen3(*args)
|
|
11
|
+
out.gets nil
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# locale data hash, with locale name as root
|
|
15
|
+
def get_locale_data(locale)
|
|
16
|
+
# todo multiple files, configuration option
|
|
17
|
+
YAML.load_file "config/locales/#{locale}.yml"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# main locale file path (for writing to)
|
|
21
|
+
def locale_file_path(locale)
|
|
22
|
+
"config/locales/#{locale}.yml"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# find all keys in the source
|
|
26
|
+
def find_source_keys
|
|
27
|
+
@source_keys ||= begin
|
|
28
|
+
grep_out = run_command 'grep', '-horI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
|
|
29
|
+
used_keys = grep_out.split("\n").map { |r| r.match(/['"](.*?)['"]/)[1] }.uniq.to_set
|
|
30
|
+
used_keys = used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
|
|
31
|
+
exclude_patterns used_keys, ignore_patterns
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def exclude_patterns(keys, patterns)
|
|
36
|
+
keys.reject do |k|
|
|
37
|
+
patterns.any? { |pattern| k == pattern || pattern.end_with?('.') && k.start_with?(pattern) }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
IGNORE_FILE = '.i18nignore'
|
|
42
|
+
|
|
43
|
+
def ignore_patterns
|
|
44
|
+
@ignored_patterns ||= begin
|
|
45
|
+
if File.exists?(IGNORE_FILE)
|
|
46
|
+
File.read(IGNORE_FILE).split("\n").map {|k|
|
|
47
|
+
k.split('#')[0].strip.presence
|
|
48
|
+
}.compact.uniq
|
|
49
|
+
else
|
|
50
|
+
[]
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def find_source_pattern_keys
|
|
56
|
+
find_source_keys.select { |k| k =~ /\#{.*?}/ || k.ends_with?('.') }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def find_source_pattern_prefixes
|
|
60
|
+
find_source_pattern_keys.map { |k| k.split(/\.?#/)[0] }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# traverse hash, yielding with full key and value
|
|
64
|
+
def traverse(path = '', hash, &block)
|
|
65
|
+
hash.each do |k, v|
|
|
66
|
+
if v.is_a?(Hash)
|
|
67
|
+
traverse("#{path}.#{k}", v, &block)
|
|
68
|
+
else
|
|
69
|
+
block.call("#{path}.#{k}"[1..-1], v)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def t(hash, key)
|
|
75
|
+
key.split('.').inject(hash) { |r, seg| r.try(:[], seg) }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def base_locale
|
|
79
|
+
I18n.default_locale.to_s
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def base
|
|
83
|
+
@base ||= get_locale_data(base_locale)
|
|
84
|
+
end
|
|
7
85
|
end
|
|
8
86
|
end
|
|
9
87
|
end
|
data/lib/i18n/tasks/missing.rb
CHANGED
|
@@ -9,10 +9,12 @@ module I18n
|
|
|
9
9
|
def perform
|
|
10
10
|
missing = find_missing
|
|
11
11
|
STDERR.puts bold cyan("= #{DESC} (#{missing.length}) =")
|
|
12
|
+
STDERR.puts cyan(" This task may report framework i18n keys as missing (use .i18nignore if that happens)")
|
|
13
|
+
STDERR.puts cyan " Legend:\t#{red '✗'} - key is missing\t#{yellow bold '∅'} - translation is blank\t#{yellow bold '='} - value same as base locale"
|
|
12
14
|
status_texts = {
|
|
13
|
-
none: red("✗
|
|
14
|
-
blank: yellow(bold '∅
|
|
15
|
-
eq_base: yellow(bold "=
|
|
15
|
+
none: red("✗".ljust(6)),
|
|
16
|
+
blank: yellow(bold '∅'.ljust(6)),
|
|
17
|
+
eq_base: yellow(bold "=".ljust(6))
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
missing.sort_by { |m| m[:type] }.reverse_each do |m|
|
|
@@ -1,65 +1,9 @@
|
|
|
1
1
|
# coding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'term/ansicolor'
|
|
2
|
+
|
|
4
3
|
|
|
5
4
|
module I18n
|
|
6
5
|
module Tasks
|
|
7
6
|
module TaskHelpers
|
|
8
|
-
include Term::ANSIColor
|
|
9
|
-
def run_command(*args)
|
|
10
|
-
_in, out, _err = Open3.popen3(*args)
|
|
11
|
-
out.gets nil
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# locale data hash, with locale name as root
|
|
15
|
-
def get_locale_data(locale)
|
|
16
|
-
# todo multiple files, configuration option
|
|
17
|
-
YAML.load_file "config/locales/#{locale}.yml"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# main locale file path (for writing to)
|
|
21
|
-
def locale_file_path(locale)
|
|
22
|
-
"config/locales/#{locale}.yml"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# find all keys in the source
|
|
26
|
-
def find_source_keys
|
|
27
|
-
@source_keys ||= begin
|
|
28
|
-
grep_out = run_command 'grep', '-horI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
|
|
29
|
-
used_keys = grep_out.split("\n").map { |r| r.match(/['"](.*?)['"]/)[1] }.uniq.to_set
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def find_source_pattern_keys
|
|
34
|
-
find_source_keys.select { |k| k =~ /\#{.*?}/ || k.ends_with?('.') }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def find_source_pattern_prefixes
|
|
38
|
-
find_source_pattern_keys.map { |k| k.split(/\.?#/)[0] }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# traverse hash, yielding with full key and value
|
|
42
|
-
def traverse(path = '', hash, &block)
|
|
43
|
-
hash.each do |k, v|
|
|
44
|
-
if v.is_a?(Hash)
|
|
45
|
-
traverse("#{path}.#{k}", v, &block)
|
|
46
|
-
else
|
|
47
|
-
block.call("#{path}.#{k}"[1..-1], v)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def t(hash, key)
|
|
53
|
-
key.split('.').inject(hash) { |r, seg| r.try(:[], seg) }
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def base_locale
|
|
57
|
-
I18n.default_locale.to_s
|
|
58
|
-
end
|
|
59
7
|
|
|
60
|
-
def base
|
|
61
|
-
@base ||= get_locale_data(base_locale)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
8
|
end
|
|
65
9
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
data/spec/i18n_tasks_spec.rb
CHANGED
|
@@ -45,11 +45,17 @@ describe 'rake i18n' do
|
|
|
45
45
|
fs = {
|
|
46
46
|
'config/locales/en.yml' => {'en' => en_data}.to_yaml,
|
|
47
47
|
'config/locales/es.yml' => {'es' => es_data}.to_yaml,
|
|
48
|
+
'.i18nignore' => <<-TEXT,
|
|
49
|
+
ignored_missing_key.a # one key to ignore
|
|
50
|
+
ignored_pattern. # ignore the whole pattern
|
|
51
|
+
TEXT
|
|
48
52
|
'app/views/index.html.slim' => <<-SLIM,
|
|
49
53
|
p \#{t('ca.a')} \#{t 'ca.b'} \#{t "ca.c"}
|
|
50
54
|
p \#{t 'ca.d'} \#{t 'ca.f', i: 'world'} \#{t 'ca.e', i: 'world'}
|
|
51
55
|
p \#{t 'missing_in_es.a'} \#{t 'same_in_es.a'} \#{t 'blank_in_es.a'}
|
|
52
56
|
p = t 'used_but_missing.a'
|
|
57
|
+
p = t 'ignored_missing_key.a'
|
|
58
|
+
p = t 'ignored_pattern.some_key'
|
|
53
59
|
SLIM
|
|
54
60
|
'app/controllers/events_controller.slim' => <<-RUBY,
|
|
55
61
|
class EventsController < ApplicationController
|
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.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- glebm
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-07-
|
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|