Fix #299 -- Make javascript's gettext calls failsafe

This commit is contained in:
Raphael Michel
2016-11-08 17:14:14 +01:00
parent 37598ed914
commit 61df0962f0
3 changed files with 21 additions and 8 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
/*global $, waitingDialog, gettext */
/*global $, waitingDialog, failsafe_gettext */
var async_task_id = null;
var async_task_timeout = null;
var async_task_check_url = null;
@@ -46,7 +46,7 @@ function async_task_error(jqXHR, textStatus, errorThrown) {
if (c.length > 0) {
ajaxErrDialog.show(c.first().html());
} else {
alert(gettext('Unknown error.'));
alert(failsafe_gettext('Unknown error.'));
}
}
@@ -58,7 +58,7 @@ $(function () {
return;
}
$(this).data('ajaxing', true);
waitingDialog.show(gettext('We are processing your request …'));
waitingDialog.show(failsafe_gettext('We are processing your request …'));
$.ajax(
{
+3 -3
View File
@@ -1,4 +1,4 @@
/*global $,django */
/*global $,failsafe_gettext,failsafe_ngettext */
var cart = {
_deadline: null,
@@ -7,10 +7,10 @@ var cart = {
draw_deadline: function () {
var diff = Math.floor(cart._deadline.diff(moment()) / 1000 / 60);
if (diff < 0) {
$("#cart-deadline").text(django.gettext("The items in your cart are no longer reserved for you."));
$("#cart-deadline").text(failsafe_gettext("The items in your cart are no longer reserved for you."));
window.clearInterval(cart._deadline_interval);
} else {
$("#cart-deadline").text(django.ngettext(
$("#cart-deadline").text(failsafe_ngettext(
"The items in your cart are reserved for you for one minute.",
"The items in your cart are reserved for you for {num} minutes.",
diff
+15 -2
View File
@@ -1,5 +1,18 @@
/*global $ */
function failsafe_gettext(msgid) {
if (typeof django !== 'undefined' && typeof django.gettext !== 'undefined') {
return django.gettext(msgid);
}
return msgid;
}
function failsafe_ngettext(singular, plural, count) {
if (typeof django !== 'undefined' && typeof django.ngettext !== 'undefined') {
return django.ngettext(singular, plural, count);
}
return plural;
}
$(function () {
"use strict";
$("input[data-toggle=radiocollapse]").change(function () {
@@ -41,11 +54,11 @@ var ajaxErrDialog = {
"use strict";
$("#ajaxerr").html(c);
$("#ajaxerr .links").html("<a class='btn btn-default ajaxerr-close'>"
+ gettext("Close message") + "</a>");
+ failsafe_gettext("Close message") + "</a>");
$("body").addClass("ajaxerr");
},
hide: function () {
"use strict";
$("body").removeClass("ajaxerr");
}
};
};