Ticket #4915 (new enhancement)

Opened 1 year ago

Last modified 5 months ago

Language-specific cover pages

Reported by: izzy Assigned to: diorgenes
Priority: normal Component: TracWikiToPdfPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

I needed language-specific cover pages, so I tweaked the code a bit. Due to a lot of patches already involved, dependencies had to be considered (hopefully someone will include them ASAP in the repository code to make this task easier), so the attached patches...

  • expect tracwikitopdf-dynimg.patch from #3483 (dated 01/14/09) to be applied before. Though this ticket is already closed, that patch does not seem to be applied to the repository code (correct me if I'm wrong).
  • are cumulatively including the multiformat patch from #4747, which cumulatively includes the titlefile patch from #4696

The tail is already long enough - hopefully it will get shorter as soon as code gets integrated into the repository.

So after having the patches applied, the Admin-form will offer a new field "Language". Put in the language extension here (e.g. "en" for English, "de" for German). In the cover directory, you should have a corresponding cover file - for the example given, "cover.html.en" for English, "cover.html.de" for German.

If there are questions, append them to this ticket - I'll try my best to answer them.

Attachments

admin_wikitopdf.cs.lang.patch (369 bytes) - added by izzy on 04/13/09 15:20:18.
patch for the template to provide the additional language field
formats.py.titlefile+multiformat+lang.patch (3.4 kB) - added by izzy on 04/13/09 15:23:41.
Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)
formats.py.titlefile+multiformat+lang.2.patch (3.4 kB) - added by izzy on 04/13/09 15:24:23.
Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)
formats.py.titlefile+multiformat+lang.3.patch (3.4 kB) - added by izzy on 04/13/09 15:25:26.
Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)
formats.py.titlefile+multiformat+lang.diff (3.4 kB) - added by izzy on 04/13/09 15:27:25.
Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)
formats.py.titlefile+multiformat+lang.4.patch (3.2 kB) - added by izzy on 04/16/09 18:18:03.
Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)
formats.py.lang.diff (1.0 kB) - added by izzy on 10/16/09 20:58:09.
Patch for the formats.py file
web_ui.py.lang.diff (0.9 kB) - added by izzy on 10/16/09 20:58:52.
patch for web_ui.py

Change History

04/13/09 15:20:18 changed by izzy

  • attachment admin_wikitopdf.cs.lang.patch added.

patch for the template to provide the additional language field

04/13/09 15:23:41 changed by izzy

  • attachment formats.py.titlefile+multiformat+lang.patch added.

Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)

04/13/09 15:24:23 changed by izzy

  • attachment formats.py.titlefile+multiformat+lang.2.patch added.

Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)

04/13/09 15:25:26 changed by izzy

  • attachment formats.py.titlefile+multiformat+lang.3.patch added.

Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)

04/13/09 15:26:42 changed by izzy

Sorry - somehow the server messes things up, I was not able to add the second patch correctly :(

04/13/09 15:27:25 changed by izzy

  • attachment formats.py.titlefile+multiformat+lang.diff added.

Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)

04/13/09 15:30:00 changed by izzy

Since the server does not store the uploaded diff, please copy and paste it from here:

--- formats.py.orig     2009-04-13 14:21:29.000000000 +0200
+++ formats.py  2009-04-13 14:43:06.000000000 +0200
@@ -24,12 +24,6 @@
 from api import IWikiToPdfFormat
 from wikitopdf import wiki_to_pdf, html_to_pdf

 class WikiToPdfOutput(Component):
     """Output wiki pages as a PDF/PS document using HTMLDOC."""

@@ -37,8 +31,10 @@

     def wikitopdf_formats(self, req):
         yield 'pdf', 'PDF'
+        yield 'ps', 'PS'
+        yield 'html', 'HTML'

-    def process_wikitopdf(self, req, format, title, subject, pages, version, date, pdfname):
+    def process_wikitopdf(self, req, format, title, subject, pages, version, date, pdfname, lang):

         os.system("rm -f /tmp/tmp*wikitopdf")

@@ -46,13 +42,19 @@
         files = [self._page_to_file('', req, p) for p in pages]

         #Setup the title and license pages
-        title_template = self.env.config.get('wikitopdf', 'pathtocover') + '/cover.html'
+       if lang: title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html' + '.' + lang
+       else:    title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html'
         titlefile = title_template and self.get_titlepage(title_template, title, subject, date, version) or None

+        if titlefile: tfile = titlefile
+       else: tfile = 'none'
+        self.log.debug('WikiToPdf => Using template %s and titlefile %s', title_template, tfile)
+
         # Prepare html doc arguments
         codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1')

