Commit 59117175a37f4314d25e11ce789de6f4b0e545c0

Authored by Antonio Terceiro
1 parent 8b08c90f

Avoid generating documentation if not needed

Showing 1 changed file with 30 additions and 7 deletions   Show diff stats
lib/tasks/doc.rake
... ... @@ -101,23 +101,46 @@ namespace :noosfero do
101 101 desc "Rebuild Noosfero online documentation"
102 102 task :rebuild => [:clean, :build]
103 103  
  104 + def percent_translated(po_file)
  105 + if !File.exists?(po_file)
  106 + raise "#{po_file}: not found"
  107 + end
  108 + output = `LANG=C msgfmt --output /dev/null --statistics #{po_file} 2>&1`
  109 + puts output
  110 + translated = (output =~ /([0-9]+) translated messages/) ? $1.to_i : 0
  111 + untranslated = (output =~ /([0-9]+) untranslated messages/) ? $1.to_i : 0
  112 + fuzzy = (output =~ /([0-9]+) fuzzy translations/) ? $1.to_i : 0
  113 +
  114 + 100 * translated / (translated + untranslated + fuzzy)
  115 + end
  116 +
104 117 desc "Translates Noosfero online documentation (does not touch PO files)"
105 118 task :translate => english_xhtml do
106 119 languages = Noosfero.locales.keys - ['en']
107 120 languages.each do |lang|
108 121 po = "po/#{lang}/noosfero-doc.po"
  122 + percent = percent_translated(po)
  123 + if percent < 80
  124 + puts "Skipping #{lang} translation, only #{percent}% translated (needs 80%)"
  125 + next
  126 + end
109 127 if File.exists?(po)
110 128 puts "Translating: #{lang}"
111 129 Dir['doc/noosfero/**/*.en.xhtml'].each do |doc|
112 130 target = doc.sub('.en.xhtml', ".#{lang}.xhtml")
113   - command = "po4a-translate -f xhtml -M utf8 -m #{doc} -p #{po} -L utf8 -l #{target} >/dev/null 2>&1"
114   - unless system(command)
115   - puts "Failed in #{lang} translation!"
116   - puts "Run the command manually to check:"
117   - puts "$ #{command}"
118   - raise "Failed."
  131 + test = "test ! -e #{target} || test #{target} -ot #{doc} || test #{target} -ot #{po}"
  132 + command = "po4a-translate -f xhtml -M utf8 -m #{doc} -p #{po} -L utf8 -l #{target}"
  133 + if system(test)
  134 + unless system("#{command} >/dev/null 2>&1")
  135 + puts "Failed in #{lang} translation!"
  136 + puts "Run the command manually to check:"
  137 + puts "$ #{command}"
  138 + raise "Failed."
  139 + end
  140 + print "."
  141 + else
  142 + print "#"
119 143 end
120   - print "."
121 144 $stdout.flush
122 145 end
123 146 puts
... ...