Koha/koha-tmpl/intranet-tmpl/prog/js/calendar.js
Jérémy Breuillard 6498c5835c Bug 22490: Some strings in JavaScript files are untranslatable
Javascript function `_` works only if used in template file (.tt or
.inc).
In .js files we should use `__`

This patch updates .js files to use `__` instead of `_`

Test Plan:
1. Do not apply the patch yet
2. Run `npx gulp po:update --lang fr-FR` (choose another language
   if you prefer)
3. Open misc/translator/po/fr-FR-messages-js.po and search "Please
   select a CSV (.csv) or ODS (.ods) spreadsheet file"
4. Notice that the references above only mention biblio_framework.js
5. If not already translated, translate it
6. Run misc/translator/translate install fr-FR
7. Go to staff interface and change language to fr-FR
8. Go to Administration » Authority types and click on "Actions ->
   Import"
9. In the modal window, click on "Import" without selecting a file. You
   should see an alert with the non-translated text
10. Apply the patch
11. Run `npx gulp po:update --lang fr-FR`
12. Open misc/translator/po/fr-FR-messages-js.po and search "Please
    select a CSV (.csv) or ODS (.ods) spreadsheet file"
13. Notice that the references above now also mention authtype.js
14. If the translation is marked as fuzzy, remove the fuzzy flag
15. Run misc/translator/translate install fr-FR
16. Go to staff interface again
17. Go to Administration » Authority types and click on "Actions ->
    Import"
18. In the modal window, click on "Import" without selecting a file. You
    should see an alert, this time with the translated text

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-02-24 16:41:31 -03:00

145 lines
4.8 KiB
JavaScript

/* global debug sentmsg __ dateformat_pref flatpickr_dateformat_string bidi calendarFirstDayOfWeek */
/* exported DateTime_from_syspref flatpickr_weekdays flatpickr_months */
var MSG_PLEASE_ENTER_A_VALID_DATE = ( __("Please enter a valid date (should match %s).") );
if (debug > 1) {
alert("dateformat: " + dateformat_pref + "\ndebug is on (level " + debug + ")");
}
function is_valid_date(date) {
// An empty string is considered as a valid date for convenient reasons.
if (date === '') return 1;
var dateformat = flatpickr_dateformat_string;
if (dateformat == 'us') {
if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
dateformat = 'm/d/Y';
} else if (dateformat == 'metric') {
if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
dateformat = 'd/m/Y';
} else if (dateformat == 'iso') {
if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0;
dateformat = 'Y-m-d';
} else if (dateformat == 'dmydot') {
if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0;
dateformat = 'd.m.Y';
}
try {
flatpickr.parseDate(date, dateformat);
} catch (e) {
return 0;
}
return 1;
}
function get_dateformat_str(dateformat) {
var dateformat_str;
if (dateformat == 'us') {
dateformat_str = 'mm/dd/yyyy';
} else if (dateformat == 'metric') {
dateformat_str = 'dd/mm/yyyy';
} else if (dateformat == 'iso') {
dateformat_str = 'yyyy-mm-dd';
} else if (dateformat == 'dmydot') {
dateformat_str = 'dd.mm.yyyy';
}
return dateformat_str;
}
function validate_date(dateText, inst) {
if (!is_valid_date(dateText)) {
var dateformat_str = get_dateformat_str( dateformat_pref );
alert(MSG_PLEASE_ENTER_A_VALID_DATE.format(dateformat_str));
inst.clear();
}
}
function Date_from_syspref(dstring) {
var dateX = dstring.split(/[-/.]/);
if (debug > 1 && sentmsg < 1) {
sentmsg++;
alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));
}
if (dateformat_pref === "iso") {
return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
} else if (dateformat_pref === "us") {
return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
} else if (dateformat_pref === "metric") {
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
} else if (dateformat_pref === "dmydot") {
return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d)
} else {
if (debug > 0) {
alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
}
return 0;
}
}
function DateTime_from_syspref(date_time) {
var parts = date_time.split(" ");
var date = parts[0];
var time = parts[1];
parts = time.split(":");
var hour = parts[0];
var minute = parts[1];
if (hour < 0 || hour > 23) {
return 0;
}
if (minute < 0 || minute > 59) {
return 0;
}
var datetime = Date_from_syspref(date);
if (isNaN(datetime.getTime())) {
return 0;
}
datetime.setHours(hour);
datetime.setMinutes(minute);
return datetime;
}
/* jQuery Validator plugin custom method
This allows you to check that a given date falls after another.
It is required that a message be defined.
Syntax:
$("#form_id").validate({
rules: {
input_name_of_later_date_field: {
is_date_after: "#input_id_of_earlier_date_field"
},
},
messages: {
input_name_of_later_date_field: {
is_date_after: __("Validation error to be shown, i.e. End date must come after start date")
}
}
});
*/
jQuery.validator.addMethod("is_date_after",
function (value, element, params) {
var from = Date_from_syspref($(params).val());
var to = Date_from_syspref(value);
return to > from;
});
jQuery.validator.addMethod("date_on_or_after",
function (value, element, params) {
var from = Date_from_syspref($(params).val());
var to = Date_from_syspref(value);
return to >= from;
});
var flatpickr_weekdays = {
shorthand: [ __("Sun"), __("Mon"), __("Tue"), __("Wed"), __("Thu"), __("Fri"), __("Sat")],
longhand: [ __("Sunday"), __("Monday"), __("Tuesday"), __("Wednesday"), __("Thursday"), __("Friday"), __("Saturday") ]
};
var flatpickr_months = {
shorthand: [ __("Jan"), __("Feb"), __("Mar"), __("Apr"), __("May"), __("Jun"), __("Jul"), __("Aug"), __("Sep"), __("Oct"), __("Nov"), __("Dec")],
longhand: [ __("January"), __("February"), __("March"), __("April"), __("May"), __("June"), __("July"), __("August"), __("September"), __("October"), __("November"), __("December")]
};