-# generate pot file for non-plugin files
-file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
-
-# generate pot files for plugin files
-rule(%r'^po/.+\.pot$' => proc {|fn|
- PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
-}, &rgettext_proc)
-
-# update po files
-# ruby-gettext treats empty output from msgmerge as error, causing this task to
-# fail. we provide a wrapper to work around it. see bin/msgmerge-wrapper.rb for
-# details
-ENV['REAL_MSGMERGE_PATH'] = ENV['MSGMERGE_PATH']
-ENV['MSGMERGE_PATH'] = ENV['MSGMERGE_WRAPPER_PATH'] || 'ruby msgmerge-wrapper.rb'
-rule(%r'^po/.+/.+\.po$' => proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}) do |t|
- require 'gettext/utils'
- po_file, pot_file = t.name, t.source
- puts "#{pot_file} => #{po_file}"
- GetText.msgmerge po_file, pot_file, 'rbot'
+# this task defines how po files and pot files are made. those rules are not defined
+# normally because po and pot files should be only updated in the updatepo task,
+# but po files are also prereqs for makemo
+task :define_po_rules do
+ # generate pot file from rb files
+ rgettext_proc = proc do |t|
+ require 'gettext/utils'
+ source_files, pot_file = t.prerequisites, t.name
+ new_pot_file = "#{pot_file}.new"
+ puts "#{source_files.join(', ')} => #{pot_file}"
+ GetText.rgettext(source_files, new_pot_file)
+
+ # only use the new pot file if it contains unique messages
+ if File.exists?(pot_file) && MSGCOMM && `#{MSGCOMM} --unique #{pot_file} #{new_pot_file}`.empty?
+ rm new_pot_file
+ else
+ mv new_pot_file, pot_file
+ end
+
+ normalize_po(pot_file)
+
+ # save all this work until rb files are updated again
+ touch pot_file
+ end
+
+ # generate pot file for non-plugin files
+ file('po/rbot.pot' => NON_PLUGIN_FILES, &rgettext_proc)
+
+ # generate pot files for plugin files
+ rule(%r'^po/.+\.pot$' => proc {|fn|
+ PLUGIN_FILES.select {|f| f.pathmap('rbot-%n') == fn.pathmap('%n')}
+ }, &rgettext_proc)
+
+ # map the po file to its source pot file
+ pot_for_po = proc {|fn| fn.pathmap '%{^po/.+/,po/}X.pot'}
+
+ # update po file from pot file
+ msgmerge_proc = proc do |t|
+ require 'gettext/utils'
+ po_file, pot_file = t.name, t.source
+ puts "#{pot_file} => #{po_file}"
+ if File.exists? po_file
+ sh "#{MSGMERGE} --backup=off --update #{po_file} #{pot_file}"
+ elsif MSGINIT
+ locale = po_file[%r'^po/(.+)/.+\.po$', 1]
+ sh "#{MSGINIT} --locale=#{locale} --no-translator --input=#{pot_file} --output-file=#{po_file}"
+ else
+ warn "#{po_file} is missing and cannot be generated without msginit"
+ next
+ end
+ normalize_po(po_file)
+ touch po_file
+ end
+
+ # generate English po files
+ file(%r'^po/en/.+\.po$' => pot_for_po) do |t|
+ po_file, pot_file = t.name, t.source
+ if MSGEN
+ sh "#{MSGEN} --output-file=#{po_file} #{pot_file}"
+ normalize_po(po_file)
+ touch po_file
+ else
+ msgmerge_proc.call t
+ end
+ end
+
+ # update po files
+ rule(%r'^po/.+/.+\.po$' => pot_for_po, &msgmerge_proc)