Opened 8 years ago

Language-specific cover pages

Reported by: Owned by: izzy diorgenes normal TracWikiToPdfPlugin normal 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)

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

Changed 8 years ago by izzy

patch for the template to provide the additional language field

Changed 8 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 8 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 8 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 8 years ago by izzy

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

Changed 8 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 8 years ago by izzy

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

• formats.py

 old (this hunk was shorter than expected) 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.""" 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") 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'] = '' # 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) 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 = '' 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

Changed 8 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 7 years ago by grigi

Could you provide a clean patch?

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

comment:6 Changed 7 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 7 years ago by izzy

Patch for the formats.py file

Changed 7 years ago by izzy

patch for web_ui.py

comment:7 Changed 7 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:

• 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 :)
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.27890515327453613, "perplexity": 23268.719326566094}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-44/segments/1476988718311.12/warc/CC-MAIN-20161020183838-00214-ip-10-171-6-4.ec2.internal.warc.gz"}