Skip to content

Commit ed4d65b

Browse files
committed
I18n nogo areas errors
1 parent b342840 commit ed4d65b

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

js/plugin/NogoAreas.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ BR.NogoAreas = L.Control.extend({
197197
resolve(reader.result);
198198
};
199199
reader.onerror = function () {
200-
self.displayUploadError('Could not load file: ' + reader.error.message);
200+
self.displayUploadError(
201+
i18next.t('loadNogos.error.loading-file-error', { err: reader.error.message })
202+
);
201203
};
202204

203205
reader.readAsText(nogoFile);
@@ -206,25 +208,25 @@ BR.NogoAreas = L.Control.extend({
206208
});
207209
} else {
208210
// FIXME: use form validator instead
209-
self.displayUploadError('Missing file or URL.');
211+
self.displayUploadError(i18next.t('loadNogos.error.missing-file-url'));
210212
return false;
211213
}
212214
var nogoWeight = parseFloat($('#nogoWeight').val());
213215
if (isNaN(nogoWeight)) {
214216
// FIXME: use form validator instead
215-
self.displayUploadError('Missing default nogo weight.');
217+
self.displayUploadError(i18next.t('loadNogos.error.missing-default-nogo-weight'));
216218
return false;
217219
}
218220
var nogoRadius = parseFloat($('#nogoRadius').val());
219221
if (isNaN(nogoRadius) || nogoRadius < 0) {
220222
// FIXME: use form validator instead
221-
self.displayUploadError('Invalid default nogo radius.');
223+
self.displayUploadError(i18next.t('loadNogos.error.invalid-default-nogo-radius'));
222224
return false;
223225
}
224226
var nogoBuffer = parseFloat($('#nogoBuffer').val());
225227
if (isNaN(nogoBuffer)) {
226228
// FIXME: use form validator instead
227-
self.displayUploadError('Invalid nogo buffering radius.');
229+
self.displayUploadError(i18next.t('loadNogos.error.invalid-nogo-buffering-radius'));
228230
return false;
229231
}
230232

@@ -243,7 +245,7 @@ BR.NogoAreas = L.Control.extend({
243245
});
244246

245247
if (cleanedGeoJSONFeatures.length === 0) {
246-
self.displayUploadError('No valid area found in provided input.');
248+
self.displayUploadError(i18next.t('loadNogos.error.no-valid-area'));
247249
return false;
248250
}
249251

@@ -255,6 +257,7 @@ BR.NogoAreas = L.Control.extend({
255257
}
256258
},
257259
});
260+
console.log('lol');
258261
var nogosPoints = geoJSON.getLayers().filter(function (e) {
259262
return e.feature.geometry.type === 'Point';
260263
});
@@ -268,18 +271,26 @@ BR.NogoAreas = L.Control.extend({
268271
nogosPoints = nogosPoints.filter(function (e) {
269272
return e;
270273
});
271-
self.setOptions({
272-
nogos: nogosPoints,
273-
polygons: geoJSON.getLayers().filter(function (e) {
274-
return e.feature.geometry.type === 'Polygon';
275-
}),
276-
polylines: geoJSON.getLayers().filter(function (e) {
277-
return e.feature.geometry.type === 'LineString';
278-
}),
279-
});
280-
self._fireUpdate();
281-
self.displayUploadError(undefined);
282-
$('#loadNogos').modal('hide');
274+
try {
275+
self.setOptions({
276+
nogos: nogosPoints,
277+
polygons: geoJSON.getLayers().filter(function (e) {
278+
return e.feature.geometry.type === 'Polygon';
279+
}),
280+
polylines: geoJSON.getLayers().filter(function (e) {
281+
return e.feature.geometry.type === 'LineString';
282+
}),
283+
});
284+
self._fireUpdate();
285+
self.displayUploadError(undefined);
286+
$('#loadNogos').modal('hide');
287+
} catch (err) {
288+
if (err.name === 'NS_ERROR_MALFORMED_URI') {
289+
self.displayUploadError(i18next.t('loadNogos.error.loading-file-too-big'));
290+
} else {
291+
self.displayUploadError(i18next.t('loadNogos.error.loading-file-unexpected'));
292+
}
293+
}
283294
});
284295
return false;
285296
},

locales/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
},
8585
"loadNogos": {
8686
"defaultProperties": "Default properties",
87+
"error": {
88+
"invalid-default-nogo-radius": "Invalid default nogo radius.",
89+
"invalid-nogo-buffering-radius": "Invalid nogo buffering radius.",
90+
"loading-file-error": "Could not load file: {{err}}.",
91+
"loading-file-too-big": "Too many nogo areas in this file! Please simplify the geometry and/or reduce the number of zones.",
92+
"loading-file-unexpected": "Unexpected error when loading this file.",
93+
"missing-default-nogo-weight": "Missing default nogo weight.",
94+
"missing-file-url": "Missing file or URL.",
95+
"no-valid-area": "No valid area found in provided input."
96+
},
8797
"file": "File (.geojson)",
8898
"load": "Load",
8999
"nogoBuffer": "Buffer no-go areas (in meters)",

0 commit comments

Comments
 (0)