#25751 closed Cleanup/optimization (fixed)
Docs about i18n_patterns() + JS translation catalog view needs enhancements
| Reported by: | George Tantiras | Owned by: | Ben Wilkins |
|---|---|---|---|
| Component: | Documentation | Version: | 1.8 |
| Severity: | Normal | Keywords: | javascript translation |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
To translate a string in a javascript file, the 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),
)
Change History (16)
comment:1 by , 10 years ago
| Summary: | Translation of strings in a javascript file docs are incorrect → Translation of strings in a javascript file: Docs are incorrect |
|---|
comment:2 by , 10 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 10 years ago
comment:4 by , 10 years ago
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 stackoverflow post.
It felt like I won the lottery!
comment:5 by , 10 years ago
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?
comment:6 by , 10 years ago
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!
comment:7 by , 10 years ago
| Needs documentation: | set |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
From what I understand your main url_patterns (the one defined by ROOT_URLCONF) uses i18n_patterns.
In this case LocaleMiddleware will behave differently by solely relying on the 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.
comment:9 by , 10 years ago
| Summary: | Translation of strings in a javascript file: Docs are incorrect → Translation of strings in a javascript file: Docs seem to be incorrect |
|---|
comment:10 by , 9 years ago
| Component: | Internationalization → Documentation |
|---|---|
| Needs documentation: | unset |
comment:12 by , 9 years ago
| Patch needs improvement: | set |
|---|
comment:13 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Patch needs improvement: | unset |
| Status: | new → assigned |
comment:14 by , 9 years ago
| Patch needs improvement: | set |
|---|---|
| Summary: | Translation of strings in a javascript file: Docs seem to be incorrect → Docs about i18n_patterns() + JS translation catalog view needs enhancements |
I think you don't need
i18n_patternsas long as you useLocaleMiddleware.