i18n-tasks 0.2.12 → 0.2.13
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/Gemfile +1 -1
- data/README.md +13 -11
- data/lib/i18n/tasks/configuration.rb +10 -1
- data/lib/i18n/tasks/fill_tasks.rb +18 -9
- data/lib/i18n/tasks/relative_keys.rb +6 -4
- data/lib/i18n/tasks/reports/terminal.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/relative_keys_spec.rb +22 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49fa662d252e8f812eedc6b79d0ecdf4e55b6979
|
4
|
+
data.tar.gz: 97deaf64038b50772fa22ea2c997f8997550fe3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0edb92a5f181c337826b617ca8d4d2d6d7d8a7299d6ba1fd7580eb2bf304e6789f69c842dcb8ddfbab57aa44b267e6bbf9d0852be18fb1fc33a683e8bb93dd9f
|
7
|
+
data.tar.gz: 576b66877ab863f4c06f2dffb351d11968e7ea73593c87390108227ba319b3618317f5c63b84697f94d057c4276b76771d20bc92018c9d03eddfdba26a43f347
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -81,21 +81,11 @@ Simply add to Gemfile:
|
|
81
81
|
gem 'i18n-tasks', '~> 0.2.10'
|
82
82
|
```
|
83
83
|
|
84
|
-
If
|
84
|
+
If not using Rails, require the tasks in Rakefile:
|
85
85
|
|
86
86
|
```ruby
|
87
87
|
# Rakefile
|
88
88
|
load 'tasks/i18n-tasks.rake'
|
89
|
-
|
90
|
-
# to prepare the environment add dependency to i18n:setup:
|
91
|
-
namespace :i18n do
|
92
|
-
task :setup => 'environment'
|
93
|
-
end
|
94
|
-
|
95
|
-
task :environment do
|
96
|
-
# set `I18n.avaliable_locales` and `I18.default_locale`, etc
|
97
|
-
# ...
|
98
|
-
end
|
99
89
|
```
|
100
90
|
|
101
91
|
## Configuration
|
@@ -171,6 +161,18 @@ search:
|
|
171
161
|
pattern: "\\bt[( ]\\s*(:?\".+?\"|:?'.+?'|:\\w+)"
|
172
162
|
```
|
173
163
|
|
164
|
+
To configure paths for relative key resolution:
|
165
|
+
|
166
|
+
```yaml
|
167
|
+
# directories containing relative keys
|
168
|
+
relative_roots:
|
169
|
+
# default:
|
170
|
+
- app/views
|
171
|
+
# add a custom one:
|
172
|
+
- app/views-mobile
|
173
|
+
```
|
174
|
+
|
175
|
+
|
174
176
|
### Fine-tuning
|
175
177
|
|
176
178
|
Tasks may incorrectly report framework i18n keys as missing, also some patterns may not be detected.
|
@@ -38,6 +38,7 @@ module I18n::Tasks::Configuration
|
|
38
38
|
search_config = (config[:search] || {}).with_indifferent_access
|
39
39
|
search_config.tap do |conf|
|
40
40
|
conf[:paths] = %w(app/) if conf[:paths].blank?
|
41
|
+
conf[:relative_roots] = %w( app/views ) if conf[:relative_roots].blank?
|
41
42
|
conf[:include] = Array(conf[:include]) if conf[:include].present?
|
42
43
|
conf[:exclude] = Array(conf[:exclude])
|
43
44
|
conf[:pattern] = conf[:pattern].present? ? Regexp.new(conf[:pattern]) : DEFAULT_PATTERN
|
@@ -45,6 +46,14 @@ module I18n::Tasks::Configuration
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def relative_roots
|
50
|
+
@config_sections[:relative_roots] ||= config[:relative_roots].presence || %w(app/views)
|
51
|
+
end
|
52
|
+
|
53
|
+
def relative_roots=(paths)
|
54
|
+
@config_sections[:relative_roots] = paths
|
55
|
+
end
|
56
|
+
|
48
57
|
# translation config
|
49
58
|
# @return [Hash{String => String,Hash,Array}]
|
50
59
|
def translation_config
|
@@ -54,4 +63,4 @@ module I18n::Tasks::Configuration
|
|
54
63
|
conf
|
55
64
|
end
|
56
65
|
end
|
57
|
-
end
|
66
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module I18n::Tasks::FillTasks
|
2
2
|
def add_missing!(locale = base_locale, placeholder = nil)
|
3
3
|
normalize_store! locale
|
4
|
-
set_blank_values! locale
|
4
|
+
set_blank_values! locale do |keys|
|
5
5
|
keys.map { |key|
|
6
6
|
placeholder || key.split('.').last.to_s.humanize
|
7
7
|
}
|
@@ -22,8 +22,13 @@ module I18n::Tasks::FillTasks
|
|
22
22
|
locales = non_base_locales(locales)
|
23
23
|
normalize_store! locales
|
24
24
|
locales.each do |locale|
|
25
|
-
|
26
|
-
|
25
|
+
blank_keys = find_blank_keys(locale).select { |k|
|
26
|
+
tr = t(k)
|
27
|
+
tr.present? && tr.is_a?(String)
|
28
|
+
}
|
29
|
+
if blank_keys.present?
|
30
|
+
translated = blank_keys.zip google_translate(blank_keys.map { |k| t(k) }, to: locale, from: base_locale)
|
31
|
+
data[locale] = data[locale].deep_merge(list_to_tree translated)
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
@@ -41,14 +46,18 @@ module I18n::Tasks::FillTasks
|
|
41
46
|
|
42
47
|
# fill blank values with values from passed block
|
43
48
|
# @param [String] locale
|
44
|
-
|
45
|
-
|
49
|
+
def set_blank_values!(locale = base_locale, &fill_with)
|
50
|
+
blank_keys = find_blank_keys locale
|
51
|
+
list = blank_keys.zip fill_with.call(blank_keys)
|
52
|
+
data[locale] = data[locale].deep_merge(list_to_tree(list))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def find_blank_keys(locale, include_missing = (locale == base_locale))
|
46
57
|
blank_keys = traverse_map_if(data[base_locale]) { |key, value|
|
47
58
|
key if !key_value?(key, locale) && !ignore_key?(key, :missing)
|
48
59
|
}
|
49
60
|
blank_keys += keys_not_in_base if include_missing
|
50
|
-
|
51
|
-
list = blank_keys.uniq.zip fill_with.call(blank_keys)
|
52
|
-
data[locale] = data[locale].deep_merge(list_to_tree(list))
|
61
|
+
blank_keys.uniq
|
53
62
|
end
|
54
|
-
end
|
63
|
+
end
|
@@ -3,11 +3,13 @@ module I18n::Tasks::RelativeKeys
|
|
3
3
|
# @param key [String] relative i18n key (starts with a .)
|
4
4
|
# @param path [String] path to the file containing the key
|
5
5
|
# @return [String] absolute version of the key
|
6
|
-
def absolutize_key(key, path)
|
6
|
+
def absolutize_key(key, path, roots = relative_roots)
|
7
7
|
# normalized path
|
8
|
-
path
|
8
|
+
path = File.expand_path path
|
9
|
+
(path_root = roots.map { |path| File.expand_path path }.sort.reverse.detect { |root| path.start_with?(root + '/') }) or
|
10
|
+
raise "No relative key root detected for \"#{key}\" at #{path}. Please set relative_roots in config/i18n-tasks.yml (currently set to #{relative_roots})"
|
9
11
|
# key prefix based on path
|
10
|
-
prefix = path.gsub(%r(
|
12
|
+
prefix = path.gsub(%r(#{path_root}/|(\.[^/]+)*$), '').tr('/', '.').gsub(%r(\._), '.')
|
11
13
|
"#{prefix}#{key}"
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
@@ -22,7 +22,7 @@ module I18n
|
|
22
22
|
base_value = ''
|
23
23
|
else
|
24
24
|
locale = magenta rec[:locale]
|
25
|
-
base_value = cyan rec[:base_value].to_s.strip
|
25
|
+
base_value = cyan rec[:base_value].to_s.strip
|
26
26
|
end
|
27
27
|
[{value: locale, alignment: :center},
|
28
28
|
{value: glyph, alignment: :center},
|
data/lib/i18n/tasks/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe 'Relative keys' do
|
3
|
+
let(:task) { I18n::Tasks::BaseTask.new }
|
4
|
+
|
5
|
+
describe 'absolutize_key' do
|
6
|
+
|
7
|
+
context 'default settings' do
|
8
|
+
it 'works' do
|
9
|
+
task.absolutize_key('.title', 'app/views/movies/show.html.slim').should == 'movies.show.title'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'custom roots' do
|
14
|
+
it 'works' do
|
15
|
+
task.relative_roots = %w(app/views-mobile)
|
16
|
+
task.absolutize_key('.title', 'app/views-mobile/movies/show.html.slim').should == 'movies.show.title'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
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.2.
|
4
|
+
version: 0.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -227,6 +227,7 @@ files:
|
|
227
227
|
- spec/i18n_tasks_spec.rb
|
228
228
|
- spec/key_pattern_matching_spec.rb
|
229
229
|
- spec/readme_spec.rb
|
230
|
+
- spec/relative_keys_spec.rb
|
230
231
|
- spec/source_keys_spec.rb
|
231
232
|
- spec/spec_helper.rb
|
232
233
|
- spec/support/fixtures.rb
|
@@ -270,6 +271,7 @@ test_files:
|
|
270
271
|
- spec/i18n_tasks_spec.rb
|
271
272
|
- spec/key_pattern_matching_spec.rb
|
272
273
|
- spec/readme_spec.rb
|
274
|
+
- spec/relative_keys_spec.rb
|
273
275
|
- spec/source_keys_spec.rb
|
274
276
|
- spec/spec_helper.rb
|
275
277
|
- spec/support/fixtures.rb
|