From 9d72f207f725490932aee278a4515e84742e21c4 Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Thu, 5 Dec 2019 08:42:15 +0100 Subject: [PATCH] Reuse fixup-docbook-translated.rb for nb translation. Used to insert the translation intro. --- Makefile | 5 ++++- fixup-docbook-translated.rb | 39 ++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index c337a15..1ea85c6 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,10 @@ $(SOURCE).es.xml: $(SOURCE).xml po/es/mwcc.po fixup-docbook-translated.rb rm -f $$TEMP $(SOURCE).nb.xml: $(SOURCE).xml po/nb/mwcc.po - po4a-translate -f docbook -m $(SOURCE).xml -p po/nb/mwcc.po -l $@ -l $@ -L utf-8 -M utf-8 $(PO4AOPTS) -k 0 + TEMP=`tempfile -p mwcc` && \ + po4a-translate -f docbook -m $(SOURCE).xml -p po/nb/mwcc.po -l $$TEMP -l $$TEMP -L utf-8 -M utf-8 $(PO4AOPTS) -k 0 && \ + ruby fixup-docbook-translated.rb nb $$TEMP $@ && \ + rm -f $$TEMP $(SOURCE).nl.xml: $(SOURCE).xml po/nl/mwcc.po po4a-translate -f docbook -m $(SOURCE).xml -p po/nl/mwcc.po -l $@ -l $@ -L utf-8 -M utf-8 $(PO4AOPTS) -k 0 diff --git a/fixup-docbook-translated.rb b/fixup-docbook-translated.rb index 3f04247..648cf26 100644 --- a/fixup-docbook-translated.rb +++ b/fixup-docbook-translated.rb @@ -21,35 +21,37 @@ def log(level,what) end end -log 0, 'Including the Spanish version introduction' -if intro = File.open('extra/es/intro_es.xml', 'r').read rescue nil +log 0, 'Including the %s version introduction' % lang +if intro = File.open('extra/%s/intro_%s.xml' % [lang, lang], + 'r').read rescue nil xml.search('preface').last.after( intro ) else log 0, ' -!- Introduction text not found or empty' end -log 0, 'Final editorial requests: Attributions on top, as in other chapters, also for prefaces' -xml.search('preface').each do |pref| - title = pref.search('title').first - attrib = pref.search('blockquote').last - attrib_text = attrib.inner_text.gsub(/\s+/,' ') +if 'es' == lang + log 0, 'Final editorial requests: Attributions on top, as in other chapters, also for prefaces' + xml.search('preface').each do |pref| + title = pref.search('title').first + attrib = pref.search('blockquote').last + attrib_text = attrib.inner_text.gsub(/\s+/,' ') - # Some formatting issues we need to modify - attrib_text.gsub!(/Paul y Sarah/, 'Paul y Sarah') - attrib_text.gsub!(/Merkley (CEO.*)/, 'Merkley \1') - attrib_text.gsub!(/Wolf (Ins.*)/, 'Wolf \1') + # Some formatting issues we need to modify + attrib_text.gsub!(/Paul y Sarah/, 'Paul y Sarah') + attrib_text.gsub!(/Merkley (CEO.*)/, 'Merkley \1') + attrib_text.gsub!(/Wolf (Ins.*)/, 'Wolf \1') - attrib.remove - title.after('
%s
' % attrib_text) - log 1, 'Moved: %s' % attrib_text + attrib.remove + title.after('
%s
' % attrib_text) + log 1, 'Moved: %s' % attrib_text + end end -log 0, 'Replace legal info by the information assembled by our publisher' -if legal = File.open('extra/es/legal_info.xml', 'r').read rescue nil +if legal = File.open('extra/%s/legal_info.xml' % lang, 'r').read rescue nil + log 0, 'Replace legal info by the information assembled by our publisher' xml.search('colophon').first.inner_html = legal end -log 0, 'Add a colophon at the end' # Doing this the dirty, non-DocBooky way: I'm adding a large section to the last appendix. This should probably go in the # section, but it's already used. @@ -57,7 +59,8 @@ log 0, 'Add a colophon at the end' # A cleaner way would be to replace the section in pdf_es.xsl — But it gets # trickier :-Þ -if colophon = File.open('extra/es/colophon.tex', 'r').read rescue nil +if colophon = File.open('extra/%s/colophon.tex' % lang, 'r').read rescue nil + log 0, 'Add a colophon at the end' xml.search('appendix').last.search('para').last.after('' % colophon) end -- 2.47.2