开发者

Django i18n Javascript Problem

开发者 https://www.devze.com 2023-02-27 15:39 出处:网络
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.

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 fi开发者_运维问答les. 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 %}

0

精彩评论

暂无评论...
验证码 换一张
取 消