Opened 6 years ago

Closed 5 years ago

#22106 closed Bug (fixed)

catalogs of django.views.i18n.javascript_catalog overwrite each other

Reported by: Moritz Sichert Owned by: Moritz Sichert
Component: Internationalization Version: master
Severity: Normal Keywords: jsi18n javascript catalog
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Right now you can only use one instance of javascript_catalog, because they will override each other if you add more to one site.
This problem can easily be solved by making packages in kwargs for javascript_catalog include all packages needed instead of having a multiple views for different packages. That however makes the internationalization of javascript code that does not directly lie in the main application somewhat inflexible.


appA: app that contains the widget FunkyJSWidget that relies on some javascript and needs jsi18n.
appMain: your main app that contains all the views for your website. Your website also contains some javascript code that also uses jsi18n. It uses appA.FunkyJSWidget on some forms as well.

INSTALLED_APPS now is ('appA', 'appMain').
The problem now occurs on all your pages that use appA.FunkyJSWidget. Because the widget includes its javascript_catalog (per Media-class for example) as well as your appMain, one will override the other. You could obviously add appA to appMain.views.jsi18n's packages argument but this shouldn't be necessary.

Possible Solution

Modify django.views.i18n.js_catalog_template to detect if a catalog already exists. If it does, update it instead of overriding it. A minor issue is that the template omits some functions if they are not needed. That should be checked for all included javascript_catalogs, too.

Change History (7)

comment:1 Changed 6 years ago by Moritz Sichert

Has patch: set
Owner: changed from nobody to Moritz Sichert
Status: newassigned

comment:2 Changed 6 years ago by Moritz Sichert

Summary: Make django.views.i18n.javascript_catalog more flexiblecatalogs of django.views.i18n.javascript_catalog overwrite each other
Type: Cleanup/optimizationBug

comment:3 Changed 5 years ago by Moritz Sichert

Owner: changed from Moritz Sichert to Moritz Sichert

comment:4 Changed 5 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:5 Changed 5 years ago by Tim Graham

Patch needs improvement: set

comment:6 Changed 5 years ago by Moritz Sichert

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Thank you for your comments!
I corrected the errors and tests are now also passing in python2.7.

comment:7 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 6bb2175:

Fixed #22106 -- Allowed using more than one instance of javascript_catalog per project.

Note: See TracTickets for help on using tickets.
Back to Top