[Django] #25751: Translation of strings in a javascript file docs are incorrect

15 views
Skip to first unread message

Django

unread,
Nov 13, 2015, 10:43:01 AM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file docs are incorrect
--------------------------------------+------------------------------------
Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Keywords: javascript translation
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
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),
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25751>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 13, 2015, 10:47:53 AM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by raratiru):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:1>

Django

unread,
Nov 13, 2015, 10:52:27 AM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by raratiru:

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>

Django

unread,
Nov 13, 2015, 12:03:29 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Nov 13, 2015, 1:08:30 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Nov 13, 2015, 1:23:49 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Nov 13, 2015, 1:28:31 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------

Reporter: raratiru | Owner: nobody
Type: Uncategorized | Status: new
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage:
translation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Nov 13, 2015, 1:49:06 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* 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>

Django

unread,
Nov 13, 2015, 3:41:08 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs are incorrect
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by raratiru):

That seems to be the issue, after all.

Thank you!

--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:8>

Django

unread,
Nov 13, 2015, 3:41:27 PM11/13/15
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs seem to be incorrect
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: | Version: 1.8
Internationalization |
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 0 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:9>

Django

unread,
Jul 8, 2016, 7:59:53 PM7/8/16
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs seem to be incorrect
-------------------------------------+-------------------------------------
Reporter: raratiru | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.8

Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_docs: 1 => 0
* component: Internationalization => Documentation


--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:10>

Django

unread,
Oct 13, 2016, 3:07:38 PM10/13/16
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs seem to be incorrect
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: nobody

Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/7351 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:11>

Django

unread,
Oct 14, 2016, 2:27:13 PM10/14/16
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs seem to be incorrect
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:12>

Django

unread,
Nov 5, 2016, 6:42:33 AM11/5/16
to django-...@googlegroups.com
#25751: Translation of strings in a javascript file: Docs seem to be incorrect
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: Ben
Type: | Wilkins
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ben Wilkins):

* owner: nobody => Ben Wilkins
* needs_better_patch: 1 => 0
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:13>

Django

unread,
Nov 15, 2016, 8:03:55 PM11/15/16
to django-...@googlegroups.com
#25751: Docs about i18n_patterns() + JS translation catalog view needs enhancements

-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: Ben
Type: | Wilkins
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 1.8
Severity: Normal | Resolution:
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25751#comment:14>

Django

unread,
Dec 15, 2016, 10:33:49 AM12/15/16
to django-...@googlegroups.com
#25751: Docs about i18n_patterns() + JS translation catalog view needs enhancements
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: Ben
Type: | Wilkins
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: fixed

Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Dec 15, 2016, 10:34:02 AM12/15/16
to django-...@googlegroups.com
#25751: Docs about i18n_patterns() + JS translation catalog view needs enhancements
-------------------------------------+-------------------------------------
Reporter: George Tantiras | Owner: Ben
Type: | Wilkins
Cleanup/optimization | Status: closed
Component: Documentation | Version: 1.8
Severity: Normal | Resolution: fixed
Keywords: javascript | Triage Stage: Accepted
translation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages