miracle2k / android2po

Convert Android string resources to gettext, and back.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python 3?

gforcada opened this issue · comments

Is support for python 3 planned?

Our project https://github.com/Softcatala/translation-memory-tools relies on android2po, and as we are thinking on supporting python 3 our dependencies also need to support it too.

If there's no plans but a pull request would be welcome we will evaluate it and try to contribute it.

I don't have any plans, but I would certainly accept patches. If I did it myself I might even drop support for Py2 completely, since to me this was never really intended to be used as a library, but maybe then its a good thing to keep Py2 support as well.

I've added Python 3 support in my fork and have it running in Travis-CI to make sure it doesn't break.

Do you want to submit a PR?

This should be closed.

Hey, nice to see this evolve - I've just tried the latest master with python3.5 and I get an error due to colors:

Traceback (most recent call last):
  File "/home/richq/src/android2po/scripts/a2po", line 3, in <module>
    android2po.run()
  File "/home/richq/src/android2po/android2po/program.py", line 227, in run
    sys.exit(main(sys.argv) or 0)
  File "/home/richq/src/android2po/android2po/program.py", line 217, in main
    writer.finish()
  File "/home/richq/src/android2po/android2po/utils.py", line 260, in finish
    action.done('failed')
  File "/home/richq/src/android2po/android2po/utils.py", line 165, in done
    self.writer._print_action(self)
  File "/home/richq/src/android2po/android2po/utils.py", line 297, in _print_action
    self._print_action_header(action)
  File "/home/richq/src/android2po/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.5/codecs.py", line 377, in write
    self.stream.write(data)
TypeError: write() argument must be str, not bytes

Seems like the output to stdout is binary with the ANSI escape codes embedded, but stdout wants a string.

FWIW, this hack in utils.py Writer.__init__ makes things work - just write direct to stdout instead of wrapping it in a codec. My $LANG is en_US.utf8 by the way, nothing exotic.

        # Create a codec writer wrapping stdout
        #isatty = sys.stdout.isatty() \
        #    if hasattr(sys.stdout, 'isatty') else False
        #self.stdout = codecs.getwriter(
        #    sys.stdout.encoding
        #        if isatty
        #        else locale.getpreferredencoding())(sys.stdout)
        self.stdout = sys.stdout

I'm closing this. Let's address any problems with Python 3 support in a new pull request.