-        htmldoc_args = { 'book': '', 'format': 'pdf14', 'charset': codepage }
+       oformat = { 'pdf':'pdf14', 'ps':'ps2', 'html':'html'}[format]
+        htmldoc_args = { 'book': '', 'format': oformat, 'charset': codepage }

         if titlefile: htmldoc_args['titlefile'] = titlefile
         else: htmldoc_args['no-title'] = ''
@@ -68,8 +70,8 @@

         # Send the output
         req.send_response(200)
-        req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript'}[format])
-        req.send_header('Content-Disposition', 'attachment; filename=' + pdfname + '.pdf')
+        req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript', 'html':'text/html'}[format])
+        req.send_header('Content-Disposition', 'attachment; filename=' + pdfname + {'pdf':'.pdf', 'ps':'.ps', 'html': '.html'}[format])
         req.send_header('Content-Length', len(out))
         req.end_headers()
         req.write(out)
@@ -94,6 +96,8 @@

     def get_titlepage(self, template_path, title, subject, version, date):

+        self.log.debug('WikiToPdf => Getting titlepage for tplpath "%s", title "%s", subject "%s", version "%s", date "%s"', template_path,title,subject,version,date)
+
         hfile, hfilename = mkstemp('wikitopdf')
         #codepage = Mimeview(self.env).default_charset
        string_page = ''
@@ -105,7 +109,7 @@
             string_page = string_page.replace('#SUBJECT#', subject)
             string_page = string_page.replace('#VERSION#', version)
             string_page = string_page.replace('#DATE#', date)
-           string_page = string_page.replace('#PATHTOCOVER#',  self.env.config.get('wikitopdf', 'pathtocover'))
+           string_page = string_page.replace('#PATHTOCOVER#',  self.env.config.get('wikitopdf', 'titlefile'))
         except:
             os.close(hfile)
             return None

04/16/09 18:18:03 changed by izzy

  • attachment formats.py.titlefile+multiformat+lang.4.patch added.

Cumulative patch to evaluate the language from the patched form, incl. patch from #4747 (PS+HTML output) and #4696 (titlefile keyword)

05/05/09 13:02:59 changed by grigi

Could you provide a clean patch?

05/07/09 21:25:30 changed by izzy

So just what's left, you mean, right? titlefile you've got already fixed AFAIR, multiformat as well - so all you need is a patch for the multilang stuff? Please confirm - and I will try to create it ASAP (I'm quite busy recently, so not that much time anymore - please fogive my delay).

05/09/09 23:26:07 changed by grigi

Yes, just the patch for the multi-language stuff. Don't worry about delay, since I think almost all of us are doing this in our spare time.

05/10/09 00:03:24 changed by izzy

OK, thanks. First: The attached patch admin_wikitopdf.cs.lang.patch can be used for the template (it includes nothing else). Unfortunately, I no longer have my test server available to try out the latest version and create a clean patch for the remaining things (I don't want to try on my production server), so I can just "quote" the changes here (as taken from above code):

def process_wikitopdf(self, req, format, title, subject, pages, version, date, pdfname, lang):
  // ...
       #Setup the title and license pages
       //title_template = self.env.config.get('wikitopdf', 'pathtocover') + '/cover.html'
       if lang: title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html' + '.' + lang
       else:    title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html'
       titlefile = title_template and self.get_titlepage(title_template, title, subject, date, version) or None
  // ...

That's all that must be done, AFAIR (i.e.: Adding the lang parameter to the function call, and replacing the one line setting up the title_template by the two lines doing that conditionally). Optionally, for a "cleaner design", there could be some error-checking included if a language was specified but no corresponding language file found, to fall back to the "old behaviour" and use cover.html without a language suffix.

10/16/09 20:58:09 changed by izzy

  • attachment formats.py.lang.diff added.

Patch for the formats.py file

10/16/09 20:58:52 changed by izzy

  • attachment web_ui.py.lang.diff added.

patch for web_ui.py

10/16/09 21:07:58 changed by izzy

Sorry for the delay. Working on the other issue (see #5915) I set up another test Trac, so I finally could create and attach the two missing patches. They apply fine against the latest repo code. So all you need for multi-lang support here is:

  • admin_wikitopdf.cs.lang.patch
  • formats.py.lang.diff
  • web_ui.py.lang.diff

The names suggest where they belong to :) After that, one just creates language-specific cover pages like e.g. cover.html.de, and in the web form put "de" in the appropriate field to use it.

Once you applied them to the repo code, this ticket can be closed :)


Add/Change #4915 (Language-specific cover pages)




Change Properties
Action