From 49c72649f340d74e8532730c3f45827a0e77ed62 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Thu, 18 Jun 2020 13:10:35 +0000 Subject: [PATCH] Bug 25351: Move cart-related strings out of opac-bottom.inc and into basket.js This patch adds the necessary JavaScript includes to the OPAC to enable translation of strings in JavaScript. It also updates the translation of cart-related strings by removing the strings from opac-bottom.inc and putting them in basket.js where they are used. To test, apply the patch and test that the correct strings are translatable. In this example I'm testing fr-FR: - Update a translation: > cd misc/translator > perl translate update fr-FR - Open the corresponding .po file for the strings pulled from JavaScript e.g. misc/translator/po/fr-FR-messages-js.po - Locate strings pulled from bootstrap/js/basket.js for translation, e.g.: #: koha-tmpl/opac-tmpl/bootstrap/js/basket.js:89 msgid "Your cart is currently empty" msgstr "" - Edit the "msgstr" string however you want (it's just for testing) - Install the updated translation: > perl translate install fr-FR In the OPAC, switch to the language you're testing. Confirm that your translated string appears. In the above example, by clicking the "Cart" icon in the header when there are no items in the cart. --- .../bootstrap/en/includes/doc-head-close.inc | 8 ++++ .../bootstrap/en/includes/opac-bottom.inc | 15 +------- koha-tmpl/opac-tmpl/bootstrap/js/basket.js | 44 +++++++++++----------- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc index ee84825445..f0fbd76eaa 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/doc-head-close.inc @@ -53,9 +53,17 @@ + +[% IF lang && lang != 'en' %] + [% Asset.js(lang _ '/js/locale_data.js') | $raw %] +[% END %] +[% Asset.js('js/Gettext.js') | $raw %] +[% Asset.js('js/i18n.js') | $raw %] + [% Asset.js("lib/modernizr.min.js") | $raw %] [% Asset.css("lib/font-awesome/css/font-awesome.min.css") | $raw %] [% PROCESS 'html_helpers.inc' %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc index a32e7a56ee..e0584809a7 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc @@ -149,20 +149,7 @@ $.widget.bridge('uitooltip', $.ui.tooltip); var MSG_CANCEL_HOLD = _("Cancel"); var MSG_CANCEL_HOLD_CONFIRM = _("Are you sure you want to cancel this hold?"); var MSG_ON_HOLD = _("On hold"); - [% IF Koha.Preference( 'opacbookbag' ) == 1 or Koha.Preference( 'virtualshelves' ) == 1 %] - var MSG_BASKET_EMPTY = _("Your cart is currently empty"); - var MSG_RECORD_IN_BASKET = _("The item is already in your cart"); - var MSG_RECORD_ADDED = _("The item has been added to your cart"); - var MSG_RECORD_REMOVED = _("The item has been removed from your cart"); - var MSG_NRECORDS_ADDED = _(" item(s) added to your cart"); - var MSG_NRECORDS_IN_BASKET = _("already in your cart"); - var MSG_NO_RECORD_SELECTED = _("No item was selected"); - var MSG_NO_RECORD_ADDED = _("No item was added to your cart"); - var MSG_CONFIRM_DEL_BASKET = _("Are you sure you want to empty your cart?"); - var MSG_CONFIRM_DEL_RECORDS = _("Are you sure you want to remove the selected items?"); - var MSG_ITEM_IN_CART = _("In your cart"); - var MSG_ITEM_NOT_IN_CART = _("Add to cart"); - [% END %] + [% IF ( Koha.Preference( 'opacuserlogin' ) == 1 ) && ( Koha.Preference( 'TagsEnabled' ) == 1 ) %] var MSG_TAGS_DISABLED = _("Sorry, tags are not enabled on this system."); var MSG_TAG_ALL_BAD = _("Error! Your tag was entirely markup code. It was NOT added. Please try again with plain text."); diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js index e5b3d3b4d0..4c45f2aee3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/basket.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/basket.js @@ -1,4 +1,4 @@ -/* global MSG_BASKET_EMPTY MSG_RECORD_IN_BASKET MSG_RECORD_ADDED MSG_NRECORDS_IN_BASKET MSG_NRECORDS_ADDED MSG_NO_RECORD_SELECTED MSG_NO_RECORD_ADDED MSG_RECORD_REMOVED MSG_CONFIRM_DEL_BASKET MSG_CONFIRM_DEL_RECORDS MSG_ITEM_IN_CART MSG_ITEM_NOT_IN_CART */ +/* global __ __p */ ////////////////////////////////////////////////////////////////////////////// // BASIC FUNCTIONS FOR COOKIE MANAGEMENT // @@ -86,7 +86,7 @@ function openBasket() { if (window.focus) {basket.focus()} } else { - showCartUpdate(MSG_BASKET_EMPTY); + showCartUpdate( __("Your cart is currently empty") ); } } @@ -115,7 +115,7 @@ function addRecord(val, selection,NoMsgAlert) { return 0; } if (! NoMsgAlert ) { - showCartUpdate(MSG_RECORD_IN_BASKET); + showCartUpdate( __p("Bibliographic record", "The item is already in your cart") ); } } else { @@ -132,7 +132,7 @@ function addRecord(val, selection,NoMsgAlert) { return 1; } if (! NoMsgAlert ) { - showCartUpdate(MSG_RECORD_ADDED); + showCartUpdate( __p("Bibliographic record", "The item has been added to your cart") ); updateLink(val,"add"); } @@ -189,18 +189,18 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t var msg = ""; if (nbAdd) { if (i > nbAdd) { - msg = nbAdd+" "+MSG_NRECORDS_ADDED+", "+(i-nbAdd)+" "+MSG_NRECORDS_IN_BASKET; + msg = nbAdd+" "+ __p("Bibliographic record", " item(s) added to your cart") +", "+(i-nbAdd)+" " + __("already in your cart"); } else { - msg = nbAdd+" "+MSG_NRECORDS_ADDED; + msg = nbAdd+" "+ __p("Bibliographic record", " item(s) added to your cart"); } } else { if (i < 1) { - msg = MSG_NO_RECORD_SELECTED; + msg = __p("Bibliographic record", "No item was selected"); } else { - msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !"; + msg = __p("Bibliographic record", "No item was added to your cart") + " (" + __("already in your cart") + ") !"; } } showCartUpdate(msg); @@ -241,7 +241,7 @@ function delSingleRecord(biblionumber){ writeCookie( nameCookie, valCookie ); updateBasket( arrayRecords.length-1 ); updateLink(biblionumber,"del"); - showCartUpdate(MSG_RECORD_REMOVED); + showCartUpdate( __p("Bibliographic record", "The item has been removed from your cart") ); } function delSelRecords() { @@ -268,7 +268,7 @@ function delSelRecords() { if (str2.length == 0) { // equivalent to emptying the basket var rep = false; - rep = confirm(MSG_CONFIRM_DEL_BASKET); + rep = confirm( __("Are you sure you want to empty your cart?") ); if (rep) { delCookie(nameCookie); document.location = "about:blank"; @@ -293,7 +293,7 @@ function delSelRecords() { document.location = "/cgi-bin/koha/opac-basket.pl?" + strCookie; } else { - alert(MSG_NO_RECORD_SELECTED); + alert( __p("Bibliographic record", "No item was selected") ); } } @@ -324,7 +324,7 @@ function delBasket() { var nameCookie = "bib_list"; var rep = false; - rep = confirm(MSG_CONFIRM_DEL_BASKET); + rep = confirm( __("Are you sure you want to empty your cart?") ); if (rep) { delCookie(nameCookie); updateAllLinks(top.opener); @@ -338,7 +338,7 @@ function delBasket() { function quit() { if (document.myform.records.value) { var rep = false; - rep = confirm(MSG_CONFIRM_DEL_RECORDS); + rep = confirm( __p("Bibliographic records", "Are you sure you want to remove the selected items?") ); if (rep) { delSelRecords(); } @@ -398,7 +398,7 @@ function holdSel() { parent.opener.document.location = "/cgi-bin/koha/opac-reserve.pl?biblionumbers=" + items; window.close(); } else { - alert(MSG_NO_RECORD_SELECTED); + alert( __p("Bibliographic record", "No item was selected") ); } } @@ -430,7 +430,7 @@ function addSelToShelf() { var loc = "/cgi-bin/koha/opac-addbybiblionumber.pl?biblionumber="+items; var shelf = open(loc, "shelf", optWin); } else { - alert(MSG_NO_RECORD_SELECTED); + alert( __p("Bibliographic record", "No item was selected") ); } } @@ -444,7 +444,7 @@ function vShelfAdd() { bibs.push("biblionumber=" + document.bookbag_form.biblionumber[i].value); } } - if (bibs.length == 0) { showListsUpdate(MSG_NO_RECORD_SELECTED); } + if (bibs.length == 0) { showListsUpdate( __p("Bibliographic record", "No item was selected") ); } return bibs.join("&"); } else { if (document.bookbag_form.biblionumber.checked) { @@ -476,18 +476,18 @@ function hideCart(){ function updateLink(val,op,target){ if(target){ if(op == "add"){ - target.$("a.cart"+val).html( " " + MSG_ITEM_IN_CART ).addClass("incart"); + target.$("a.cart"+val).html( " " + __("In your cart") ).addClass("incart"); target.$("a.cartR"+val).show(); } else { - target.$("a.cart"+val).html( " " + MSG_ITEM_NOT_IN_CART ).removeClass("incart").addClass("addtocart cart"+val); + target.$("a.cart"+val).html( " " + __("Add to cart") ).removeClass("incart").addClass("addtocart cart"+val); target.$("a.cartR"+val).hide(); } } else { if(op == "add"){ - $("a.cart"+val).html( " " + MSG_ITEM_IN_CART ).addClass("incart"); + $("a.cart"+val).html( " " + __("In your cart") ).addClass("incart"); $("a.cartR"+val).show(); } else { - $("a.cart"+val).html( " " + MSG_ITEM_NOT_IN_CART ).removeClass("incart").addClass("addtocart cart"+val); + $("a.cart"+val).html( " " + __("Add to cart") ).removeClass("incart").addClass("addtocart cart"+val); $("a.cartR"+val).hide(); } } @@ -495,10 +495,10 @@ function updateLink(val,op,target){ function updateAllLinks(target){ if(target){ - target.$("a.incart").html( " " + MSG_ITEM_NOT_IN_CART ).removeClass("incart").addClass("addtocart"); + target.$("a.incart").html( " " + __("Add to cart") ).removeClass("incart").addClass("addtocart"); target.$("a.cartRemove").hide(); } else { - $("a.incart").html( " " + MSG_ITEM_NOT_IN_CART ).removeClass("incart").addClass("addtocart"); + $("a.incart").html( " " + __("Add to cart") ).removeClass("incart").addClass("addtocart"); $("a.cartRemove").hide(); } } -- 2.11.0