Django i18n Javascript Problem

限于喜欢 提交于 2019-12-07 12:41:20

问题


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.


回答1:


you should run

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

for each language you have :)




回答2:


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 %}



来源:https://stackoverflow.com/questions/5750903/django-i18n-javascript-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!