6

I am suppose to change some of these characters in English to Chinese in this setting.py file but then error happened.

I know that it's saying because no encoding is declared in the error message but I have been reading a few posts and still have no idea how / where I can make it happen.

in my setting.py I have something like this

OSCAR_DASHBOARD_NAVIGATION = [
{
    'label': _('dashboard'),
    'icon': 'icon-th-list',
    'url_name': 'dashboard:index',
},

but need to change the navigation to Chinese so ended up looking like this

OSCAR_DASHBOARD_NAVIGATION = [
{
    'label': _('仪表板'),
    'icon': 'icon-th-list',
    'url_name': 'dashboard:index',
},

Edit, I already read the post which thought might be duplicated and tried what's in that post and instead of getting errors, I get a no show in my page but regarding to Pedru's answer. It works like a charm now.

2
  • @Ilja tried, gives me no error but in browser it just shows blank totally nothing and if I type in English, the Characters will show up if I combine English with Chinese or Chinese only, it just shows a space nothing else Commented Apr 4, 2016 at 9:34
  • you should keep _('dashboard') in the source code and provide Chinese translation instead (gettext). You don't need to hardcode the language. Here's code example where gettext('world') from the source code can be shown using a chosen language.—the word 'world' is always in English in the code but it can be shown in any language in the browser if the corresponding translation is available. Commented Apr 5, 2016 at 10:20

1 Answer 1

19

Try adding

# -*- coding: utf-8 -*-

at the beginning of the file, make sure your file is really encoded in utf-8

Sign up to request clarification or add additional context in comments.

9 Comments

tried, gives me no error but in browser it just shows blank totally nothing and if I type in English, the Characters will show up if I combine English with Chinese or Chinese only, it just shows a space nothing else
I see you use the _( ) function, try replacing 'label': _('仪表板') with 'label': '仪表板'
Bravo! Thanks, this worked like a charm
I don't know if you have access to the code that reads the setting.py file, but I think it does something like _ = gettext.gettext, gettext does not support unicode, instead this should be used _ = gettext.ugettext
actually what I posted in inside the setting.py file and the json is pasted in there to override the default json info (Sorry first time working with python kind of have no idea what you really meant) but so if it's ugettext instead of gettext I didn't have to change that much things then?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.