简体   繁体   中英

Django i18n Javascript Problem

I have this problem: When i set a language (it or en)in my django app, with this form , the javascript strings are converted always in English. My base Language is Italian.

This is my configuration: urls.py:

js_info_dict = { 'domain': 'djangojs', 'packages': ('myproject',), }

urlpatterns += patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict), )

I have run this command:

django-admin.py makemessages -d djangojs -l en

To generating the djangojs.mo/po files. I Have translated the string from it to en in that file. and i've run:

django-admin.py compilemessages

Now when I go on the page that contains this JS:

document.write(gettext('Questa stringa è da tradurre'));

the strings return always 'This string is to be translated', (That is the translation of 'Questa stringa è da tradurre')

I have included this js in my html file:

<script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>

Where am i wrong? Any Ideas? Thanks in advance.

you should run

django-admin.py makemessages -d djangojs -l en
django-admin.py compilemessages

for each language you have :)

In your file base.html add the following lines to the beginning

{% load static from staticfiles %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% get_available_languages as LANGUAGES %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM