1
votes

I am trying to install a Russian translation on a Django site.

What I did: in the 'locale' folder, alongside other languages I created the 'ru' folder then inside that I created the 'LC_MESSAGES' folder and that's where I placed the 'django.po' file with the translations. I created that .po file manually because the translations were given to me as an Excel file. In that .po file I copied the header that I found in another .po file on the same project and then with a script I created the 'msgid' / 'msgstr' pairs extracting this info from the Excel file. I checked the file and after modifying manually some errors it appeared to be correct and when doing a compilemessages I receive no error and the .mo file gets created. Then I added 'ru' as a language in the settings file. Then I reloaded the home page and in the widget that we use to switch languages appeared Russian. But when I click it, it reloads the page and I get the Unicode error.

Some context: The site is in English but a Spanish translation is already installed and working properly with non ascii characters.

Any idea is welcome, even if not a full solution, just a way to debug it would be appreciated.

The error is: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128). You passed in ()

From what I have found it is a problem with ugettext lazy but what I don't understand is why it works with other translations...

I get a Unicode hint from Django: The string that could not be encoded/decoded was: ������ This string changes according to what page I try to load.

Here is the traceback:

Traceback:
File "/home/env/project/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  136.                     response.render()
File "/home/env/project/lib/python2.7/site-packages/django/template/response.py" in render
  96.             self._set_content(self.rendered_content)
File "/home/env/project/lib/python2.7/site-packages/django/template/response.py" in rendered_content
  75.         content = template.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render
  123.             return self._render(context)
File "/home/env/project/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
  57.     return self.nodelist.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render_node
  757.         return node.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  127.         return compiled_parent._render(context)
File "/home/env/project/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
  57.     return self.nodelist.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render_node
  757.         return node.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  127.         return compiled_parent._render(context)
File "/home/env/project/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
  57.     return self.nodelist.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render_node
  757.         return node.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  64.             result = block.nodelist.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render
  744.                 bits.append(self.render_node(node, context))
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in render_node
  757.         return node.render(context)
File "/home/env/project/lib/python2.7/site-packages/django/templatetags/i18n.py" in render
  76.         return _render_value_in_context(output, context)
File "/home/env/project/lib/python2.7/site-packages/django/template/base.py" in _render_value_in_context
  777.     value = force_unicode(value)
File "/home/env/project/lib/python2.7/site-packages/django/utils/encoding.py" in force_unicode
  93.             raise DjangoUnicodeDecodeError(s, *e.args)

Exception Type: DjangoUnicodeDecodeError at /
Exception Value: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128). You passed in <django.utils.functional.__proxy__ object at 0x9f3f16c> (<class 'django.utils.functional.__proxy__'>)

Edit:

I tried to start again from scratch. I deleted my manually created locale folder and .po files to try with the 'makemessages' command and during the execution of that command I get this error:

processing language ru
Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_manager(settings)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/commands/makemessages.py", line 365, in handle_noargs
    make_messages(locale, domain, verbosity, process_all, extensions, symlinks, ignore_patterns, no_wrap, no_obsolete)
  File "/home/env/project/lib/python2.7/site-packages/django/core/management/commands/makemessages.py", line 233, in make_messages
    f.write(templatize(src, orig_file[2:]))
  File "/home/env/project/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 127, in templatize
    return _trans.templatize(src, origin)
  File "/home/env/project/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 450, in templatize
    content = u''.join(comment)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

So obviously something must be wrong somewhere else. I'll keep looking.

Edit:

Apparently the 'makemessages' tool cannot handle non ascii characters in templates, whether marked as to be translated or not. I spotted quite a lot of them and I don't know yet what to do with them. Once I find it I will report here.

1
Please do post the traceback. It will help you understand which procedure is throwing the error. - Jim DeLaHunt
Ok I have just updated the question with the traceback. - Bastian
I am going to start everything again from scratch and try to understand where it crashes. I'll report here if I find anything interesting. - Bastian

1 Answers

0
votes

I have updated to Django 1.4.5 and the problem totally disappeared. The .po file is generated properly and the compilation goes well too.