2

I try to localize OSQA (django + python) for russian language. A lot of string I can translate with locale-folder. But in OSQA some string was hard-coded (put in code in simple text).

I try simply replace english text to russian, but get an error.

For example:

class WordpressAuthContext(ConsumerTemplateContext):
    mode = 'SMALLICON'
    type = 'SIMPLE_FORM'
    simple_form_context = {
        'your_what': 'Wordpress blog name'
    }
    weight = 270
    human_name = 'Wordpress'
    icon = '/media/images/openid/wordpress.png'

In this code I need to replace 'Wordpress blog name' on russian text.

I try replace english characters with unicode \uXXXX characters, but on web-page I will see these characters in original view \uXXXX.

Then I try this code:

'your_what': 'Wordpress blog name'.encode('utf-8')

And it's not work too.

What can I try?

poke
  • 369,085
  • 72
  • 557
  • 602
  • Just a comment in your second part of code: You cannot encode a str because it's already encoded data. When you have an unicode object and want to store it in a file (.html here) you have to choose the way to represent each character: utf-8, iso-8859-1, latin-1, ... Once you've chosen which one, you have to `encode` the unicode object by calling `encode('utf-8')`. In the example you've shown you have a `str` object, not a unicode. Then decode('utf-8') is used to move from str to unicode again. – AlbertFerras Jun 26 '12 at 22:26

1 Answers1

2

Try:

simple_form_context = {
    'your_what': u'whätévèr wéird chars you w@ñt to ûse'
}

I really don't know if django is prepared to handle Unicode strings through all framework, but's worth trying.

I don't think it would be prepared to handle byte strings (like the one generated with .encode()), so forget about that.

KurzedMetal
  • 12,540
  • 6
  • 39
  • 65
  • thanks for your answer, but it's not work too. Web-page displayed string with u-prefix like \u0412\u0430\u0448\u0435 \u0438\u043C\u044F .... – user1436788 Jun 26 '12 at 20:23
  • check the [Django's Internationalization and localization documentation](https://docs.djangoproject.com/en/dev/topics/i18n/) – KurzedMetal Jun 26 '12 at 20:30