i18n-tasks 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +9 -0
- data/README.md +46 -36
- data/Rakefile +2 -2
- data/lib/i18n/tasks/base_task.rb +2 -0
- data/lib/i18n/tasks/commands.rb +55 -35
- data/lib/i18n/tasks/commands_base.rb +36 -9
- data/lib/i18n/tasks/configuration.rb +14 -13
- data/lib/i18n/tasks/console_context.rb +0 -1
- data/lib/i18n/tasks/data.rb +2 -2
- data/lib/i18n/tasks/data/adapter/json_adapter.rb +6 -2
- data/lib/i18n/tasks/data/file_formats.rb +19 -4
- data/lib/i18n/tasks/data/file_system_base.rb +1 -1
- data/lib/i18n/tasks/data/tree/node.rb +11 -37
- data/lib/i18n/tasks/data/tree/nodes.rb +6 -2
- data/lib/i18n/tasks/data/tree/siblings.rb +53 -29
- data/lib/i18n/tasks/data/tree/traversal.rb +4 -2
- data/lib/i18n/tasks/fill_tasks.rb +5 -2
- data/lib/i18n/tasks/ignore_keys.rb +1 -1
- data/lib/i18n/tasks/locale_pathname.rb +1 -1
- data/lib/i18n/tasks/logging.rb +2 -0
- data/lib/i18n/tasks/missing_keys.rb +74 -31
- data/lib/i18n/tasks/plural_keys.rb +4 -3
- data/lib/i18n/tasks/reports/base.rb +8 -5
- data/lib/i18n/tasks/reports/spreadsheet.rb +15 -3
- data/lib/i18n/tasks/reports/terminal.rb +62 -23
- data/lib/i18n/tasks/scanners/base_scanner.rb +4 -2
- data/lib/i18n/tasks/scanners/relative_keys.rb +21 -0
- data/lib/i18n/tasks/split_key.rb +39 -0
- data/lib/i18n/tasks/used_keys.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/fixtures/app/views/index.html.slim +2 -0
- data/spec/i18n_tasks_spec.rb +19 -5
- data/spec/locale_pathname_spec.rb +24 -0
- data/spec/locale_tree/siblings_spec.rb +41 -4
- data/spec/split_key_spec.rb +27 -0
- data/spec/support/i18n_tasks_output_matcher.rb +7 -13
- data/spec/support/trees.rb +4 -0
- data/templates/config/i18n-tasks.yml +82 -0
- data/templates/rspec/i18n_spec.rb +18 -0
- metadata +10 -3
- data/lib/i18n/tasks/relative_keys.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03263ddf669098e8580e4656d41e7b15d2ba5721
|
4
|
+
data.tar.gz: ae4bcf9dee99a2e6cb19e6ee2d52cc34b281e335
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69aff7e4e6369e2fe1c622255bfda9290a3141eeb28be0fa368af1be3f568e1934d65ee77e66d180025bd2c9279ca4a0aff73e7135fa21b538b1a00941e26540
|
7
|
+
data.tar.gz: e21ca15833a7a7822ce166599863e3d6184cdc7a9535740554cf7e7b29a10e7c013cb34a3be4b54d6a8be4a5d53fb18a1038a9d3a2ce4bbeef06664e2d5f8a1e
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.6.0
|
2
|
+
|
3
|
+
* New output format options for reports: yaml, json, and inspect.
|
4
|
+
* Templates for config and rspec.
|
5
|
+
* Keys with values same as base locale have been moved from `missing` into a separate task, `eq-base`.
|
6
|
+
* `missing` now also shows keys that are present in some locale but not in base locale.
|
7
|
+
* Terminal output: no more Type column in `missing`, first code usage shown for keys missing base value.
|
8
|
+
* `relative_roots` configuration key moved to `search.relative_roots`, deprecation warning (removed in the next minor).
|
9
|
+
|
1
10
|
## 0.5.4
|
2
11
|
|
3
12
|
* ActiveSupport 3 compatibility
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ i18n-tasks can be used with any project using [i18n][i18n-gem] (default in Rails
|
|
18
18
|
Add to Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem 'i18n-tasks', '~> 0.
|
21
|
+
gem 'i18n-tasks', '~> 0.6.0'
|
22
22
|
```
|
23
23
|
|
24
24
|
|
@@ -36,14 +36,16 @@ Available commands:
|
|
36
36
|
|
37
37
|
missing show missing translations
|
38
38
|
unused show unused translations
|
39
|
+
eq-base show translations equal to base value
|
40
|
+
find show where the keys are used in the code
|
39
41
|
translate-missing translate missing keys with Google Translate
|
40
42
|
add-missing add missing keys to the locales
|
41
|
-
find show where the keys are used in the code
|
42
43
|
normalize normalize translation data: sort and move to the right files
|
43
44
|
remove-unused remove unused keys
|
44
45
|
config display i18n-tasks configuration
|
45
46
|
xlsx-report save missing and unused translations to an Excel file
|
46
|
-
irb
|
47
|
+
irb REPL session within i18n-tasks context
|
48
|
+
gem-path show path to the gem
|
47
49
|
|
48
50
|
See `<command> --help` for more information on a specific command.
|
49
51
|
```
|
@@ -122,11 +124,10 @@ Translation data storage, key usage search, and other [settings](#configuration)
|
|
122
124
|
Configuration is read from `config/i18n-tasks.yml` or `config/i18n-tasks.yml.erb`.
|
123
125
|
Inspect configuration with `i18n-tasks config`.
|
124
126
|
|
127
|
+
Install the default config file with:
|
125
128
|
|
126
|
-
|
127
|
-
|
128
|
-
```ruby
|
129
|
-
i18n-tasks config > config/i18n-tasks.yml
|
129
|
+
```bash
|
130
|
+
cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml spec/
|
130
131
|
```
|
131
132
|
|
132
133
|
### Locales
|
@@ -239,6 +240,12 @@ search:
|
|
239
240
|
paths:
|
240
241
|
- 'app/'
|
241
242
|
- 'vendor/'
|
243
|
+
# paths for relative key resolution:
|
244
|
+
relative_roots:
|
245
|
+
# default:
|
246
|
+
- app/views
|
247
|
+
# add a custom one:
|
248
|
+
- app/views-mobile
|
242
249
|
# include only files matching this glob pattern (default: blank = include all files)
|
243
250
|
include:
|
244
251
|
- '*.rb'
|
@@ -254,18 +261,6 @@ search:
|
|
254
261
|
- "^\\s*[#/](?!\\si18n-tasks-use)"
|
255
262
|
```
|
256
263
|
|
257
|
-
To configure paths for relative key resolution:
|
258
|
-
|
259
|
-
```yaml
|
260
|
-
# config/i18n-tasks.yml
|
261
|
-
# directories containing relative keys
|
262
|
-
relative_roots:
|
263
|
-
# default:
|
264
|
-
- app/views
|
265
|
-
# add a custom one:
|
266
|
-
- app/views-mobile
|
267
|
-
```
|
268
|
-
|
269
264
|
It is also possible to use a custom key usage scanner by setting `search.scanner` to a class name.
|
270
265
|
See this basic [pattern scanner](/lib/i18n/tasks/scanners/pattern_scanner.rb) for reference.
|
271
266
|
|
@@ -320,25 +315,12 @@ translation:
|
|
320
315
|
## RSpec integration
|
321
316
|
|
322
317
|
You might want to test for missing and unused translations as part of your test suite.
|
323
|
-
|
324
|
-
|
325
|
-
```ruby
|
326
|
-
# spec/i18n_spec.rb:
|
327
|
-
require 'spec_helper'
|
328
|
-
require 'i18n/tasks'
|
318
|
+
Install the spec file:
|
329
319
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
it 'does not have missing keys' do
|
334
|
-
expect(i18n.missing_keys).to be_empty
|
335
|
-
end
|
336
|
-
|
337
|
-
it 'does not have unused keys' do
|
338
|
-
expect(i18n.unused_keys).to be_empty
|
339
|
-
end
|
340
|
-
end
|
320
|
+
```bash
|
321
|
+
cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
|
341
322
|
```
|
323
|
+
|
342
324
|
### XLSX
|
343
325
|
|
344
326
|
Export missing and unused data to XLSX:
|
@@ -351,6 +333,34 @@ i18n-tasks xlsx-report
|
|
351
333
|
|
352
334
|
While i18n-tasks does not provide an HTML version of the report, you can add [one like this](https://gist.github.com/glebm/bdd3ab6d12d915f0c81b).
|
353
335
|
|
336
|
+
|
337
|
+
## Add New Tasks
|
338
|
+
|
339
|
+
Tasks that come with the gem are defined in [lib/i18n/tasks/commands.rb](lib/i18n/tasks/commands.rb).
|
340
|
+
|
341
|
+
You can add a new task by re-opening the class and loading it in i18n-tasks.yml:
|
342
|
+
|
343
|
+
```ruby
|
344
|
+
# lib/i18n/tasks/my_task.rb
|
345
|
+
I18n::Tasks::Commands.class_eval do
|
346
|
+
desc 'my task'
|
347
|
+
cmd :my_task do |opts = {}|
|
348
|
+
puts i18n.data[opts[:arguments].try(:first) || base_locale]
|
349
|
+
end
|
350
|
+
end
|
351
|
+
```
|
352
|
+
|
353
|
+
```yaml
|
354
|
+
# config/i18n-tasks.yml
|
355
|
+
<% require 'i18n/tasks/my_task' %>
|
356
|
+
```
|
357
|
+
|
358
|
+
Run with:
|
359
|
+
|
360
|
+
```console
|
361
|
+
$ i18n-tasks my-task
|
362
|
+
```
|
363
|
+
|
354
364
|
[MIT license]: /LICENSE.txt
|
355
365
|
[travis]: https://travis-ci.org/glebm/i18n-tasks
|
356
366
|
[badge-travis]: http://img.shields.io/travis/glebm/i18n-tasks.svg
|
data/Rakefile
CHANGED
data/lib/i18n/tasks/base_task.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'i18n/tasks/command_error'
|
3
|
+
require 'i18n/tasks/split_key'
|
3
4
|
require 'i18n/tasks/key_pattern_matching'
|
4
5
|
require 'i18n/tasks/logging'
|
5
6
|
require 'i18n/tasks/plural_keys'
|
@@ -16,6 +17,7 @@ require 'i18n/tasks/configuration'
|
|
16
17
|
module I18n
|
17
18
|
module Tasks
|
18
19
|
class BaseTask
|
20
|
+
include SplitKey
|
19
21
|
include KeyPatternMatching
|
20
22
|
include PluralKeys
|
21
23
|
include UsedKeys
|
data/lib/i18n/tasks/commands.rb
CHANGED
@@ -9,91 +9,116 @@ module I18n::Tasks
|
|
9
9
|
require 'highline/import'
|
10
10
|
|
11
11
|
on_locale_opt = { as: Array, delimiter: /[+:,]/, default: 'all', argument: true, optional: false }
|
12
|
+
OPT = {
|
13
|
+
locale: proc {
|
14
|
+
on '-l', :locales=,
|
15
|
+
'Filter by locale(s), comma-separated list (e.g. en,fr) or all (default: all), also accepted as arguments without -l',
|
16
|
+
on_locale_opt
|
17
|
+
},
|
18
|
+
format: proc {
|
19
|
+
on '-f', :format=,
|
20
|
+
'Format: terminal-table, terminal-tree, json, yaml. Default: terminal-table.',
|
21
|
+
{default: 'terminal-table', argument: true, optional: false}
|
22
|
+
}
|
23
|
+
}
|
12
24
|
desc 'show missing translations'
|
13
25
|
opts do
|
14
|
-
|
15
|
-
|
26
|
+
instance_exec &OPT[:locale]
|
27
|
+
instance_exec &OPT[:format]
|
28
|
+
on '-t', :types=, 'Filter by type (types: used, diff)', as: Array, delimiter: /[+:,]/
|
16
29
|
end
|
17
30
|
cmd :missing do |opt = {}|
|
18
31
|
parse_locales! opt
|
19
|
-
|
32
|
+
print_locale_tree i18n.missing_keys(opt), opt, :missing_keys
|
20
33
|
end
|
21
34
|
|
22
35
|
desc 'show unused translations'
|
23
36
|
opts do
|
24
|
-
|
37
|
+
instance_exec &OPT[:locale]
|
38
|
+
instance_exec &OPT[:format]
|
25
39
|
end
|
26
40
|
cmd :unused do |opt = {}|
|
27
41
|
parse_locales! opt
|
28
|
-
|
42
|
+
print_locale_tree i18n.unused_keys(opt), opt, :unused_keys
|
43
|
+
end
|
44
|
+
|
45
|
+
desc 'show translations equal to base value'
|
46
|
+
opts do
|
47
|
+
instance_exec &OPT[:format]
|
48
|
+
end
|
49
|
+
cmd :eq_base do |opt = {}|
|
50
|
+
parse_locales! opt
|
51
|
+
print_locale_tree i18n.eq_base_keys(opt), opt, :eq_base_keys
|
52
|
+
end
|
53
|
+
|
54
|
+
desc 'show where the keys are used in the code'
|
55
|
+
opts do
|
56
|
+
on '-p', :pattern=, 'Show only keys matching pattern', argument: true, optional: false
|
57
|
+
instance_exec &OPT[:format]
|
58
|
+
end
|
59
|
+
cmd :find do |opt = {}|
|
60
|
+
opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
|
61
|
+
print_locale_tree i18n.used_tree(key_filter: opt[:filter].presence, source_locations: true), opt, :used_keys
|
29
62
|
end
|
30
63
|
|
64
|
+
|
31
65
|
desc 'translate missing keys with Google Translate'
|
32
66
|
opts do
|
33
|
-
on '-l', :locales=, 'Locales to translate (default: all)', on_locale_opt
|
67
|
+
on '-l', :locales=, 'Locales to translate (comma-separated, default: all)', on_locale_opt
|
34
68
|
on '-f', :from=, 'Locale to translate from (default: base)', default: 'base', argument: true, optional: false
|
35
69
|
end
|
36
70
|
cmd :translate_missing do |opt = {}|
|
37
71
|
opt[:from] = base_locale if opt[:from].blank? || opt[:from] == 'base'
|
38
72
|
parse_locales! opt
|
39
|
-
|
73
|
+
i18n.fill_missing_google_translate opt
|
40
74
|
end
|
41
75
|
|
42
76
|
desc 'add missing keys to the locales'
|
43
77
|
opts do
|
44
|
-
on '-l', :locales=, 'Locales to add keys into (default: all)', on_locale_opt
|
78
|
+
on '-l', :locales=, 'Locales to add keys into (comma-separated, default: all)', on_locale_opt
|
45
79
|
on '-p', :placeholder=, 'Value for empty keys (default: base value or key.humanize)', argument: true, optional: false
|
46
80
|
end
|
47
81
|
cmd :add_missing do |opt = {}|
|
48
82
|
parse_locales! opt
|
49
83
|
opt[:value] ||= opt.delete(:placeholder) || proc { |key, locale|
|
50
84
|
# default to base value or key.humanize
|
51
|
-
locale != base_locale && t(key, base_locale) ||
|
85
|
+
locale != base_locale && t(key, base_locale) || SplitKey.split_key(key).last.to_s.humanize
|
52
86
|
}
|
53
87
|
|
54
88
|
v = opt[:value]
|
55
89
|
if v.is_a?(String) && v.include?('%{base_value}')
|
56
|
-
opt[:value] = proc { |key, locale|
|
57
|
-
base_value = t(key, base_locale) || ''
|
90
|
+
opt[:value] = proc { |key, locale, node|
|
91
|
+
base_value = node.value || t(key, base_locale) || ''
|
58
92
|
v % {base_value: base_value}
|
59
93
|
}
|
60
94
|
end
|
61
95
|
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
desc 'show where the keys are used in the code'
|
66
|
-
opts do
|
67
|
-
on '-p', :pattern=, 'Show only keys matching pattern', argument: true, optional: false
|
68
|
-
end
|
69
|
-
cmd :find do |opt = {}|
|
70
|
-
opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
|
71
|
-
terminal_report.used_keys i18n_task.used_tree(key_filter: opt[:filter].presence, source_locations: true)
|
96
|
+
i18n.fill_missing_value opt
|
72
97
|
end
|
73
98
|
|
74
99
|
desc 'normalize translation data: sort and move to the right files'
|
75
100
|
opts do
|
76
|
-
on '-l', :locales=, 'Locales to normalize (default: all)', on_locale_opt
|
101
|
+
on '-l', :locales=, 'Locales to normalize (comma-separated, default: all)', on_locale_opt
|
77
102
|
on '-p', :pattern_router, 'Use pattern router, regardless of config.', argument: false, optional: true
|
78
103
|
end
|
79
104
|
cmd :normalize do |opt = {}|
|
80
105
|
parse_locales! opt
|
81
|
-
|
106
|
+
i18n.normalize_store! opt[:locales], opt[:pattern_router]
|
82
107
|
end
|
83
108
|
|
84
109
|
desc 'remove unused keys'
|
85
110
|
opts do
|
86
|
-
on '-l', :locales=, 'Locales to remove unused keys from (default: all)', on_locale_opt
|
111
|
+
on '-l', :locales=, 'Locales to remove unused keys from (comma-separated, default: all)', on_locale_opt
|
87
112
|
end
|
88
113
|
cmd :remove_unused do |opt = {}|
|
89
114
|
parse_locales! opt
|
90
|
-
unused_keys =
|
115
|
+
unused_keys = i18n.unused_keys(opt)
|
91
116
|
if unused_keys.present?
|
92
117
|
terminal_report.unused_keys(unused_keys)
|
93
118
|
unless ENV['CONFIRM']
|
94
119
|
exit 1 unless agree(red "#{unused_keys.leaves.count} translations will be removed in #{bold opt[:locales] * ', '}#{red '.'} " + yellow('Continue? (yes/no)') + ' ')
|
95
120
|
end
|
96
|
-
|
121
|
+
i18n.remove_unused!(opt[:locales])
|
97
122
|
$stderr.puts "Removed #{unused_keys.leaves.count} keys"
|
98
123
|
else
|
99
124
|
$stderr.puts bold green 'No unused keys to remove'
|
@@ -102,7 +127,7 @@ module I18n::Tasks
|
|
102
127
|
|
103
128
|
desc 'display i18n-tasks configuration'
|
104
129
|
cmd :config do
|
105
|
-
cfg =
|
130
|
+
cfg = i18n.config_for_inspect.to_yaml
|
106
131
|
cfg.sub! /\A---\n/, ''
|
107
132
|
cfg.gsub! /^([^\s-].+?:)/, Term::ANSIColor.cyan(Term::ANSIColor.bold('\1'))
|
108
133
|
puts cfg
|
@@ -129,14 +154,9 @@ module I18n::Tasks
|
|
129
154
|
::I18n::Tasks::ConsoleContext.start
|
130
155
|
end
|
131
156
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
@terminal_report ||= I18n::Tasks::Reports::Terminal.new(i18n_task)
|
136
|
-
end
|
137
|
-
|
138
|
-
def spreadsheet_report
|
139
|
-
@spreadsheet_report ||= I18n::Tasks::Reports::Spreadsheet.new(i18n_task)
|
157
|
+
desc 'show path to the gem'
|
158
|
+
cmd :gem_path do
|
159
|
+
puts File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
140
160
|
end
|
141
161
|
end
|
142
162
|
end
|
@@ -1,21 +1,22 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require 'ostruct'
|
3
|
+
require 'set'
|
3
4
|
module I18n::Tasks
|
4
5
|
class CommandsBase
|
5
6
|
include ::I18n::Tasks::Logging
|
6
7
|
|
7
|
-
def initialize(
|
8
|
-
@
|
8
|
+
def initialize(i18n = nil)
|
9
|
+
@i18n = i18n
|
9
10
|
end
|
10
11
|
|
11
12
|
def locales_opt(locales)
|
12
|
-
return
|
13
|
+
return i18n.locales if locales == ['all'] || locales == 'all'
|
13
14
|
if locales.present?
|
14
15
|
locales = Array(locales).map { |v| v.strip.split(/\s*[\+,:]\s*/).compact.presence if v.is_a?(String) }.flatten
|
15
16
|
locales = locales.map(&:presence).compact.map { |v| v == 'base' ? base_locale : v }
|
16
17
|
locales
|
17
18
|
else
|
18
|
-
|
19
|
+
i18n.locales
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -25,6 +26,32 @@ module I18n::Tasks
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
29
|
+
|
30
|
+
VALID_TREE_FORMATS = %w(terminal-table yaml json inspect)
|
31
|
+
|
32
|
+
def print_locale_tree(tree, opt, version = :show_tree)
|
33
|
+
format = opt[:format] || VALID_TREE_FORMATS.first
|
34
|
+
raise CommandError.new("unknown format: #{format}. Valid formats are: #{VALID_TREE_FORMATS * ', '}.") unless VALID_TREE_FORMATS.include?(format)
|
35
|
+
case format
|
36
|
+
when 'terminal-table'
|
37
|
+
terminal_report.send(version, tree)
|
38
|
+
when 'inspect'
|
39
|
+
puts tree.inspect
|
40
|
+
else
|
41
|
+
puts i18n.data.adapter_dump tree, i18n.data.adapter_by_name(format)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def terminal_report
|
48
|
+
@terminal_report ||= I18n::Tasks::Reports::Terminal.new(i18n)
|
49
|
+
end
|
50
|
+
|
51
|
+
def spreadsheet_report
|
52
|
+
@spreadsheet_report ||= I18n::Tasks::Reports::Spreadsheet.new(i18n)
|
53
|
+
end
|
54
|
+
|
28
55
|
class << self
|
29
56
|
def cmds
|
30
57
|
@cmds ||= {}.with_indifferent_access
|
@@ -35,8 +62,8 @@ module I18n::Tasks
|
|
35
62
|
@next_def = {}
|
36
63
|
define_method name do |*args|
|
37
64
|
begin
|
38
|
-
coloring_was
|
39
|
-
Term::ANSIColor.coloring = STDOUT.isatty
|
65
|
+
coloring_was = Term::ANSIColor.coloring?
|
66
|
+
Term::ANSIColor.coloring = ENV['I18N_TASKS_COLOR'] || STDOUT.isatty
|
40
67
|
instance_exec *args, &block
|
41
68
|
rescue CommandError => e
|
42
69
|
log_error e.message
|
@@ -65,10 +92,10 @@ module I18n::Tasks
|
|
65
92
|
self.class.cmds.try(:[], name).try(:desc)
|
66
93
|
end
|
67
94
|
|
68
|
-
def
|
69
|
-
@
|
95
|
+
def i18n
|
96
|
+
@i18n ||= I18n::Tasks::BaseTask.new
|
70
97
|
end
|
71
98
|
|
72
|
-
delegate :base_locale, :t, to: :
|
99
|
+
delegate :base_locale, :t, to: :i18n
|
73
100
|
end
|
74
101
|
end
|
@@ -13,8 +13,17 @@ module I18n::Tasks::Configuration
|
|
13
13
|
|
14
14
|
def file_config
|
15
15
|
file = CONFIG_FILES.detect { |f| File.exists?(f) }
|
16
|
-
|
17
|
-
|
16
|
+
config = file && YAML.load(Erubis::Eruby.new(File.read(file)).result)
|
17
|
+
if config.present?
|
18
|
+
config.with_indifferent_access.tap do |c|
|
19
|
+
if c[:relative_roots]
|
20
|
+
warn_deprecated 'config/i18n-tasks.yml has relative_roots on top level. Please move relative_roots under search.'
|
21
|
+
c[:search][:relative_roots] = c.delete(:relative_roots)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
else
|
25
|
+
{}.with_indifferent_access
|
26
|
+
end
|
18
27
|
end
|
19
28
|
|
20
29
|
def config=(conf)
|
@@ -34,10 +43,6 @@ module I18n::Tasks::Configuration
|
|
34
43
|
end
|
35
44
|
end
|
36
45
|
|
37
|
-
def relative_roots
|
38
|
-
@config_sections[:relative_roots] ||= config[:relative_roots].presence || %w(app/views)
|
39
|
-
end
|
40
|
-
|
41
46
|
# translation config
|
42
47
|
# @return [Hash{String => String,Hash,Array}]
|
43
48
|
def translation_config
|
@@ -75,21 +80,18 @@ module I18n::Tasks::Configuration
|
|
75
80
|
end
|
76
81
|
end
|
77
82
|
|
78
|
-
def non_base_locales(from = nil)
|
79
|
-
from ||= self.locales
|
80
|
-
Array(from) - [base_locale]
|
81
|
-
end
|
82
|
-
|
83
83
|
# @return [String] default i18n locale
|
84
84
|
def base_locale
|
85
85
|
@config_sections[:base_locale] ||= (config[:base_locale] || 'en').to_s
|
86
86
|
end
|
87
87
|
|
88
|
+
|
88
89
|
def ignore_config(type = nil)
|
89
90
|
key = type ? "ignore_#{type}" : 'ignore'
|
90
91
|
@config_sections[key] ||= config[key]
|
91
92
|
end
|
92
93
|
|
94
|
+
IGNORE_TYPES = [nil, :missing, :unused, :eq_base].freeze
|
93
95
|
# evaluated configuration (as the app sees it)
|
94
96
|
def config_sections
|
95
97
|
# init all sections
|
@@ -97,9 +99,8 @@ module I18n::Tasks::Configuration
|
|
97
99
|
locales
|
98
100
|
data_config
|
99
101
|
search_config
|
100
|
-
relative_roots
|
101
102
|
translation_config
|
102
|
-
|
103
|
+
IGNORE_TYPES.each do |ignore_type|
|
103
104
|
ignore_config ignore_type
|
104
105
|
end
|
105
106
|
@config_sections
|