Opened 17 years ago
Last modified 7 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)
Change History (16)
Changed 17 years ago by
| Attachment: | admin_wikitopdf.cs.lang.patch added |
|---|
Changed 17 years ago by
| Attachment: | formats.py.titlefile+multiformat+lang.patch added |
|---|
Changed 17 years ago by
| Attachment: | formats.py.titlefile+multiformat+lang.2.patch added |
|---|
Changed 17 years ago by
| Attachment: | formats.py.titlefile+multiformat+lang.3.patch added |
|---|
comment:1 Changed 17 years ago by
Sorry - somehow the server messes things up, I was not able to add the second patch correctly :(
Changed 17 years ago by
| Attachment: | formats.py.titlefile+multiformat+lang.diff added |
|---|
comment:2 Changed 17 years ago by
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) 24 24 from api import IWikiToPdfFormat 25 25 from wikitopdf import wiki_to_pdf, html_to_pdf 26 26 27 27 class WikiToPdfOutput(Component): 28 28 """Output wiki pages as a PDF/PS document using HTMLDOC.""" 29 29 … … 37 31 38 32 def wikitopdf_formats(self, req): 39 33 yield 'pdf', 'PDF' 34 yield 'ps', 'PS' 35 yield 'html', 'HTML' 40 36 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): 42 38 43 39 os.system("rm -f /tmp/tmp*wikitopdf") 44 40 … … 46 42 files = [self._page_to_file('', req, p) for p in pages] 47 43 48 44 #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' 50 47 titlefile = title_template and self.get_titlepage(title_template, title, subject, date, version) or None 51 48 49 if titlefile: tfile = titlefile 50 else: tfile = 'none' 51 self.log.debug('WikiToPdf => Using template %s and titlefile %s', title_template, tfile) 52 52 53 # Prepare html doc arguments 53 54 codepage = self.env.config.get('trac', 'default_charset', 'iso-8859-1') 54 55 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 } 56 58 57 59 if titlefile: htmldoc_args['titlefile'] = titlefile 58 60 else: htmldoc_args['no-title'] = '' … … 68 70 69 71 # Send the output 70 72 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]) 73 75 req.send_header('Content-Length', len(out)) 74 76 req.end_headers() 75 77 req.write(out) … … 94 96 95 97 def get_titlepage(self, template_path, title, subject, version, date): 96 98 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 97 101 hfile, hfilename = mkstemp('wikitopdf') 98 102 #codepage = Mimeview(self.env).default_charset 99 103 string_page = '' … … 105 109 string_page = string_page.replace('#SUBJECT#', subject) 106 110 string_page = string_page.replace('#VERSION#', version) 107 111 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')) 109 113 except: 110 114 os.close(hfile) 111 115 return None
Changed 17 years ago by
| Attachment: | formats.py.titlefile+multiformat+lang.4.patch added |
|---|
comment:4 Changed 17 years ago by
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 17 years ago by
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 17 years ago by
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.
comment:7 Changed 16 years ago by
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.patchformats.py.lang.diffweb_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 7 years ago by
| Owner: | Diorgenes Felipe Grzesiuk deleted |
|---|



patch for the template to provide the additional language field