Skip to content

Commit

Permalink
locale:po_to_json: add support for including catalogs from js plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mzazrivec committed Jul 20, 2018
1 parent 3e58954 commit 60bac82
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions lib/tasks/locale.rake
Original file line number Diff line number Diff line change
Expand Up @@ -191,30 +191,60 @@ namespace :locale do

desc "Convert PO files from all plugins to JS files"
task "po_to_json" => :environment do
require_relative 'gettext_task_override.rb'
require Rails.root.join("lib/vmdb/gettext/domains")

po_files = {}
Vmdb::Gettext::Domains.paths.each do |path|
files = ::Pathname.glob(::File.join(path, "**", "*.po"))
files.each do |file|
locale = file.dirname.basename.to_s
po_files[locale] ||= []
po_files[locale].push(file)
begin
require_relative 'gettext_task_override.rb'
require Rails.root.join('lib/manageiq/environment')
require Rails.root.join("lib/vmdb/gettext/domains")

po_files = {}
Vmdb::Gettext::Domains.paths.each do |path|
files = ::Pathname.glob(::File.join(path, "**", "*.po"))
files.each do |file|
locale = file.dirname.basename.to_s
po_files[locale] ||= []
po_files[locale].push(file)
end
end
end

combined_dir = File.join(Rails.root, "locale/combined")
Dir.mkdir(combined_dir, 0700)
po_files.keys.each do |locale|
dir = File.join(combined_dir, locale)
po = File.join(dir, 'manageiq.po')
Dir.mkdir(dir, 0700)
system "rmsgcat -o #{po} #{po_files[locale].join(' ')}"
end
js_plugins = {
'ui-components' => {
'en' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/en/ui-components.po',
'es' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/es/ui-components.po',
'fr' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/fr/ui-components.po',
'ja' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/ja/ui-components.po',
'pt_BR' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/pt_BR/ui-components.po',
'zh_CN' => 'https://raw.githubusercontent.com/ManageIQ/ui-components/master/locale/zh_CN/ui-components.po',
}
}

plugins_dir = File.join(Rails.root, 'locale/plugins')
Dir.mkdir(plugins_dir, 0700)
js_plugins.each do |plugin, content|
plugin_dir = File.join(plugins_dir, plugin)
Dir.mkdir(plugin_dir)
content.each do |lang, url|
lang_dir = File.join(plugin_dir, lang)
Dir.mkdir(lang_dir)
lang_file = "#{lang_dir}/#{url.split('/')[-1]}"
ManageIQ::Environment.system! "curl -f -o #{lang_file} #{url}"
po_files[lang] ||= []
po_files[lang].push(Pathname(lang_file))
end
end

combined_dir = File.join(Rails.root, "locale/combined")
Dir.mkdir(combined_dir, 0700)
po_files.keys.each do |locale|
dir = File.join(combined_dir, locale)
po = File.join(dir, 'manageiq.po')
Dir.mkdir(dir, 0700)
system "rmsgcat -o #{po} #{po_files[locale].join(' ')}"
end

Rake::Task['gettext:po_to_json'].invoke
system "rm -rf #{combined_dir}"
Rake::Task['gettext:po_to_json'].invoke
ensure
system "rm -rf #{combined_dir} #{plugins_dir}"
end
end

desc "Create display names for models"
Expand Down

0 comments on commit 60bac82

Please sign in to comment.