Modify

Opened 15 years ago

Last modified 6 years ago

#4915 new enhancement

Language-specific cover pages

Reported by: izzy Owned by:
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 (8)

admin_wikitopdf.cs.lang.patch (369 bytes) - added by izzy 15 years ago.
patch for the template to provide the additional language field
formats.py.titlefile+multiformat+lang.patch (3.4 KB) - added by izzy 15 years ago.
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 15 years ago.
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 15 years ago.
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 15 years ago.
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 15 years ago.
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 (1002 bytes) - added by izzy 15 years ago.
Patch for the formats.py file
web_ui.py.lang.diff (935 bytes) - added by izzy 15 years ago.
patch for web_ui.py

Download all attachments as: .zip

Change History (16)

Changed 15 years ago by izzy

patch for the template to provide the additional language field

Changed 15 years ago by izzy

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

Changed 15 years ago by izzy

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

Changed 15 years ago by izzy

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

comment:1 Changed 15 years ago by izzy

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

Changed 15 years ago by izzy

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

comment:2 Changed 15 years ago by izzy

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

  • formats.py

    old new (this hunk was shorter than expected) 
    2424from api import IWikiToPdfFormat
    2525from wikitopdf import wiki_to_pdf, html_to_pdf
    2626
    2727class WikiToPdfOutput(Component):
    2828    """Output wiki pages as a PDF/PS document using HTMLDOC."""
    2929
     
    3731
    3832    def wikitopdf_formats(self, req):
    3933        yield 'pdf', 'PDF'
     34        yield 'ps', 'PS'
     35        yield 'html', 'HTML'
    4036
    41     def process_wikitopdf(self, req, format, title, subject, pages, version, date, pdfname):
     37    def process_wikitopdf(self, req, format, title, subject, pages, version, date, pdfname, lang):
    4238
    4339        os.system("rm -f /tmp/tmp*wikitopdf")
    4440
     
    4642        files = [self._page_to_file('', req, p) for p in pages]
    4743
    4844        #Setup the title and license pages
    49         title_template = self.env.config.get('wikitopdf', 'pathtocover') + '/cover.html'
     45       if lang: title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html' + '.' + lang
     46       else:    title_template = self.env.config.get('wikitopdf', 'titlefile') + '/cover.html'
    5047        titlefile = title_template and self.get_titlepage(title_template, title, subject, date, version) or None
    5148
     49        if titlefile: tfile = titlefile
     50       else: tfile = 'none'
     51        self.log.debug('WikiToPdf => Using template %s and titlefile %s', title_template, tfile)
     52
    5253        # Prepare html doc arguments
    5354        codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1')
    5455
    55         htmldoc_args = { 'book': '', 'format': 'pdf14', 'charset': codepage }
     56       oformat = { 'pdf':'pdf14', 'ps':'ps2', 'html':'html'}[format]
     57        htmldoc_args = { 'book': '', 'format': oformat, 'charset': codepage }
    5658
    5759        if titlefile: htmldoc_args['titlefile'] = titlefile
    5860        else: htmldoc_args['no-title'] = ''
     
    6870
    6971        # Send the output
    7072        req.send_response(200)
    71         req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript'}[format])
    72         req.send_header('Content-Disposition', 'attachment; filename=' + pdfname + '.pdf')
     73        req.send_header('Content-Type', {'pdf':'application/pdf', 'ps':'application/postscript', 'html':'text/html'}[format])
     74        req.send_header('Content-Disposition', 'attachment; filename=' + pdfname + {'pdf':'.pdf', 'ps':'.ps', 'html': '.html'}[format])
    7375        req.send_header('Content-Length', len(out))
    7476        req.end_headers()
    7577        req.write(out)
     
    9496
    9597    def get_titlepage(self, template_path, title, subject, version, date):
    9698
     99        self.log.debug('WikiToPdf => Getting titlepage for tplpath "%s", title "%s", subject "%s", version "%s", date "%s"', template_path,title,subject,version,date)
     100
    97101        hfile, hfilename = mkstemp('wikitopdf')
    98102        #codepage = Mimeview(self.env).default_charset
    99103       string_page = ''
     
    105109            string_page = string_page.replace('#SUBJECT#', subject)
    106110            string_page = string_page.replace('#VERSION#', version)
    107111            string_page = string_page.replace('#DATE#', date)
    108            string_page = string_page.replace('#PATHTOCOVER#',  self.env.config.get('wikitopdf', 'pathtocover'))
     112           string_page = string_page.replace('#PATHTOCOVER#',  self.env.config.get('wikitopdf', 'titlefile'))
    109113        except:
    110114            os.close(hfile)
    111115            return None

Changed 15 years ago by izzy

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

comment:3 Changed 15 years ago by Nickolas Grigoriadis

Could you provide a clean patch?

comment:4 Changed 15 years ago 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).

comment:5 Changed 15 years ago by Nickolas Grigoriadis

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.

comment:6 Changed 15 years ago 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.

Changed 15 years ago by izzy

Attachment: formats.py.lang.diff added

Patch for the formats.py file

Changed 15 years ago by izzy

Attachment: web_ui.py.lang.diff added

patch for web_ui.py

comment:7 Changed 15 years ago 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 :)

comment:8 Changed 6 years ago by Ryan J Ollos

Owner: Diorgenes Felipe Grzesiuk deleted

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.