From d51497e4d68e852ed0f8aa67386f394301c30c96 Mon Sep 17 00:00:00 2001 From: Thiago Araujo Date: Mon, 10 Mar 2025 20:39:53 -0600 Subject: [PATCH] Add reformat locale rake task This task reformats all YAML locales. --- tasks/reformat_yaml.rake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasks/reformat_yaml.rake b/tasks/reformat_yaml.rake index dde08d2362..250fdd9fd6 100644 --- a/tasks/reformat_yaml.rake +++ b/tasks/reformat_yaml.rake @@ -2,6 +2,21 @@ require 'yaml' +desc 'Reformat all locales' +task :reformat_locales do + path = File.absolute_path(File.join(__dir__, '..', 'lib', 'locales', '**', '*.yml')) + locales = Dir[path] + failures = [] + + locales.each do |locale_path| + reformat_file(locale_path) + rescue StandardError => e + failures << "Error reformatting #{locale_path}: #{e.message}" + end + + puts failures +end + desc 'Reformat a yaml file into a common format' task :reformat_yaml, [:filename] do |_, args| args.with_defaults(filename: nil) @@ -16,7 +31,7 @@ end def reformat_file(filename) puts "Reformatting #{filename}" - input = YAML.load_file(filename) + input = YAML.safe_load_file(filename, aliases: true) # Psych outputs non-indented hypendated array list items. output = input.to_yaml(line_width: -1) .gsub(/(^ *- .+$)/, ' \1') # Indent hyphenated list items