Basically everytime I used the tg-admin i18n collect command, if I had
a javascript file containing non-ascii characters, it would give me a
unicode error.
This was apparently supposed to be fixed here : http://trac.turbogears.org/changeset/6645.
Now I've been trying to collect my strings using tg-admin collect --js-
encoding utf-8 but I'm getting the following error :
Traceback (most recent call last):
File "/usr/bin/tg-admin", line 8, in <module>
load_entry_point('TurboGears==1.1', 'console_scripts', 'tg-admin')
()
File "/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/
turbogears/command/base.py", line 416, in main
command.run()
File "/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/
turbogears/command/i18n.py", line 150, in run
self.scan_source_files()
File "/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/
turbogears/command/i18n.py", line 336, in scan_source_files
self.scan_js_files(tmp_potfile, js_files)
File "/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/
turbogears/command/i18n.py", line 481, in scan_js_files
self._write_potfile_entries(potfile, messages)
File "/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/
turbogears/command/i18n.py", line 489, in _write_potfile_entries
text = catalog.normalize(text.encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
13: ordinal not in range(128)
So if there is someone around here who knows where the problem is and
how I can fix it, it would be very cool. Removing the non-ascii
characters from my js strings is not really an option as there are a
LOT of them.
Thanks for the help.
Can you show at least an example of one such files?
Diez
What's very weird, is that after some debugging,I realized line 10
failed but not the others and only one string in line 10 actually
fails.
I did this to figure out the problem : (this is in turbogears/command/
i18n.py, line 483)
def _write_potfile_entries(self, potfile, messages):
if messages:
fd = open(potfile, 'at+')
for linenumber, fname, text in messages:
if text == '':
continue
print 'Original, ',type(text), text, fname, linenumber
text = catalog.normalize(text.encode('utf-8'))
fd.write('#: %s:%s\n' % (fname, linenumber))
fd.write('msgid %s\n' % text)
fd.write('msgstr ""\n\n')
fd.close()
and this is the output I get for line 10 :
Original, <type 'unicode'> clé(s) envoyée(s). cinego/static/
javascript/film.js 222
Original, <type 'str'> Afficher le détail cinego/static/javascript/
film.js 222
I don't understand why one string would be typed as string and another
as unicode.
I'm guessing it's got to do with my typing of the strings but I really
don't see what's wrong.
Tom
/usr/lib/python2.5/site-packages/TurboGears-1.1-py2.5.egg/turbogears/
command/i18n.py:469: UnicodeWarning: Unicode equal comparison failed
to convert both arguments to Unicode - interpreting them as being
unequal
Don't know if it's related...
Tom
Well, that's pretty simple: you saved them in some different encoding
than UTF-8. Which is required for the command to work (there might be
some parameter to determine the encoding, I don't remember that).
And shuffling the files around might have convinced your editor to store
them as UTF-8 by accident. Whatever editor you use, you should try &
figure out how to convince it to save in utf-8 by default.
Diez