i18n-tasks 0.2.0 → 0.2.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/.travis.yml +4 -1
- data/README.md +40 -13
- data/doc/img/i18n-tasks.gif +0 -0
- data/lib/i18n/tasks/source_keys.rb +14 -7
- data/lib/i18n/tasks/version.rb +1 -1
- data/lib/tasks/i18n-tasks.rake +14 -13
- data/spec/fixtures/app/views/index.html.slim +1 -0
- data/spec/i18n_tasks_spec.rb +11 -4
- data/spec/source_keys_spec.rb +22 -0
- metadata +4 -2
- data/doc/img/i18n-tasks.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 191973eaa9d7a29ea1b149eef1ce61c2d79f8c4c
|
4
|
+
data.tar.gz: 8cdd8e2e5408577ce0abf3b7d78bb90c43834bd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acefe02918495e2091ac389e985491eb14542f7b54f94e8301d1aa0333e814b69ddc361d796f1a898084ddd48ab1393650cc34102e71c16a1f8917d1e2d2d741
|
7
|
+
data.tar.gz: 53c49f375246c3dc38e7c63b9a8ed27e99cb42fc2f709557cdf63040d6d4635b7ad7cff2c165887adbba042ef44e853dc6b08110af63f947eff890dea0d67603
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,23 +3,50 @@
|
|
3
3
|
|
4
4
|
Rails I18n tasks to find missing / unused translations and more. Works with slim / coffee / haml etc.
|
5
5
|
|
6
|
-

