Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2183 (closed defect: fixed)

Opened 9 years ago

Last modified 8 years ago

[PATCH] tg-admin i18n collect exception on JavaScript files with non-ascii chars

Reported by: zafy Owned by: Chris Arndt
Priority: normal Milestone: 1.1
Component: TurboGears Version: 1.0.8
Severity: normal Keywords: internationalization
Cc:

Description

Javascript file in turbogears accept the _() to wrap the strings and translate them using the i18n module. However if these strings contain non-ascii characters, the following error occurs when trying to run tg-admin i18n collect on the javascript file :

Traceback (most recent call last):
  File "/usr/bin/tg-admin", line 8, in <module>
    load_entry_point('TurboGears==1.0.8', 'console_scripts', 'tg-
admin')()
  File "/usr/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/
turbogears/command/base.py", line 400, in main
    command.run()
  File "/usr/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/
turbogears/command/i18n.py", line 137, in run
    self.scan_source_files()
  File "/usr/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/
turbogears/command/i18n.py", line 310, in scan_source_files
    self.scan_js_files(tmp_potfile, js_files)
  File "/usr/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/
turbogears/command/i18n.py", line 414, in scan_js_files
    text = normalize(text.decode().encode('utf-8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
12: ordinal not in range(128) 

I solved the problem by changing the code in /usr/lib/python2.5/site-packages/TurboGears-1.0.8-py2.5.egg/turbogears/command/i18n.py :

the code was :

line 182 in create_js_messages : key = unicode(key) 
line 414 in scan_js_files : text = normalize(text.encode('utf-8'))

so I changed it to :

line 182 in create_js_messages : key = unicode(key.decode('utf-8')) 
line 414 in scan_js_files : text = normalize(text)

This way, the strings are being collected as they are and they are converted back to utf-8 when creating the message-xx.js.

I am attaching my resulting patch just in case.

issue is described here as well :  http://groups.google.com/group/turbogears/browse_thread/thread/a1b482fd2c406ade

Attachments

i18n.patch Download (946 bytes) - added by zafy 9 years ago.
i18n.py patch file

Change History

Changed 9 years ago by zafy

i18n.py patch file

comment:1 Changed 8 years ago by Chris Arndt

  • Status changed from new to assigned
  • Owner changed from faide to Chris Arndt
  • Summary changed from i18n collect on non-ascii characters in Javascript files to [PATCH] i18n collect on non-ascii characters in Javascript files

comment:2 Changed 8 years ago by Chris Arndt

  • Summary changed from [PATCH] i18n collect on non-ascii characters in Javascript files to [PATCH] tg-admin i18n collect exception on JavaScript files with non-ascii chars

comment:3 Changed 8 years ago by Chris Arndt

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed in r6645 for all 1.x branches. "tg-admin i18n collect" now has a new option -e|--js-encoding to set the file encoding of the JS source files.

Note: See TracTickets for help on using tickets.