ankitpopli1891 / django-autotranslate

A simple Django app to automatically translate the pot (.po) files generated by django's makemessages command using google translate.
https://ankitpopli1891.github.io/django-autotranslate/
MIT License
70 stars 39 forks source link

Iterable error when running translate_messages #37

Closed argolian closed 2 months ago

argolian commented 1 year ago

I am getting the following exception when I run either a command

python manage.py translate_messages -l 'fr'

or simply

python manage.py translate_messages

` File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv self.execute(*args, **cmd_options)

File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute output = self.handle(*args, **options)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/management/commands/translate_messages.py", line 81, in handle

self.translate_file(root, file, target_language)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/management/commands/translate_messages.py", line 101, in translate_file

translated_strings = tl.translate_strings(strings, target_language, self.source_language, False)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/services.py", line 44, in translate_strings assert isinstance(strings, collections.Iterable), 'strings should a iterable containing string_types'

AttributeError: module 'collections' has no attribute 'Iterable' `

According to https://stackoverflow.com/questions/59809785/i-get-a-attributeerror-module-collections-has-no-attribute-iterable-when-i

this is because collections.Iterable is deprecated. Replace it with collections.abc.Iterable.

As a test I modified the code

but I now get this error

`python manage.py translate_messages -l 'fr' Traceback (most recent call last): File "/home/john/www/travianpy/manage.py", line 22, in main()

File "/home/john/www/travianpy/manage.py", line 18, in main execute_from_command_line(sys.argv)

File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute()

File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv)

File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv self.execute(*args, **cmd_options)

File "/home/john/www/travianpy/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute output = self.handle(*args, **options)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/management/commands/translate_messages.py", line 81, in handle self.translate_file(root, file, target_language)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/management/commands/translate_messages.py", line 101, in translate_file translated_strings = tl.translate_strings(strings, target_language, self.source_language, False)

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/services.py", line 48, in translatestrings return translations if optimized else [ for _ in translations]

File "/home/john/www/travianpy/lib/python3.10/site-packages/autotranslate/services.py", line 48, in return translations if optimized else [ for in translations]

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 447, in return (_unwrapper_single_element(i) for i in

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 221, in _execute raise exception File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs)

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 441, in task r = self._translate_single_text(text, target_language, source_language)

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 340, in _translate_single_text results = list(self._execute(make_task(i) for i in split_text(text)))

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 209, in _execute yield each()

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 338, in return lambda: self._basic_translate(text, target_language, source_lauguage)[0]

File "/home/john/www/travianpy/lib/python3.10/site-packages/goslate.py", line 259, in _basic_translate data = {'src': raw_data[-1][0][0]}

IndexError: list index out of range `

Is there an updated version of this or any alternatives available, or am I missing an import somewhere?

thorntonedgar commented 1 year ago

@argolian this is an issue with python 3.10, collecitons moved a little bit. i fixed this in my code by try: assert isinstance(strings, collections.MutableSequence), \ 'stringsshould be a sequence containing string_types' except: assert isinstance(strings, collections.abc.MutableSequence), \

i'm opening a PR to fix in the package.

MichealCodez commented 3 months ago

Hi @thorntonedgar, was this fixed?

because I'm getting the same error

thorntonedgar commented 3 months ago

I think so but let me check and confirm.

Hi @thorntonedgar, was this fixed?

because I'm getting the same error

thorntonedgar commented 3 months ago

It's definitely fixed in 1.3.0. Doesn't look like it's been pushed to pypi yet but I don't have access. maybe @ankitpopli1891 can help?

MichealCodez commented 3 months ago

Oh, hi @ankitpopli1891

it will be nice if the 1.3.0 is pushed to pypi so everyone can have it going well on their end

ankitpopli1891 commented 2 months ago

version 1.3.0 is released on Pypi, thanks for being so patient. haven't tested it out myself, but from the conversation it seems this should be fixed now. @MichealCodez