|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
10
10
|
Use `rake -T i18n` to get the list of tasks with descriptions. These are [the tasks](/lib/tasks/i18n-tasks.rake) available:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
There are reports for missing and unused translations:
|
13
|
+
```bash
|
14
|
+
rake i18n:missing
|
15
|
+
rake i18n:unused
|
16
|
+
```
|
17
|
+
|
18
|
+
To add the keys that are not in the base locale data but detected in the source do:
|
19
|
+
```bash
|
20
|
+
# add missing keys to the base locale data (I18n.default_locale)
|
21
|
+
# values set to key.humanize
|
22
|
+
rake i18n:add_missing
|
23
|
+
# or set all values to the task argument
|
24
|
+
rake i18n:add_missing[OhNoesMissing]
|
25
|
+
```
|
26
|
+
|
27
|
+
Prefill empty translations using Google Translate:
|
28
|
+
```bash
|
29
|
+
rake i18n:fill:google_translate
|
30
|
+
# this task and the ones below can also accept specific locales:
|
31
|
+
rake i18n:fill:google_translate[es+de]
|
32
|
+
```
|
33
|
+
Prefill using values from the base locale - `I8n.default_locale`:
|
34
|
+
```bash
|
35
|
+
rake i18n:fill:base_value
|
36
|
+
```
|
37
|
+
Add just blank yaml keys - `key: ''` for all missing and untranslated keys:
|
38
|
+
```bash
|
39
|
+
rake i18n:fill:blanks
|
40
|
+
```
|
41
|
+
|
42
|
+
i18n-tasks sorts the keys and writes them to their respective files:
|
43
|
+
```bash
|
44
|
+
# this happens automatically on any i18n:fill:* task
|
45
|
+
rake i18n:normalize
|
46
|
+
```
|
47
|
+
|
48
|
+
|
49
|
+
`i18n:unused` will detect pattern translations and not report them, e.g.:
|
23
50
|
|
24
51
|
```ruby
|
25
52
|
t 'category.' + category.key # 'category.arts_and_crafts' considered used
|
@@ -36,7 +63,7 @@ For more examples see [the tests](/spec/i18n_tasks_spec.rb).
|
|
36
63
|
Simply add to Gemfile:
|
37
64
|
|
38
65
|
```ruby
|
39
|
-
gem 'i18n-tasks', '~> 0.2.
|
66
|
+
gem 'i18n-tasks', '~> 0.2.1'
|
40
67
|
```
|
41
68
|
|
42
69
|
## Configuration
|
Binary file
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'find'
|
2
2
|
|
3
3
|
module I18n::Tasks::SourceKeys
|
4
|
+
DEFAULT_PATTERN = /\bt[( ]\s*(:?".+?"|:?'.+?'|:\w+)/
|
5
|
+
|
4
6
|
# find all keys in the source (relative keys are returned in absolutized)
|
5
7
|
# @return [Array<String>]
|
6
8
|
def find_source_keys
|
@@ -27,8 +29,6 @@ module I18n::Tasks::SourceKeys
|
|
27
29
|
find_source_keys.select { |k| k =~ /\#{.*?}/ || k.ends_with?('.') }.map { |k| k.split(/\.?#/)[0].presence }.compact
|
28
30
|
end
|
29
31
|
|
30
|
-
protected
|
31
|
-
|
32
32
|
# grep config, also from config/i18n-tasks.yml
|
33
33
|
# @return [Hash{String => String,Hash,Array}]
|
34
34
|
def search_config
|
@@ -42,7 +42,7 @@ module I18n::Tasks::SourceKeys
|
|
42
42
|
conf[:paths] = %w(app/) if conf[:paths].blank?
|
43
43
|
conf[:include] = Array(conf[:include]) if conf[:include].present?
|
44
44
|
conf[:exclude] = Array(conf[:exclude])
|
45
|
-
conf[:pattern] ||= conf[:pattern].present? ? Regexp.new(conf[:pattern]) :
|
45
|
+
conf[:pattern] ||= conf[:pattern].present? ? Regexp.new(conf[:pattern]) : DEFAULT_PATTERN
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -66,10 +66,9 @@ module I18n::Tasks::SourceKeys
|
|
66
66
|
keys = []
|
67
67
|
File.open(path, 'rb') do |f|
|
68
68
|
while (line = f.gets)
|
69
|
-
line.scan(search_config[:pattern]) do |
|
70
|
-
|
71
|
-
|
72
|
-
end
|
69
|
+
line.scan(search_config[:pattern]) do |match|
|
70
|
+
key = parse_key(match)
|
71
|
+
key = absolutize_key(key, path) if key.start_with? '.'
|
73
72
|
if key =~ /^[\w.\#{}]+$/
|
74
73
|
keys << key
|
75
74
|
end
|
@@ -78,4 +77,12 @@ module I18n::Tasks::SourceKeys
|
|
78
77
|
end
|
79
78
|
keys
|
80
79
|
end
|
80
|
+
|
81
|
+
private
|
82
|
+
def parse_key(match)
|
83
|
+
key = match[0]
|
84
|
+
key.slice!(0) if ':' == key[0]
|
85
|
+
key = key[1..-2] if %w(' ").include?(key[0])
|
86
|
+
key
|
87
|
+
end
|
81
88
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
data/lib/tasks/i18n-tasks.rake
CHANGED
@@ -18,21 +18,22 @@ namespace :i18n do
|
|
18
18
|
normalize_store!
|
19
19
|
end
|
20
20
|
|
21
|
+
desc 'add <key: placeholder || key.humanize> to the base locale'
|
22
|
+
task :add_missing, [:placeholder] => 'i18n:setup' do |t, args|
|
23
|
+
normalize_store!
|
24
|
+
i18n_tasks.fill_blanks!(base_locale) { |keys|
|
25
|
+
keys.map { |key|
|
26
|
+
args[:placeholder] || key.split('.').last.to_s.humanize
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
|
21
32
|
desc 'fill translations with values'
|
22
33
|
namespace :fill do
|
23
34
|
|
24
|
-
desc 'add <key: placeholder || key.humanize> to the base locale'
|
25
|
-
task :add_missing, [:placeholder] => 'i18n:setup' do |t, args|
|
26
|
-
normalize_store!
|
27
|
-
i18n_tasks.fill_blanks!(base_locale) { |keys|
|
28
|
-
keys.map { |key|
|
29
|
-
args[:placeholder] || key.split('.').last.to_s.humanize
|
30
|
-
}
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
35
|
desc 'add <key: ""> to each locale'
|
35
|
-
task :
|
36
|
+
task :blanks, [:locales] => 'i18n:setup' do |t, args|
|
36
37
|
normalize_store!
|
37
38
|
[base_locale, *non_base_locales].each do |locale|
|
38
39
|
fill_blanks!(locale) { |blank_keys| blank_keys.map { '' } }
|
@@ -40,7 +41,7 @@ namespace :i18n do
|
|
40
41
|
end
|
41
42
|
|
42
43
|
desc 'add <key: Google Translated value> to each non-base locale, uses env GOOGLE_TRANSLATE_API_KEY'
|
43
|
-
task :
|
44
|
+
task :google_translate, [:locales] => 'i18n:setup' do |t, args|
|
44
45
|
normalize_store!
|
45
46
|
non_base_locales(args).each do |locale|
|
46
47
|
fill_blanks!(locale) { |blank_keys|
|
@@ -50,7 +51,7 @@ namespace :i18n do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
desc 'add <key: base value> to each non-base locale'
|
53
|
-
task :
|
54
|
+
task :base_value, [:locales] => 'i18n:setup' do |t, args|
|
54
55
|
normalize_store!
|
55
56
|
non_base_locales(args).each do |locale|
|
56
57
|
fill_blanks!(locale) { |blank_keys| blank_keys.map { |k| t(k) } }
|
data/spec/i18n_tasks_spec.rb
CHANGED
@@ -6,10 +6,11 @@ describe 'rake i18n' do
|
|
6
6
|
it 'detects missing or identical' do
|
7
7
|
TestCodebase.capture_stderr do
|
8
8
|
TestCodebase.rake_result('i18n:missing').should be_i18n_keys %w(
|
9
|
-
en.used_but_missing.a en.
|
9
|
+
en.used_but_missing.a en.relative.index.missing
|
10
10
|
es.missing_in_es.a es.blank_in_es.a es.same_in_es.a
|
11
|
+
en.missing_symbol_key en.missing_symbol.key_two en.missing_symbol.key_three
|
11
12
|
)
|
12
|
-
end.should =~ /Missing keys and translations \(
|
13
|
+
end.should =~ /Missing keys and translations \(8\)/
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -32,9 +33,15 @@ describe 'rake i18n' do
|
|
32
33
|
end
|
33
34
|
|
34
35
|
describe 'fill:' do
|
35
|
-
it '
|
36
|
+
it 'add missing' do
|
37
|
+
TestCodebase.in_test_app_dir { YAML.load_file('config/locales/en.yml')['en']['used_but_missing'].should be_nil }
|
38
|
+
TestCodebase.rake_result('i18n:add_missing')
|
39
|
+
TestCodebase.in_test_app_dir { YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['a'].should == 'A' }
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'base_value' do
|
36
43
|
TestCodebase.in_test_app_dir { YAML.load_file('config/locales/es.yml')['es']['missing_in_es'].should be_nil }
|
37
|
-
TestCodebase.rake_result('i18n:fill:
|
44
|
+
TestCodebase.rake_result('i18n:fill:base_value')
|
38
45
|
TestCodebase.in_test_app_dir {
|
39
46
|
YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a'].should == 'EN_TEXT'
|
40
47
|
YAML.load_file('config/locales/devise.en.yml')['en']['devise']['a'].should == 'EN_TEXT'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Source keys' do
|
4
|
+
let!(:task) { I18n::Tasks::BaseTask.new }
|
5
|
+
describe 'pattern' do
|
6
|
+
let!(:pattern) { task.search_config[:pattern] }
|
7
|
+
|
8
|
+
['t "a.b"', "t 'a.b'", 't("a.b")', "t('a.b')",
|
9
|
+
"t('a.b', :arg => val)", "t('a.b', arg: val)",
|
10
|
+
"t :a_b", "t :'a.b'", 't :"a.b"', "t(:ab)", "t(:'a.b')", 't(:"a.b")'].each do |s|
|
11
|
+
it "matches #{s}" do
|
12
|
+
pattern.should match s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
["t \"a.b'", "t a.b"].each do |s|
|
17
|
+
it "does not match #{s}" do
|
18
|
+
pattern.should_not match s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
@@ -136,7 +136,7 @@ files:
|
|
136
136
|
- LICENSE.txt
|
137
137
|
- README.md
|
138
138
|
- Rakefile
|
139
|
-
- doc/img/i18n-tasks.
|
139
|
+
- doc/img/i18n-tasks.gif
|
140
140
|
- i18n-tasks.gemspec
|
141
141
|
- lib/i18n/tasks.rb
|
142
142
|
- lib/i18n/tasks/base_task.rb
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- spec/fixtures/config/i18n-tasks.yml
|
164
164
|
- spec/i18n_tasks_spec.rb
|
165
165
|
- spec/readme_spec.rb
|
166
|
+
- spec/source_keys_spec.rb
|
166
167
|
- spec/spec_helper.rb
|
167
168
|
- spec/support/fixtures.rb
|
168
169
|
- spec/support/i18n_tasks_output_matcher.rb
|
@@ -200,6 +201,7 @@ test_files:
|
|
200
201
|
- spec/fixtures/config/i18n-tasks.yml
|
201
202
|
- spec/i18n_tasks_spec.rb
|
202
203
|
- spec/readme_spec.rb
|
204
|
+
- spec/source_keys_spec.rb
|
203
205
|
- spec/spec_helper.rb
|
204
206
|
- spec/support/fixtures.rb
|
205
207
|
- spec/support/i18n_tasks_output_matcher.rb
|
data/doc/img/i18n-tasks.png
DELETED
Binary file
|