2
votes

I'm currently using django 1.3 for my project. I'm working on the localization of the project. I'm able to localize the python code and templates, but I'm having trouble with the javascript localization. I'm getting TemplateSyntaxError message saying that "Caught NoReverseMatch while rendering: Reverse for ''django.views.i18n.javascript_catalog'' with arguments '()' and keyword arguments '{}' not found." I put the part of my url.py and the template home.html codes below. I checked django.views.i18n.javascript_catalog using python manage.py shell which is fine.

Can you tell me what I'm doing wrong?

Shouldn't url function in the template result in http:///jsi18n/?

Thanks!

Min

=== urls.py ===

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

urlpatterns = patterns('',

    url(r'^$', 'messages.views.home', name='home'),
    url(r'^messages/$', include('messages.urls')),

    # Localization
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

=== end ===

=== home.html ===

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

=== end ===

2

2 Answers

7
votes

I finally found the reason for this error. The error is not related to the localization. If you change

<script... {% url 'django.views.i18n.javascript_catalog' %}"></script>

to

<script... {% url django.views.i18n.javascript_catalog %}"></script>

the error goes away.

Note that in urls.py, it is

url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

In short, in the html template file, no quotes around django.views.i18n.javascript_catalog whereas the the urls.py file, quotes around django.views.i18n.javascript_catalog. After this, I was able to get the javascript translation working.

Min

0
votes

had the same error but found out that i had this:

url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog',js_info_dict),
url(r'^i18n/', include('django.conf.urls.i18n')),

instead of this:

url(r'^i18n/', include('django.conf.urls.i18n')),
url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),