Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on unicode character \u00A0 #52

Open
farindk opened this issue Apr 28, 2017 · 4 comments
Open

Error on unicode character \u00A0 #52

farindk opened this issue Apr 28, 2017 · 4 comments

Comments

@farindk
Copy link

farindk commented Apr 28, 2017

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)

@hansfn
Copy link
Contributor

hansfn commented Feb 21, 2018

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.

@farindk
Copy link
Author

farindk commented Feb 21, 2018

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.

@hansfn
Copy link
Contributor

hansfn commented Feb 21, 2018

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.

@brentinrochester
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants