Le Wednesday 05 November 2008 00:26:18 Matthew Nuzum, vous avez écrit :
> <Sorry for delay, I started this yesterday afternoon but the power in
> my house went out and I got kicked offline for several hours - by then
> it was bed time>
>
> 2008/10/30 Gabor Kelemen <[EMAIL PROTECTED]>:
> > Perhaps a silly idea, but what is your locale?
> > Running LANG=en_US.utf8 ./localize.sh generated good looking html's for
> > me with several translations mailed previously to this list.
> > See them here:
> > http://delfin.unideb.hu/~kg0021/start/
>
> $ env | grep -i lang
> LANG=en_US.UTF-8
>
> I've also tried adding -utf8 to the tidy call. Using ru as an example I
> get:
>
> title>Ð"омашнÑÑ Ñтраница Ubuntu</title>
This is because po2html.py use tidy with acsii encoding as default option.
I fixed this bug by adding a missing argument in po2html.py, here's the
modified
script.
You should overwrite /usr/share/pyshared/translate/convert/test_po2html.py
with the new script, and regenerate HTML files with your localise.sh script.
I've tested it and it works fine.
diff :
84c84
< htmlresult = str(tidy.parseString(htmlresult))
---
> htmlresult = str(tidy.parseString(htmlresult,
**{'char_encoding': "utf8"}))
--
Bruno
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2004-2006 Zuza Software Foundation
#
# This file is part of translate.
#
# translate is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# translate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with translate; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""convert Gettext PO localization files to HTML files
see: http://translate.sourceforge.net/wiki/toolkit/po2html for examples and
usage instructions
"""
from translate.storage import po
try:
import textwrap
except:
textwrap = None
try:
import tidy
except:
tidy = None
class po2html:
"""po2html can take a po file and generate html. best to give it a template file otherwise will just concat msgstrs"""
def __init__(self, wrap=None):
self.wrap = wrap
def wrapmessage(self, message):
"""rewraps text as required"""
if self.wrap is None:
return message
return "\n".join([textwrap.fill(line, self.wrap, replace_whitespace=False) for line in message.split("\n")])
def convertstore(self, inputstore, includefuzzy):
"""converts a file to .po format"""
htmlresult = ""
for inputunit in inputstore.units:
if inputunit.isheader():
continue
if includefuzzy or not inputunit.isfuzzy():
htmlresult += self.wrapmessage(inputunit.target) + "\n" + "\n"
else:
htmlresult += self.wrapmessage(inputunit.source) + "\n" + "\n"
return htmlresult.encode('utf-8')
def mergestore(self, inputstore, templatetext, includefuzzy):
"""converts a file to .po format"""
htmlresult = templatetext.replace("\n", " ")
if isinstance(htmlresult, str):
#TODO: get the correct encoding
htmlresult = htmlresult.decode('utf-8')
# TODO: use the algorithm from html2po to get blocks and translate them individually
# rather than using replace
for inputunit in inputstore.units:
if inputunit.isheader():
continue
msgid = inputunit.source
msgstr = None
if includefuzzy or not inputunit.isfuzzy():
msgstr = self.wrapmessage(inputunit.target)
else:
msgstr = self.wrapmessage(inputunit.source)
if msgstr.strip():
htmlresult = htmlresult.replace(msgid, msgstr, 1)
htmlresult = htmlresult.encode('utf-8')
if tidy:
htmlresult = str(tidy.parseString(htmlresult, **{'char_encoding': "utf8"}))
return htmlresult
def converthtml(inputfile, outputfile, templatefile, wrap=None, includefuzzy=False):
"""reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
inputstore = po.pofile(inputfile)
convertor = po2html(wrap=wrap)
if templatefile is None:
outputstring = convertor.convertstore(inputstore, includefuzzy)
else:
templatestring = templatefile.read()
outputstring = convertor.mergestore(inputstore, templatestring, includefuzzy)
outputfilepos = outputfile.tell()
outputfile.write(outputstring)
return 1
def main(argv=None):
from translate.convert import convert
from translate.misc import stdiotell
import sys
sys.stdout = stdiotell.StdIOWrapper(sys.stdout)
formats = {("po", "htm"):("htm",converthtml), ("po", "html"):("html",converthtml), ("po", "xhtml"):("xhtml",converthtml), ("po"):("html",converthtml)}
parser = convert.ConvertOptionParser(formats, usetemplates=True, description=__doc__)
if textwrap is not None:
parser.add_option("-w", "--wrap", dest="wrap", default=None, type="int",
help="set number of columns to wrap html at", metavar="WRAP")
parser.passthrough.append("wrap")
parser.add_fuzzy_option()
parser.run(argv)
if __name__ == '__main__':
main()
--
ubuntu-translators mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-translators