Skip to content

Commit 431b651

Browse files
thdaraujostefannibrasil
authored andcommitted
Add reformat locale rake task
This task reformats all YAML locales.
1 parent c48530e commit 431b651

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

tasks/reformat_yaml.rake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
require 'yaml'
44

5+
desc 'Reformat all locales'
6+
task :reformat_locales do
7+
path = File.absolute_path(File.join(__dir__, '..', 'lib', 'locales', '**', '*.yml'))
8+
locales = Dir[path]
9+
failures = []
10+
11+
locales.each do |locale_path|
12+
reformat_file(locale_path)
13+
rescue StandardError => e
14+
failures << "Error reformatting #{locale_path}: #{e.message}"
15+
end
16+
17+
puts failures
18+
end
19+
520
desc 'Reformat a yaml file into a common format'
621
task :reformat_yaml, [:filename] do |_, args|
722
args.with_defaults(filename: nil)
@@ -16,7 +31,7 @@ end
1631
def reformat_file(filename)
1732
puts "Reformatting #{filename}"
1833

19-
input = YAML.load_file(filename)
34+
input = YAML.safe_load_file(filename, aliases: true)
2035
# Psych outputs non-indented hypendated array list items.
2136
output = input.to_yaml(line_width: -1)
2237
.gsub(/(^ *- .+$)/, ' \1') # Indent hyphenated list items

0 commit comments

Comments
 (0)