{{{
from django.views.i18n import javascript_catalog
js_info_dict = {
'packages': ('your.app.package',),
}
urlpatterns = [
url(r'^jsi18n/$', javascript_catalog, js_info_dict),
]
}}}
This will not work unless the javascript url is added to urlpatterns under
i18n_patterns:
{{{
from django.views.i18n import javascript_catalog
from django.conf.urls.i18n import i18n_patterns
js_info_dict = {
'packages': ('your.app.package',),
}
urlpatterns = [
...
]
urlpatterns += i18n_patterns(
url(r'^jsi18n/$', javascript_catalog, js_info_dict),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25751>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:1>
Old description:
> To translate a string in a javascript file, the
> [https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#module-
> django.views.i18n docs] propose the following setup in the urls.py:
>
> {{{
> from django.views.i18n import javascript_catalog
>
> js_info_dict = {
> 'packages': ('your.app.package',),
> }
>
> urlpatterns = [
> url(r'^jsi18n/$', javascript_catalog, js_info_dict),
> ]
> }}}
>
> This will not work unless the javascript url is added to urlpatterns
> under i18n_patterns:
>
> {{{
> from django.views.i18n import javascript_catalog
> from django.conf.urls.i18n import i18n_patterns
>
> js_info_dict = {
> 'packages': ('your.app.package',),
> }
>
> urlpatterns = [
> ...
> ]
>
> urlpatterns += i18n_patterns(
> url(r'^jsi18n/$', javascript_catalog, js_info_dict),
> )
> }}}
New description:
To translate a string in a javascript file, the
[https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#module-
django.views.i18n docs] propose the following setup in the urls.py:
{{{
from django.views.i18n import javascript_catalog
js_info_dict = {
'packages': ('your.app.package',),
}
urlpatterns = [
url(r'^jsi18n/$', javascript_catalog, js_info_dict),
]
}}}
This will not work unless the javascript url is added to urlpatterns under
i18n_patterns:
{{{
from django.views.i18n import javascript_catalog
from django.conf.urls.i18n import i18n_patterns
js_info_dict = {
'packages': ('application.name',),
}
urlpatterns = [
...
]
urlpatterns += i18n_patterns(
url(r'^jsi18n/$', javascript_catalog, js_info_dict),
)
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:2>
Comment (by charettes):
I think you don't need `i18n_patterns` as long as you use
`LocaleMiddleware`.
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:3>
Comment (by raratiru):
I had placed LocaleMiddleware to the specific place described in the docs.
I could not receive the translation whatsoever although makemessages was
working as expected.
Then I bumped to a forgotten [http://stackoverflow.com/a/27147542/2996101
stackoverflow] post.
It felt like I won the lottery!
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:4>
Comment (by charettes):
Using `i18n_patterns` will make translations available under a language
specific namespace instead of relying on the `_language` session key,
`django_language` cookie and `Accept-Language` header.
What happens if you try access the non-i18n namespaced URL with an empty
session and an `Accept-Language` header set to `fr`?
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:5>
Comment (by raratiru):
Actually I do not have access to my computer now, but what was actually
happening was that when I reached the url:
/fr/my_page everything was translated to French except for the Javascript
strings.
I will also have to study some more in order to achieve accessing the url
with an empty session and an Accept-Language header set to fr!
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:6>
* needs_docs: 0 => 1
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
From what I understand your main `url_patterns` (the one defined by
`ROOT_URLCONF`) uses `i18n_patterns`.
In this case `LocaleMiddleware` will behave
[https://github.com/django/django/blob/abcdb237bb313d116ce2ac8e90f79f61429afc70/django/middleware/locale.py#L63-L71
differently] by solely relying on the
[https://github.com/django/django/blob/abcdb237bb313d116ce2ac8e90f79f61429afc70/django/utils/translation/trans_real.py#L474-L487
request path] to determine the active language.
I guess we should add a note in the `i18n_patterns` documentation stating
if used all translated content views must also be placed within it.
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:7>
Comment (by raratiru):
That seems to be the issue, after all.
Thank you!
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:8>
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:9>
* needs_docs: 1 => 0
* component: Internationalization => Documentation
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:10>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/7351 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:11>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:12>
* owner: nobody => Ben Wilkins
* needs_better_patch: 1 => 0
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:13>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:14>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"9524fd9133e47fa90846904f81fe91c72f331e56" 9524fd9]:
{{{
#!CommitTicketReference repository=""
revision="9524fd9133e47fa90846904f81fe91c72f331e56"
Fixed #25751 -- Doc'd how to use JavaScriptCatalog with i18n_patterns().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:15>
Comment (by Tim Graham <timograham@…>):
In [changeset:"cdc343cac33d2e0b4d573e7c38ac0b2b7b19ea71" cdc343ca]:
{{{
#!CommitTicketReference repository=""
revision="cdc343cac33d2e0b4d573e7c38ac0b2b7b19ea71"
[1.10.x] Fixed #25751 -- Doc'd how to use JavaScriptCatalog with
i18n_patterns().
Backport of 9524fd9133e47fa90846904f81fe91c72f331e56 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:16>