7 raise ArgumentError
, 'Language and source/destination files not specified' if ARGV.size !
= 3
13 xml
= Nokogiri
::XML(f
)
16 indicators
= %w(! •
# -)
18 print indicators
[level
]
20 print
"\n%s %s\n" % ['*' * (level+
1), what
]
24 log
0, 'Including the Spanish version introduction'
25 if intro
= File
.open('extra/es/intro_es.xml', 'r').read
rescue nil
26 xml
.search('preface').last
.after( intro
)
28 log
0, ' -!- Introduction text
not found
or empty
'
31 log 0, 'replace images with translated versions
'
32 xml.search('imagedata
').each do |img|
33 # Included images are in the 'Pictures
' directory. Translated images
34 # are in Pictures/[langcode]/. Only translated images need to be
36 orig_img = img.attributes['fileref
'].text
37 trans_img = orig_img.gsub(/Pictures/, "Pictures/#{lang}")
38 next if orig_img == trans_img
40 if File.exists?(trans_img)
41 log 1, 'Replaced
%s by
%s
' % [orig_img, trans_img]
42 img.set_attribute('fileref
', trans_img)
46 log 0, 'Writing processed file
'
47 # Unable to figure out API way to replace DOCTYPE
49 File.open(dstfile, 'w
') {|f| f.write(data)}