android2po icon indicating copy to clipboard operation
android2po copied to clipboard

Error on unicode character \u00A0

Open farindk opened this issue 8 years ago • 4 comments

When using Unicode character \u00A0 (non-breaking whitespace) in a strings.xml, I get the crash below. Anything wrong with my configuration (if there is any) or any quick fix for that?


u'00A0' u'00A0' u'00A0' [failed] locale/strings.pot Traceback (most recent call last): File "/usr/local/bin/a2po", line 3, in android2po.run() File "/usr/local/lib/python2.7/dist-packages/android2po/program.py", line 227, in run sys.exit(main(sys.argv) or 0) File "/usr/local/lib/python2.7/dist-packages/android2po/program.py", line 215, in main command_result = cmd.execute() File "/usr/local/lib/python2.7/dist-packages/android2po/commands.py", line 464, in execute self.generate_templates() File "/usr/local/lib/python2.7/dist-packages/android2po/commands.py", line 293, in generate_templates kind, do_write=True, update=update) File "/usr/local/lib/python2.7/dist-packages/android2po/commands.py", line 264, in make_or_get_template xmldata = read_xml(action, self.env.default.xml(kind)) File "/usr/local/lib/python2.7/dist-packages/android2po/commands.py", line 63, in read_xml return convert.read_xml(filename, warnfunc=action.message, **kw) File "/usr/local/lib/python2.7/dist-packages/android2po/convert.py", line 370, in read_xml text, formatted = get_element_text(tag, name, warnfunc) File "/usr/local/lib/python2.7/dist-packages/android2po/convert.py", line 310, in get_element_text converted_value, elem_formatted = convert_text(t) File "/usr/local/lib/python2.7/dist-packages/android2po/convert.py", line 242, in convert_text return "".join(text[:-1]), formatted UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)

farindk avatar Apr 28 '17 15:04 farindk

The important part of the error is: "UnicodeDecodeError: 'ascii' codec can't decode". We need to know why the ascii codec is used for Unicode/UTF-8.

If this still is a problem for you, please attach the xml file causing the error.

hansfn avatar Feb 21 '18 12:02 hansfn

It seems I cannot attach an XML file here, but a very simple input file will do already:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="blabla">just some bla\u00a0bla</string>
</resources>

I am simply running a2po export --android . --gettext locale with python 2.7.12.

farindk avatar Feb 21 '18 14:02 farindk

I tested on Python 3 and couldn't reproduce the issue - it just worked. I don't have time to look at this for Python 2.

PS! You cant use "\u00a0" inside the XML file, but I just replaced it with an actual non-breaking space.

hansfn avatar Feb 21 '18 22:02 hansfn

I had a similar problem with unicode escapes. I did not get a crash, but instead all strings with unicode escape were being omitted. Based on this thread I installed android2po again using my python3 binaries and the problem went away.

brentinrochester avatar Dec 04 '19 19:12 brentinrochester