Skip to content

Commit 9fcdad2

Browse files
committed
[fix] Backported leaflet.draw.i18n.js workaround for withForms uncaught exception
1 parent 50b5c4b commit 9fcdad2

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
/**
3+
* Internationalization setup for Leaflet.draw
4+
* Adapted from django-leaflet:
5+
* https://github.com/makinacorpus/django-leaflet/blob/master/leaflet/static/leaflet/draw/leaflet.draw.i18n.js
6+
*
7+
* Using block scope to prevent 'withForms' variable leaking to global scope,
8+
* which would cause errors when this script is included multiple times
9+
* (particularly in Django inline formsets).
10+
*/
11+
const withForms = document.getElementById("with-forms")
12+
? JSON.parse(document.getElementById("with-forms").textContent)
13+
: false;
14+
if (withForms) {
15+
L.drawLocal.draw.toolbar.actions.title = JSON.parse(
16+
document.getElementById("draw-toolbar-actions-title").textContent,
17+
);
18+
L.drawLocal.draw.toolbar.actions.text = JSON.parse(
19+
document.getElementById("draw-toolbar-actions-text").textContent,
20+
);
21+
L.drawLocal.draw.toolbar.undo.title = JSON.parse(
22+
document.getElementById("draw-toolbar-undo-title").textContent,
23+
);
24+
L.drawLocal.draw.toolbar.undo.text = JSON.parse(
25+
document.getElementById("draw-toolbar-undo-text").textContent,
26+
);
27+
L.drawLocal.draw.toolbar.buttons.polyline = JSON.parse(
28+
document.getElementById("draw-toolbar-buttons-polyline").textContent,
29+
);
30+
L.drawLocal.draw.toolbar.buttons.polygon = JSON.parse(
31+
document.getElementById("draw-toolbar-buttons-polygon").textContent,
32+
);
33+
L.drawLocal.draw.toolbar.buttons.rectangle = JSON.parse(
34+
document.getElementById("draw-toolbar-buttons-rectangle").textContent,
35+
);
36+
L.drawLocal.draw.toolbar.buttons.circle = JSON.parse(
37+
document.getElementById("draw-toolbar-buttons-circle").textContent,
38+
);
39+
L.drawLocal.draw.toolbar.buttons.marker = JSON.parse(
40+
document.getElementById("draw-toolbar-buttons-marker").textContent,
41+
);
42+
L.drawLocal.draw.handlers.circle.tooltip.start = JSON.parse(
43+
document.getElementById("draw-handlers-circle-tooltip-start").textContent,
44+
);
45+
L.drawLocal.draw.handlers.marker.tooltip.start = JSON.parse(
46+
document.getElementById("draw-handlers-marker-tooltip-start").textContent,
47+
);
48+
L.drawLocal.draw.handlers.polygon.tooltip.start = JSON.parse(
49+
document.getElementById("draw-handlers-polygon-tooltip-start")
50+
.textContent,
51+
);
52+
L.drawLocal.draw.handlers.polygon.tooltip.cont = JSON.parse(
53+
document.getElementById("draw-handlers-polygon-tooltip-cont").textContent,
54+
);
55+
L.drawLocal.draw.handlers.polygon.tooltip.end = JSON.parse(
56+
document.getElementById("draw-handlers-polygon-tooltip-end").textContent,
57+
);
58+
L.drawLocal.draw.handlers.polyline.error = JSON.parse(
59+
document.getElementById("draw-handlers-polyline-error").textContent,
60+
);
61+
L.drawLocal.draw.handlers.polyline.tooltip.start = JSON.parse(
62+
document.getElementById("draw-handlers-polyline-tooltip-start")
63+
.textContent,
64+
);
65+
L.drawLocal.draw.handlers.polyline.tooltip.cont = JSON.parse(
66+
document.getElementById("draw-handlers-polyline-tooltip-cont")
67+
.textContent,
68+
);
69+
L.drawLocal.draw.handlers.polyline.tooltip.end = JSON.parse(
70+
document.getElementById("draw-handlers-polyline-tooltip-end").textContent,
71+
);
72+
L.drawLocal.draw.handlers.rectangle.tooltip.start = JSON.parse(
73+
document.getElementById("draw-handlers-rectangle-tooltip-start")
74+
.textContent,
75+
);
76+
L.drawLocal.draw.handlers.simpleshape.tooltip.end = JSON.parse(
77+
document.getElementById("draw-handlers-simpleshape-tooltip-end")
78+
.textContent,
79+
);
80+
81+
L.drawLocal.edit.toolbar.actions.save.title = JSON.parse(
82+
document.getElementById("edit-toolbar-actions-save-title").textContent,
83+
);
84+
L.drawLocal.edit.toolbar.actions.save.text = JSON.parse(
85+
document.getElementById("edit-toolbar-actions-save-text").textContent,
86+
);
87+
L.drawLocal.edit.toolbar.actions.cancel.title = JSON.parse(
88+
document.getElementById("edit-toolbar-actions-cancel-title").textContent,
89+
);
90+
L.drawLocal.edit.toolbar.actions.cancel.text = JSON.parse(
91+
document.getElementById("edit-toolbar-actions-cancel-text").textContent,
92+
);
93+
L.drawLocal.edit.toolbar.buttons.edit = JSON.parse(
94+
document.getElementById("edit-toolbar-buttons-edit").textContent,
95+
);
96+
L.drawLocal.edit.toolbar.buttons.editDisabled = JSON.parse(
97+
document.getElementById("edit-toolbar-buttons-editDisabled").textContent,
98+
);
99+
L.drawLocal.edit.toolbar.buttons.remove = JSON.parse(
100+
document.getElementById("edit-toolbar-buttons-remove").textContent,
101+
);
102+
L.drawLocal.edit.toolbar.buttons.removeDisabled = JSON.parse(
103+
document.getElementById("edit-toolbar-buttons-removeDisabled")
104+
.textContent,
105+
);
106+
L.drawLocal.edit.handlers.edit.tooltip.text = JSON.parse(
107+
document.getElementById("edit-handlers-edit-tooltip-text").textContent,
108+
);
109+
L.drawLocal.edit.handlers.edit.tooltip.subtext = JSON.parse(
110+
document.getElementById("edit-handlers-edit-tooltip-subtext").textContent,
111+
);
112+
L.drawLocal.edit.handlers.remove.tooltip.text = JSON.parse(
113+
document.getElementById("edit-handlers-remove-tooltip-text").textContent,
114+
);
115+
}
116+
}

0 commit comments

Comments
 (0)