Coder Social home page Coder Social logo

ankitpopli1891 / django-autotranslate Goto Github PK

View Code? Open in Web Editor NEW
69.0 69.0 38.0 156 KB

A simple Django app to automatically translate the pot (.po) files generated by django's makemessages command using google translate.

Home Page: https://ankitpopli1891.github.io/django-autotranslate/

License: MIT License

Python 100.00%
django internationalization localization python

django-autotranslate's Introduction

Hi there 👋

Need help with your product ? I can help in reaching out to the amazing people @codemymobile.

django-autotranslate's People

Contributors

anilshanbhag avatar ankitpopli1891 avatar generalov avatar gpavlovichhtec avatar pogowurst avatar prayagverma avatar santteegt avatar thomaspaulb avatar thorntonedgar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-autotranslate's Issues

Efficient API Usage

Hello,

Currently, the library translates for each word within the po files. I think that it should check whether related message id is translated before or not. This helps us to improve the efficiency of using the Google Translate API.

UTF-8 encodings break the entire .po file

To Fix change add codecs usage to the code in translate_messages.py as the following:

from autotranslate.utils import translate_strings

from django.conf import settings
from django.core.management.base import BaseCommand

from optparse import make_option

import os
import codecs

class Command(BaseCommand):
    help = ('autotranslate all the message files that have been generated '
            'using the `makemessages` command.')

    option_list = BaseCommand.option_list + (
        make_option('--locale', '-l', default=[], dest='locale', action='append',
                    help='autotranslate the message files for the given locale(s) (e.g. pt_BR). '
                         'can be used multiple times.'),
    )

    def add_arguments(self, parser):
        # Previously, only the standard optparse library was supported and
        # you would have to extend the command option_list variable with optparse.make_option().
        # See: https://docs.djangoproject.com/en/1.8/howto/custom-management-commands/#accepting-optional-arguments
        # In django 1.8, these custom options can be added in the add_arguments()
        parser.add_argument('--locale', '-l', default=[], dest='locale', action='append',
                            help='autotranslate the message files for the given locale(s) (e.g. pt_BR). '
                                 'can be used multiple times.')

    def handle(self, *args, **options):
        locale = options.get('locale')
        assert getattr(settings, 'USE_I18N', False), 'i18n framework is disabled'
        assert getattr(settings, 'LOCALE_PATHS', []), 'locale paths is not configured properly'
        for directory in settings.LOCALE_PATHS:
            # walk through all the paths
            # and find all the pot files
            for root, dirs, files in os.walk(directory):
                for file in files:
                    if not file.endswith('.po'):
                        # process file only
                        # if its a pot file
                        continue

                    # get the target language from the parent folder name
                    target_language = os.path.basename(os.path.dirname(root))

                    if locale and target_language not in locale:
                        #print "Skipping language %s" % target_language
                        continue

                    self.translate_file(root, file, target_language)

    @classmethod
    def translate_file(cls, root, file_name, target_language):
        """
        convenience method for translating a pot file

        :param root:            the absolute path of folder where the file is present
        :param file_name:       name of the file to be translated (it should be a pot file)
        :param target_language: language in which the file needs to be translated
        """
        print('translating ', target_language)

        strings = []
        translations = {}
        with codecs.open(os.path.join(root, file_name),'r','utf-8') as _input_file:
            original_file = _input_file.readlines()
            for index, line in enumerate(original_file):
                if line.startswith('msgid'):
                    # separate the actual string from the whole line
                    # for each line in input file
                    strings.append('"'.join(line.split('"')[1:-1]))
                if line.startswith('msgstr'):
                    # map the line number with the raw string
                    # taken out for translation
                    translations.update({
                        index: line
                    })

        # translate the strings,
        # all the translated strings are returned
        # in the same order on the same index
        # viz. [a, b] -> [trans_a, trans_b]
        translated_strings = translate_strings(strings, target_language, 'en', False)

        # sort the numbers to make sure all the translations
        # are injected at the right position
        keys = [_ for _ in translations.keys()]
        keys.sort()

        index = 0
        for key in keys:
            line = translations.get(key).split('"')
            line = [line[0], line[-1]]
            line.insert(1, translated_strings[index])
            line = '"'.join(line)
            translations[key] = line
            index += 1

        with codecs.open(os.path.join(root, file_name), 'w','utf-8') as output_file:
            for index, line in enumerate(original_file):
                if index in translations.keys():
                    line = translations.get(index)
                    output_file.write(line)
                    continue
                output_file.write(line)

