i18n-tasks 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/i18n/tasks/base_task.rb +17 -3
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/i18n_tasks_spec.rb +26 -22
- 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: 249e36d0665a2fda7758aede212244f485083b54
|
4
|
+
data.tar.gz: 149073894264064e8972f43833fdffb4df4d2e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 772c68ce93f166f9c41886a3de694088031efb5433dd58cb8f3da032c91a3a5be3b55027d460a29f63ee2a41c7f9ad7d033a5d1abe4bb8693ea3cb175b409c3b
|
7
|
+
data.tar.gz: 354dd75548fc81da5eb335be15472dcf96fcd269e8c6ff077ec1c44833a10011e2aea69aecd79a8e1b93cde6a9b478ba56e6a8ca38eca89f6f431dcd202a44f9
|
data/README.md
CHANGED
@@ -16,11 +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
|
-
|
19
|
+
Relative keys (`t '.title'`) are supported too.
|
20
20
|
|
21
|
-
|
22
|
-
pagination.views. # ignore the whole pattern (note the .)
|
21
|
+
`i18n:missing` may incorrectly show framework i18n keys as missing, to work around this use `.i18nignore` file in project root:
|
23
22
|
|
23
|
+
devise.errors.unauthorized # ignore this key
|
24
|
+
pagination.views. # ignore the whole pattern (note the .)
|
24
25
|
|
25
26
|
For more examples see [the tests](https://github.com/glebm/i18n-tasks/blob/master/spec/i18n_tasks_spec.rb#L43-L59).
|
26
27
|
|
@@ -29,7 +30,7 @@ Installation
|
|
29
30
|
|
30
31
|
Simply add to Gemfile:
|
31
32
|
|
32
|
-
gem 'i18n-tasks', '~> 0.0.
|
33
|
+
gem 'i18n-tasks', '~> 0.0.7'
|
33
34
|
|
34
35
|
Configuration
|
35
36
|
-------------
|
data/lib/i18n/tasks/base_task.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'open3'
|
2
3
|
require 'term/ansicolor'
|
3
4
|
|
@@ -22,11 +23,24 @@ module I18n
|
|
22
23
|
"config/locales/#{locale}.yml"
|
23
24
|
end
|
24
25
|
|
25
|
-
# find all keys in the source
|
26
|
+
# find all keys in the source (relative keys are returned in absolutized)
|
26
27
|
def find_source_keys
|
27
28
|
@source_keys ||= begin
|
28
|
-
grep_out = run_command 'grep', '-
|
29
|
-
used_keys = grep_out.split("\n").map { |r|
|
29
|
+
grep_out = run_command 'grep', '-HorI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/'
|
30
|
+
used_keys = grep_out.split("\n").map { |r|
|
31
|
+
key = r.match(/['"](.*?)['"]/)[1]
|
32
|
+
# absolutize relative key:
|
33
|
+
if key.start_with?('.')
|
34
|
+
path = r.split(':')[0]
|
35
|
+
# normalized path
|
36
|
+
path = Pathname.new(File.expand_path path).relative_path_from(Pathname.new(Dir.pwd)).to_s
|
37
|
+
# key prefix based on path
|
38
|
+
prefix = path.gsub(%r(app/views/|(\.[^/]+)*$), '').tr('/', '.')
|
39
|
+
"#{prefix}#{key}"
|
40
|
+
else
|
41
|
+
key
|
42
|
+
end
|
43
|
+
}.uniq.to_set
|
30
44
|
used_keys = used_keys.reject { |k| k !~ /^[\w.\#{}]+$/ }
|
31
45
|
exclude_patterns used_keys, ignore_patterns
|
32
46
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
data/spec/i18n_tasks_spec.rb
CHANGED
@@ -33,40 +33,44 @@ describe 'rake i18n' do
|
|
33
33
|
'unused' => {'a' => v},
|
34
34
|
'missing_in_es' => {'a' => v},
|
35
35
|
'same_in_es' => {'a' => v},
|
36
|
-
'blank_in_es' => {'a' => v}
|
36
|
+
'blank_in_es' => {'a' => v},
|
37
|
+
'relative' => {'index' => {'title' => v}}
|
37
38
|
}
|
38
39
|
}
|
39
40
|
|
40
|
-
en_data
|
41
|
-
es_data
|
42
|
-
es_data['same_in_es']['a']
|
43
|
-
es_data['blank_in_es']['a']
|
41
|
+
en_data = gen_data.('EN_TEXT')
|
42
|
+
es_data = gen_data.('ES_TEXT').except('missing_in_es')
|
43
|
+
es_data['same_in_es']['a'] = 'EN_TEXT'
|
44
|
+
es_data['blank_in_es']['a'] = ''
|
44
45
|
|
45
46
|
fs = {
|
46
|
-
'config/locales/en.yml'
|
47
|
-
'config/locales/es.yml'
|
48
|
-
'.i18nignore'
|
49
|
-
|
47
|
+
'config/locales/en.yml' => {'en' => en_data}.to_yaml,
|
48
|
+
'config/locales/es.yml' => {'es' => es_data}.to_yaml,
|
49
|
+
'.i18nignore' => <<-TEXT,
|
50
|
+
ignored_missing_key.a # one key to ignore
|
50
51
|
|
51
|
-
|
52
|
+
ignored_pattern. # ignore the whole pattern
|
52
53
|
TEXT
|
53
54
|
'app/views/index.html.slim' => <<-SLIM,
|
54
55
|
p \#{t('ca.a')} \#{t 'ca.b'} \#{t "ca.c"}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
p \#{t 'ca.d'} \#{t 'ca.f', i: 'world'} \#{t 'ca.e', i: 'world'}
|
57
|
+
p \#{t 'missing_in_es.a'} \#{t 'same_in_es.a'} \#{t 'blank_in_es.a'}
|
58
|
+
p = t 'used_but_missing.a'
|
59
|
+
p = t 'ignored_missing_key.a'
|
60
|
+
p = t 'ignored_pattern.some_key'
|
61
|
+
SLIM
|
62
|
+
'app/views/relative/index.html.slim' => <<-SLIM,
|
63
|
+
p = t '.title'
|
60
64
|
SLIM
|
61
65
|
'app/controllers/events_controller.slim' => <<-RUBY,
|
62
66
|
class EventsController < ApplicationController
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def show
|
68
|
+
redirect_to :edit, notice: I18n.t('cb.a')
|
69
|
+
I18n.t("cb.b", i: "Hello")
|
70
|
+
I18n.t("hash_pattern.\#{some_value}", i: "Hello")
|
71
|
+
I18n.t("hash_pattern2." + some_value, i: "Hello")
|
72
|
+
end
|
73
|
+
end
|
70
74
|
RUBY
|
71
75
|
}
|
72
76
|
TestCodebase.setup fs
|
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.7
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|