Class: I18nTemplate::Extractor::Yaml
- Inherits:
-
Base
- Object
- Base
- I18nTemplate::Extractor::Yaml
show all
- Defined in:
- lib/i18n_template/extractor/yaml.rb
Overview
Extract phrases to yaml format. E.g: config/locales/templates.yml
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Class Method Details
.default_options ⇒ Object
16
17
18
19
20
|
# File 'lib/i18n_template/extractor/yaml.rb', line 16
def default_options
super.merge({
:locales_root => 'config/locales'
})
end
|
12
13
14
|
# File 'lib/i18n_template/extractor/yaml.rb', line 12
def format
'yaml'
end
|
Instance Method Details
#call(paths) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/i18n_template/extractor/yaml.rb', line 23
def call(paths)
FileUtils.mkdir_p(@options[:locales_root])
output_file = File.join(@options[:locales_root], 'phrases.yml')
phrases = []
paths.each do |path|
phrases += (path)
end
phrases.uniq!
log "Extracting #{phrases.size} phrases to #{output_file}"
data = File.exists?(output_file) ? YAML.load_file(output_file) : {}
data['en'] ||= {}
data.keys.each do |locale|
phrases.each do |phrase|
data[locale][phrase] ||= nil
end
end
File.open(output_file, "w") do |f|
f << data.to_yaml
end
end
|