From 5b1318f3d12f21cb4e4739fbac1cd8bb8d43a873 Mon Sep 17 00:00:00 2001 From: jeremy breuillard Date: Mon, 25 Apr 2022 15:03:32 +0200 Subject: [PATCH] Bug 22490: Some strings in JavaScript files are untranslatable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- koha-tmpl/intranet-tmpl/prog/js/authtype.js | 8 ++++---- .../intranet-tmpl/prog/js/background-job-progressbar.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/calendar.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/letter.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/pages/results.js | 6 +++--- koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js | 8 ++++---- koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/resolve_claim_modal.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js | 2 +- koha-tmpl/intranet-tmpl/prog/js/xmlControlfield.js | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/authtype.js b/koha-tmpl/intranet-tmpl/prog/js/authtype.js index f1ce1c87f2a..9032dfbd8fa 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/authtype.js +++ b/koha-tmpl/intranet-tmpl/prog/js/authtype.js @@ -41,7 +41,7 @@ $(document).ready(function() { var filename = $(this).val(); if ( ! /(?:\.csv|\.ods)$/.test(filename)) { $(this).css("background-color","yellow"); - alert(_("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.")); + alert(__("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.")); $(this).val(""); $(this).css("background-color","white"); } @@ -56,9 +56,9 @@ $(document).ready(function() { var id = $(this).attr('id'); var obj = $('#' + id + ' input:file'); if (/(?:\.csv|\.ods)$/.test(obj.val())) { - if (confirm(_("Do you really want to import the authority type fields and subfields? This will overwrite the current configuration. For safety reasons please use the export option to make a backup"))) { + if (confirm(__("Do you really want to import the authority type fields and subfields? This will overwrite the current configuration. For safety reasons please use the export option to make a backup"))) { var authtypecode = $('#' + id + ' input:hidden[name=authtypecode]').val(); - $('#importing_' + authtypecode).find("span").html(_("Importing to authority type: %s. Importing from file: %s").format("" + authtypecode + "", "" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "")); + $('#importing_' + authtypecode).find("span").html(__("Importing to authority type: %s. Importing from file: %s").format("" + authtypecode + "", "" + obj.val().replace(new RegExp("^.+[/\\\\]"),"") + "")); if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) { var timestamp = new Date().getTime(); $('#importing_' + authtypecode).find("img").attr('src', '[% interface | html %]/[% theme | html %]/img/loading-small.gif' + '?' +timestamp); @@ -73,7 +73,7 @@ $(document).ready(function() { } } obj.css("background-color","yellow"); - alert(_("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.")); + alert(__("Please select a CSV (.csv) or ODS (.ods) spreadsheet file.")); obj.val(""); bj.css("background-color","white"); return false; diff --git a/koha-tmpl/intranet-tmpl/prog/js/background-job-progressbar.js b/koha-tmpl/intranet-tmpl/prog/js/background-job-progressbar.js index 5ddb4053c22..52ee7380e4a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/background-job-progressbar.js +++ b/koha-tmpl/intranet-tmpl/prog/js/background-job-progressbar.js @@ -69,7 +69,7 @@ function submitBackgroundJob(f) { backgroundJobProgressTimer = setInterval("updateJobProgress()", 500); }, error: function(xml, textStatus) { - humanMsg.displayMsg( '

' + _('Import of record(s) failed: ') + textStatus + '


'+xml.responseText, { className: 'humanError' } ); + humanMsg.displayMsg( '

' + __('Import of record(s) failed: ') + textStatus + '


'+xml.responseText, { className: 'humanError' } ); } }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/calendar.js b/koha-tmpl/intranet-tmpl/prog/js/calendar.js index 81561cc42d2..24a86e5bcde 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/calendar.js +++ b/koha-tmpl/intranet-tmpl/prog/js/calendar.js @@ -114,7 +114,7 @@ function DateTime_from_syspref(date_time) { }, messages: { input_name_of_later_date_field: { - is_date_after: _("Validation error to be shown, i.e. End date must come after start date") + is_date_after: __("Validation error to be shown, i.e. End date must come after start date") } } }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 2e922c64a63..9d72cf37308 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -875,7 +875,7 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { if ( existing_search ) { $(this).html( ''.format(existing_search) ); } else { - var search_title = _("%s search").format(title); + var search_title = __("%s search").format(title); $(this).html( ''.format(search_title) ); } } diff --git a/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js b/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js index 33d6c25058a..92c98f3027d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js +++ b/koha-tmpl/intranet-tmpl/prog/js/item_search_fields.js @@ -2,7 +2,7 @@ jQuery.validator.addMethod("marcfield", function(value, element) { return this.optional(element) || /^[0-9a-zA-Z]+$/.test(value); -}, _("Please enter letters or numbers") ); +}, __("Please enter letters or numbers") ); $(document).ready(function(){ $("#add_field_form").hide(); diff --git a/koha-tmpl/intranet-tmpl/prog/js/letter.js b/koha-tmpl/intranet-tmpl/prog/js/letter.js index d755dde6261..fd03c0dc431 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/letter.js +++ b/koha-tmpl/intranet-tmpl/prog/js/letter.js @@ -147,7 +147,7 @@ $(document).ready(function() { $(".content_sms").on("keyup", function(){ var length = $(this).val().length; var sms_counter = ("#sms_counter_" + $(this).data('lang')); - $(sms_counter).html(length + "/" + sms_limit + _(" characters")); + $(sms_counter).html(length + "/" + sms_limit + __(" characters")); if ( length > sms_limit ) { $(sms_counter).css("color", "red"); } else { diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js index ee8bc83d246..2e381c22608 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/results.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/results.js @@ -54,11 +54,11 @@ function verify_cover_images() { if( div.hasClass("coce-coverimg") ){ /* Identify which service's image is being loaded by IntranetCoce system pref */ if( $(img).attr("src").indexOf('amazon.com') >= 0 ){ - div.find(".hint").html(_("Coce image from Amazon.com")); + div.find(".hint").html(__("Coce image from Amazon.com")); } else if( $(img).attr("src").indexOf('google.com') >= 0 ){ - div.find(".hint").html(_("Coce image from Google Books")); + div.find(".hint").html(__("Coce image from Google Books")); } else if( $(img).attr("src").indexOf('openlibrary.org') >= 0 ){ - div.find(".hint").html(_("Coce image from Open Library")); + div.find(".hint").html(__("Coce image from Open Library")); } else { blanks.push( coverId ); div.remove(); diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js b/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js index d2917689799..4de6dc9f3e6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js +++ b/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js @@ -32,13 +32,13 @@ function count_reject () { } var success_approve = function(tag){ - // window.alert(_("AJAX approved tag: ") + tag); + // window.alert(__("AJAX approved tag: ") + tag); }; var failure_approve = function(tag){ window.alert( __("AJAX failed to approve tag: %s").format(decodeURIComponent(tag)) ); }; var success_reject = function(tag){ - // window.alert(_("AJAX rejected tag: ") + tag); + // window.alert(__("AJAX rejected tag: ") + tag); }; var failure_reject = function(tag){ window.alert( __("AJAX failed to reject tag: %s").format(decodeURIComponent(tag)) ); @@ -55,7 +55,7 @@ var indeterminate_test = function(tag){ var success_test_call = function() { $('#test_button').prop('disabled', false); - $('#test_button').html("" +_(" Test")); + $('#test_button').html("" +__(" Test")); }; $(document).ready(function() { @@ -100,7 +100,7 @@ $(document).ready(function() { pull_counts(); var getelement; var gettitle; - // window.alert(_("Click detected on ") + event.target + ": " + $(event.target).html); + // window.alert(__("Click detected on ") + event.target + ": " + $(event.target).html); if ($(event.target).is('.ok')) { $.ajax(Object.assign({}, review_ajax_params, { data: { diff --git a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js index f4620896ced..49ff14f84b8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js +++ b/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js @@ -46,7 +46,7 @@ function patron_autocomplete(node, options) { }, error: function(e) { if ( e.state() != 'rejected' ) { - alert( _("An error occurred. Check the logs") ); + alert( __("An error occurred. Check the logs") ); } return response(); } diff --git a/koha-tmpl/intranet-tmpl/prog/js/resolve_claim_modal.js b/koha-tmpl/intranet-tmpl/prog/js/resolve_claim_modal.js index a60598db6c3..65c008b66fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/resolve_claim_modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/resolve_claim_modal.js @@ -5,7 +5,7 @@ $('body').on('click', '.return-claim-tools-resolve', function() { $('#claims-returned-resolved-modal-id').val(id); $("#new_lost_status").val(current_lost_status); let selected_option = $("#new_lost_status option:selected"); - $(selected_option).text(_("%s (current status)").format($(selected_option).text())); + $(selected_option).text(__("%s (current status)").format($(selected_option).text())); $('#claims-returned-resolved-modal').modal() }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js b/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js index e7869382bfb..91871a469ef 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js +++ b/koha-tmpl/intranet-tmpl/prog/js/rotating-collections.js @@ -5,7 +5,7 @@ $(document).ready(function(){ $(".confirmdelete").click(function(){ $(this).parents('tr').addClass("warn"); - if(confirm(_("Are you sure you want to delete this rotating collection?"))){ + if(confirm(__("Are you sure you want to delete this rotating collection?"))){ return true; } else { $(this).parents('tr').removeClass("warn"); diff --git a/koha-tmpl/intranet-tmpl/prog/js/xmlControlfield.js b/koha-tmpl/intranet-tmpl/prog/js/xmlControlfield.js index d995bda23f5..25acae56fa4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/xmlControlfield.js +++ b/koha-tmpl/intranet-tmpl/prog/js/xmlControlfield.js @@ -212,7 +212,7 @@ function changeH4Result(form, h4_result, tr_result, pos, value) }).responseXML; if (this.xmlDoc) this.renderTemplate(); $("*").ajaxError(function(evt, request, settings){ - alert(_("AJAX error: receiving data from %s").format(settings.url)); + alert(__("AJAX error: receiving data from %s").format(settings.url)); }); },//loadXmlValues -- 2.30.2