miracle2k / android2po

Convert Android string resources to gettext, and back.
BSD 2-Clause "Simplified" License
126 stars 50 forks source link

crash on UTF-8 characters #35

Closed farindk closed 9 years ago

farindk commented 9 years ago

I get crashes when generating the .pot files during "init" and when converting back to "XML" with "import" on each input file containing any non-ASCII UTF-8 characters.

For example: File "/usr/local/lib/python2.7/dist-packages/android2po-1.3.dev-py2.7.egg/android2po/commands.py", line 184, in write_file f.write(content) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 19558: ordinal not in range(128)

UTF-8 is specified in the XML file: <?xml version="1.0" encoding="utf-8"?>

Anything I am missing or is UTF-8 support missing (which would make a translation tool pretty unusable)?

miracle2k commented 9 years ago

Python 3 support was recently merged, and I'd wager it is related to that.

Until the bug is fixed (I don't have time to look right now), you could try using the other Python version (2 if the error occurs with 3, or 3 if the error occurs with 2).

farindk commented 9 years ago

I am a complete python noob, but I now tried with python3. Hope that I did everything correctly. Now I get this error:

$ a2po init --android . --gettext . Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/android2po/program.py", line 215, in main command_result = cmd.execute() File "/usr/local/lib/python3.4/dist-packages/android2po/commands.py", line 407, in execute something_done = self.generate_templates(update=False) File "/usr/local/lib/python3.4/dist-packages/android2po/commands.py", line 293, in generate_templates kind, do_write=True, update=update) File "/usr/local/lib/python3.4/dist-packages/android2po/commands.py", line 279, in make_or_get_template action=action, ignore_exists=True, update=update): File "/usr/local/lib/python3.4/dist-packages/android2po/commands.py", line 171, in write_file action.done('exists') File "/usr/local/lib/python3.4/dist-packages/android2po/utils.py", line 165, in done self.writer._print_action(self) File "/usr/local/lib/python3.4/dist-packages/android2po/utils.py", line 297, in _print_action self._print_action_header(action) File "/usr/local/lib/python3.4/dist-packages/android2po/utils.py", line 323, in _print_action_header self.stdout.write(colored("%_s" % (self.max_event_len, tag), attrs=['bold',], *_style)) File "/usr/lib/python3.4/codecs.py", line 369, in write self.stream.write(data) TypeError: must be str, not bytes

It's not that urgent. I will simply wait for an update :)

mauriciogior commented 9 years ago

@farindk fixed on https://github.com/miracle2k/android2po/pull/36