build system: add targets for pushing to Transifex

This commit is contained in:
Moritz Bunkus 2016-03-26 12:15:11 +01:00
parent 63b07980a7
commit 8af78d72fc
2 changed files with 47 additions and 8 deletions

View File

@ -533,32 +533,54 @@ EOT
normalize_po po_file
end
end
end
namespace :transifex do
transifex_pull_targets = {
"man-pages" => [],
"programs" => [],
}
transifex_push_targets = {
"man-pages" => [],
"programs" => [],
}
$all_po_files.each do |po_file|
language = /\/([^\/]+)\.po$/.match(po_file)[1]
resource = /doc\/man/.match(po_file) ? "man-pages" : "programs"
target = "transifex-pull-#{resource}-#{language}"
language = /\/([^\/]+)\.po$/.match(po_file)[1]
resource = /doc\/man/.match(po_file) ? "man-pages" : "programs"
pull_target = "pull-#{resource}-#{language}"
push_target = "push-#{resource}-#{language}"
transifex_pull_targets[resource] << "translations:update:#{target}"
transifex_pull_targets[resource] << "translations:transifex:#{pull_target}"
transifex_push_targets[resource] << "translations:transifex:#{push_target}"
task target => :no_unstaged_changes do
task pull_target => :no_unstaged_changes do
transifex_pull_and_merge resource, language
end
task push_target => :no_unstaged_changes do
transifex_remove_fuzzy_and_push resource, language
end
end
desc "Fetch and merge program translations from Transifex"
task "transifex-programs" => transifex_pull_targets["programs"]
task "pull-programs" => transifex_pull_targets["programs"]
desc "Fetch and merge man page translations from Transifex"
task "transifex-man-pages" => transifex_pull_targets["man-pages"]
task "pull-man-pages" => transifex_pull_targets["man-pages"]
desc "Fetch and merge all translations from Transifex"
task "transifex" => transifex_pull_targets.values.flatten
task "pull" => transifex_pull_targets.values.flatten
desc "Push program translations to Transifex"
task "push-programs" => transifex_push_targets["programs"]
desc "Push man page translations to Transifex"
task "push-man-pages" => transifex_push_targets["man-pages"]
desc "Push all translations to Transifex"
task "push" => transifex_push_targets.values.flatten
end
[ :stats, :statistics ].each_with_index do |task_name, idx|

View File

@ -193,3 +193,20 @@ def transifex_pull_and_merge resource, language
write_po po_file, merged_items
end
def transifex_remove_fuzzy_and_push resource, language
po_file = resource == "programs" ? "po/#{language}.po" : "doc/man/po4a/po/#{language}.po"
po_file_no_fuzzy = Tempfile.new("mkvtoolnix-rake-po-no-fuzzy")
runq_git po_file, "checkout HEAD -- #{po_file}"
runq "MSGATTRIB #{po_file}", "msgattrib --no-fuzzy --output=#{po_file_no_fuzzy.path} #{po_file}"
IO.write(po_file, IO.read(po_file_no_fuzzy))
normalize_po po_file
runq " TX_PUSH #{po_file}", "tx push -t -f --no-interactive -r mkvtoolnix.#{resource} -l #{language} > /dev/null"
runq_git po_file, "checkout HEAD -- #{po_file}"
end