Django autotranslate installation fails

Collecting django-autotranslate
  Using cached django-autotranslate-1.1.0.tar.gz (8.7 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/sharat/.virtualenvs/mycroft/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-install-y2vmq72u/django-autotranslate/setup.py'"'"'; __file__='"'"'/private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-install-y2vmq72u/django-autotranslate/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-pip-egg-info-rcg342li
         cwd: /private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-install-y2vmq72u/django-autotranslate/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-install-y2vmq72u/django-autotranslate/setup.py", line 25, in <module>
        requirements = [str(ir.req) for ir in install_requirements]
      File "/private/var/folders/lw/n4rl9vm16t38zzv2x_kl74xc0000gn/T/pip-install-y2vmq72u/django-autotranslate/setup.py", line 25, in <listcomp>
        requirements = [str(ir.req) for ir in install_requirements]
    AttributeError: 'ParsedRequirement' object has no attribute 'req'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

It is failing when installing via pip 20.1
This issue seems to be related pypa/pip#8188

IndexError: list index out of range

I get this error every time I try to used it

$ python3 manage.py translate_messages 
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/mestre/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/mestre/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mestre/.local/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mestre/.local/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/home/mestre/.local/lib/python3.8/site-packages/autotranslate/management/commands/translate_messages.py", line 76, in handle
    self.translate_file(root, file, target_language)
  File "/home/mestre/.local/lib/python3.8/site-packages/autotranslate/management/commands/translate_messages.py", line 96, in translate_file
    translated_strings = tl.translate_strings(strings, target_language, 'en', False)
  File "/home/mestre/.local/lib/python3.8/site-packages/autotranslate/services.py", line 46, in translate_strings
    return translations if optimized else [_ for _ in translations]
  File "/home/mestre/.local/lib/python3.8/site-packages/autotranslate/services.py", line 46, in <listcomp>
    return translations if optimized else [_ for _ in translations]
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 441, in <genexpr>
    return (_unwrapper_single_element(i) for i in
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 203, in _execute
    yield each()
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 435, in task
    r = self._translate_single_text(text, target_language, source_language)
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 334, in _translate_single_text
    results = list(self._execute(make_task(i) for i in split_text(text)))
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 203, in _execute
    yield each()
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 332, in <lambda>
    return lambda: self._basic_translate(text, target_language, source_lauguage)[0]
  File "/home/mestre/.local/lib/python3.8/site-packages/goslate.py", line 253, in _basic_translate
    data = {'src': raw_data[-1][0][0]}
IndexError: list index out of range

IndexError

python --version : Python 3.6.8
python manage.py --version : 2.2

output of python manage.py translate_messages

    Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 76, in handle
    self.translate_file(root, file, target_language)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 96, in translate_file
    translated_strings = tl.translate_strings(strings, target_language, 'en', False)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/autotranslate/services.py", line 46, in translate_strings
    return translations if optimized else [_ for _ in translations]
  File "/home/vagrant/.venv/lib/python3.6/site-packages/autotranslate/services.py", line 46, in <listcomp>
    return translations if optimized else [_ for _ in translations]
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 441, in <genexpr>
    return (_unwrapper_single_element(i) for i in
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 215, in _execute
    raise exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 435, in task
    r = self._translate_single_text(text, target_language, source_language)
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 334, in _translate_single_text
    results = list(self._execute(make_task(i) for i in split_text(text)))
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 203, in _execute
    yield each()
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 332, in <lambda>
    return lambda: self._basic_translate(text, target_language, source_lauguage)[0]
  File "/home/vagrant/.venv/lib/python3.6/site-packages/goslate.py", line 253, in _basic_translate
    data = {'src': raw_data[-1][0][0]}
IndexError: list index out of range

HTTP Error 429: Too Many Requests

Using the translate_messages -l 'fr' command results in the following error:

urllib.error.HTTPError: HTTP Error 429: Too Many Requests

Using the translate_messages command without specifying the locale results in the follow error:

File "/usr/local/lib/python3.8/site-packages/goslate.py", line 253, in _basic_translate
data = {'src': raw_data[-1][0][0]}
IndexError: list index out of range

goslate dependency has been abandoned/deleted

One of the dependencies, goslate, has been abandoned and deleted by its author. It needs to be replaced.

Google has updated its translation service recently with a ticket mechanism to prevent simple crawler program like goslate from accessing. Though a more sophisticated crawler may still work technically, however it would have crossed the fine line between using the service and breaking the service. goslate will not be updated to break google’s ticket mechanism. Free lunch is over. Thanks for using.

Source: https://pypi.org/project/goslate/

The function `translate_strings` returns wrong value then it called twice

from autotranslate.services import translate_strings

res1 = translate_strings(['Hello'], 'de', 'en', False)
res2 = translate_strings(['Hello'], 'fr', 'en', False)

def translate_strings(self, strings, target_language, source_language='en', optimized=True):

The result of the first call contains one translation into 'de' language as expected.
But the result of the second call contains two translations and the first result element is the translation into 'de' language from the first function call. It seems the function accomulates results between calls.
I expect the result for the second function call has only one translation into 'fr' language.

Alternative source language

I believe that is a good feature the possibility of translate from other language diferente of us.
You may create create in settings.py like source_language=xx and default is us.
tks.

Too many text segments Error

Google Translate API V2 has a limitation per each request should have 128 query entries. I think current version sends without limitation.

Getting 503 Service Unavailable Error

I am getting
urllib.error.HTTPError: HTTP Error 503: Service Unavailable
on executing
python manage.py translate_messages

Any idea what's is wrong here?

googleapiclient.errors.HttpError: <HttpError 500 when requesting https://www.googleapis.com/language/translate/v2 returned "Internal Error">

Got this error due to a 500 error

MacBook-Air-3:jobmind pierreslam$ ./manage.py translate_messages -u -l de
Traceback (most recent call last):
  File "./manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/management/commands/translate_messages.py", line 69, in handle
    self.translate_file(root, file, target_language)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/management/commands/translate_messages.py", line 87, in translate_file
    translated_strings = translate_strings(strings, target_language, 'en', False)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 90, in translate_strings
    target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 88, in translate_strings
    self.translate_strings(strings[0:self.max_segments], target_language, source_language, optimized)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/autotranslate/services.py", line 84, in translate_strings
    .list(source=source_language, target=target_language, q=strings).execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/oauth2client/util.py", line 132, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googleapiclient/http.py", line 723, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 500 when requesting https://www.googleapis.com/language/translate/v2 returned "Internal Error">

Iterable error when running translate_messages

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 translate_strings
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?

Can translate only from English

In autotranslate/management/commands/translate_messages.py : 96 hardcoded 'en' as source_language.

Better set to settings.LANGUAGE_CODE or add own setting var for this app

Django autotranslate installation fails

I keep getting this error anytime I attempt to install the package. I'm trying to install it within a docker environment.

pip3 install --upgrade -r test.txt

It gives the error below
image

IndexError while running the app using GOOGLE_TRANSLATE_KEY

I am getting the following error while running translate_messages. I have generated a Google Translate API key and set it as GOOGLE_TRANSLATE_KEY as well.

masked@masked:~/masked$ ./manage.py translate_messages -l ar -u 
2021-06-30 08:43:14.585 INFO [autotranslate.management.commands.translate_messages] skipping translation for locale `vi`
2021-06-30 08:43:14.586 INFO [autotranslate.management.commands.translate_messages] filling up translations for locale `ar`
2021-06-30 08:43:14.683 INFO [googleapiclient.discovery_cache] file_cache is only supported with oauth2client<4.0.0
Traceback (most recent call last):
  File "./manage.py", line 157, in <module>
    execute_from_command_line(sys.argv)
  File "./manage.py", line 122, in execute_from_command_line
    utility.execute()
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 81, in handle
    self.translate_file(root, file, target_language)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 102, in translate_file
    self.update_translations(po, translated_strings)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 154, in update_translations
    translation = fix_translation(entry.msgid, translation)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 196, in fix_translation
    translation = restore_placeholders(msgid, translation)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 182, in restore_placeholders
    translation)
  File "/srv/masked-py3-venv/lib/python3.6/re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/srv/masked-py3-venv/lib/python3.6/site-packages/autotranslate/management/commands/translate_messages.py", line 181, in <lambda>
    lambda matches: '{0}{1}{2}'.format(placehoders[0][0], placehoders[0][1], placehoders.pop(0)[2]),
IndexError: list index out of range

%(placeholder)s incorrect when translating to Chinese Characters

When converting something like
Hello %(placeholder)s

To Chinese becomes:
您好%(占位符)

The % symbol becomes a different Unicode character .
The ( character also becomes a different Unicode character .
Also sometimes the s disappears or moves.

And so this unfortunately fails at the compilemessages stage

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.