i18n-tasks 0.1.0 → 0.1.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 +4 -4
- data/README.md +40 -26
- data/lib/i18n/tasks/base_task.rb +19 -15
- data/lib/i18n/tasks/missing.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- 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: f116de755ba0474543cb353a777bf20e7eeab5ac
|
4
|
+
data.tar.gz: 2850693394e00b2c1aad7421695aa4d42d4c4f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85aa544fd0af018aade6cf796efbfbd20028a0f296b06f48e4f4c9941fa1c79862ecd5a31c9f8aa34d0abc9908d3dd6c1a56a696557e99a10d55866a4c3d4363
|
7
|
+
data.tar.gz: cc88b01eb13bbe1c00e3d3ef89f2ec239f4b673a124cb436dc612ced9c318bd977baa32bc8daf50ae62fcfe4b7161afa686bc4225484a4598f380e7f4fded9bf
|
data/README.md
CHANGED
@@ -13,8 +13,10 @@ Use `rake -T i18n` to get the list of tasks with descriptions. There are 3 tasks
|
|
13
13
|
|
14
14
|
`i18n:unused` will detect pattern translations and not report them, e.g.:
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
```ruby
|
17
|
+
t 'category.' + category.key # 'category.arts_and_crafts' considered used
|
18
|
+
t "category.#{category.key}" # also works
|
19
|
+
```
|
18
20
|
|
19
21
|
Relative keys (`t '.title'`) are supported too.
|
20
22
|
|
@@ -25,7 +27,11 @@ Installation
|
|
25
27
|
|
26
28
|
Simply add to Gemfile:
|
27
29
|
|
28
|
-
|
30
|
+
```ruby
|
31
|
+
gem 'i18n-tasks', '~> 0.1.0'
|
32
|
+
```
|
33
|
+
|
34
|
+
`grep` is required. You likely have it already on Linux / Mac / BSD, Windows users will need to [install](http://gnuwin32.sourceforge.net/packages/grep.htm) and make sure it's available in `PATH`.
|
29
35
|
|
30
36
|
Configuration
|
31
37
|
-------------
|
@@ -33,36 +39,44 @@ Configuration
|
|
33
39
|
|
34
40
|
Tasks may incorrectly report framework i18n keys as missing. You can add `config/i18n-tasks.yml` to work around this:
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
```yaml
|
43
|
+
# do not report these keys as missing (both on blank value and no key)
|
44
|
+
ignore_missing:
|
45
|
+
- devise.errors.unauthorized # ignore this key
|
46
|
+
- pagination.views. # ignore the whole pattern (note the .)
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
# do not report these keys when they have the same value as the base locale version
|
49
|
+
ignore_eq_base:
|
50
|
+
all:
|
51
|
+
- common.ok
|
52
|
+
es,fr:
|
53
|
+
- common.brand
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
# do not report these keys as unused
|
56
|
+
ignore_unused:
|
57
|
+
- category.
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
59
|
+
# do not report these keys ever
|
60
|
+
ignore:
|
61
|
+
- kaminari.
|
62
|
+
```
|
55
63
|
|
56
64
|
|
57
65
|
By default reports I18n reads locale data from `config/locales/{locale_code}.yml`.
|
58
66
|
You can customize this, e.g.:
|
59
67
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
68
|
+
```ruby
|
69
|
+
# load all config/locales/*.locale.yml and config/locales/locale.yml:
|
70
|
+
I18n::Tasks.get_locale_data = ->(locale) {
|
71
|
+
(["config/locales/#{locale}.yml"] + Dir["config/locales/*.#{locale}.yml"]).inject({}) { |hash, path|
|
72
|
+
hash.deep_merge! YAML.load_file(path)
|
73
|
+
hash
|
74
|
+
}
|
75
|
+
}
|
76
|
+
```
|
77
|
+
|
78
|
+
---
|
79
|
+
|
80
|
+
This was originally developed for [Zuigo](http://zuigo.com/), a platform to organize and discover events.
|
67
81
|
|
68
82
|
[i18n-missing-screenshot]: https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-missing.png "rake i18n:missing output screenshot"
|
data/lib/i18n/tasks/base_task.rb
CHANGED
@@ -22,21 +22,25 @@ module I18n
|
|
22
22
|
def find_source_keys
|
23
23
|
@source_keys ||= begin
|
24
24
|
grep_out = run_command 'grep', '-HorI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
25
|
+
if grep_out
|
26
|
+
used_keys = grep_out.split("\n").map { |r|
|
27
|
+
key = r.match(/['"](.*?)['"]/)[1]
|
28
|
+
# absolutize relative key:
|
29
|
+
if key.start_with? '.'
|
30
|
+
path = r.split(':')[0]
|
31
|
+
# normalized path
|
32
|
+
path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
33
|
+
# key prefix based on path
|
34
|
+
prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.')
|
35
|
+
"#{prefix}#{key}"
|
36
|
+
else
|
37
|
+
key
|
38
|
+
end
|
39
|
+
}.uniq
|
40
|
+
used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
|
41
|
+
else
|
42
|
+
[]
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
data/lib/i18n/tasks/missing.rb
CHANGED
@@ -17,7 +17,7 @@ module I18n
|
|
17
17
|
eq_base: yellow(bold "=".ljust(6))
|
18
18
|
}
|
19
19
|
|
20
|
-
missing.
|
20
|
+
missing.sort { |a, b| (l = a[:locale] <=> b[:locale]).zero? ? a[:type] <=> b[:type] : l }.each do |m|
|
21
21
|
locale, key, base_value = m[:locale], m[:key], m[:base_value]
|
22
22
|
status_text = ' ' + status_texts[m[:type]]
|
23
23
|
case m[:type]
|
data/lib/i18n/tasks/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|