Skip to content

Commit

Permalink
Merge pull request ManageIQ#20929 from lpichler/use_rails_root_when_r…
Browse files Browse the repository at this point in the history
…oot_is_present_from_args

Use Rails.root when root args[:root] not present in locale.rake extract_yaml_strings task
  • Loading branch information
gtanzillo authored Jan 7, 2021
2 parents e9e9c4e + 76f09c7 commit 14f0689
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/tasks/locale.rake
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,25 @@ namespace :locale do
end
end

config_file = args[:root].join('config/locale_task_config.yaml')
config_file = Rails.root.join('config/locale_task_config.yaml') unless config_file.exist?
root_path = args[:root] || Rails.root

config_file = root_path.join('config/locale_task_config.yaml')
next unless config_file.exist?

yamls = YAML.load_file(config_file)['yaml_strings_to_extract']
output = {}

yamls.each_key do |yaml_glob|
yaml_glob_full = args[:root].join(yaml_glob)
yaml_glob_full = root_path.join(yaml_glob)
Dir.glob(yaml_glob_full).each do |file|
yml = YAML.load_file(file)
parse_object(yml, yamls[yaml_glob], file, output, args[:root].to_s)
parse_object(yml, yamls[yaml_glob], file, output, root_path.to_s)
end
end

next if output.empty? # no yaml strings were found

File.open(args[:root].join("config/yaml_strings.rb"), "w+") do |f|
File.open(root_path.join("config/yaml_strings.rb"), "w+") do |f|
f.puts "# This is automatically generated file (rake locale:extract_yaml_strings)."
f.puts "# The file contains strings extracted from various yaml files for gettext to find."
output.each_key do |key|
Expand Down

0 comments on commit 14f0689

Please sign in to comment.