From 61ddb9fe322c496b94665c80ad5d830755e7c9ba Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 14 Feb 2020 10:44:39 +0100 Subject: [PATCH] Bug 24662: Remove global variables MSG_* from datatables.inc Now that bug 21156 is pushed, we don't need to have global variables in .inc or .tt files for translation in .js file. We can simply declare our translatable strings where they are used. This patch removes all global variables used in DataTables configuration Test plan: 1. cd misc/translator && ./translate update fr-FR 2. Translate strings in misc/tranlator/po/fr-FR-messages-js.po 3. cd misc/translator && ./translate install fr-FR 4. Go to the staff interface, in english, and check that DataTables tables are still working. You should check at least the following pages: - catalogue/detail.pl - circ/circulation.pl - tools/quotes.pl - tools/letter.pl 5. Switch to french and check again DataTables tables, and verify that strings are translated This patch depends on bug 24661 Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Martin Renvoize --- .../prog/en/includes/datatables.inc | 24 ---------- .../prog/en/modules/circ/circulation.tt | 1 - .../prog/en/modules/tools/quotes.tt | 18 +------- koha-tmpl/intranet-tmpl/prog/js/checkouts.js | 5 +- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 46 +++++++++---------- koha-tmpl/intranet-tmpl/prog/js/letter.js | 4 +- .../intranet-tmpl/prog/js/table_filters.js | 4 +- 7 files changed, 31 insertions(+), 71 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc index cf0043e545..a545868ce7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc @@ -2,28 +2,4 @@ [% USE Asset %] [% INCLUDE 'format_price.inc' %] [% Asset.js("lib/datatables/datatables.min.js") | $raw %] - [% Asset.js("js/datatables.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 718ad01ee5..568eb5944a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -1030,7 +1030,6 @@ var ClaimReturnedLostValue = "[% Koha.Preference('ClaimReturnedLostValue') | html %]"; var ClaimReturnedChargeFee = "[% Koha.Preference('ClaimReturnedChargeFee') | html %]"; var ClaimReturnedWarningThreshold = "[% Koha.Preference('ClaimReturnedWarningThreshold') | html %]"; - var MSG_DT_LOADING_RECORDS = _("Loading... you may continue scanning."); var interface = "[% interface | html %]"; var theme = "[% theme | html %]"; var borrowernumber = "[% patron.borrowernumber | html %]"; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt index 6191b02037..bf910d229c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt @@ -90,23 +90,7 @@ { "sWidth": "75%" }, { "sWidth": "11%" }, ], - "oLanguage" : { - "oPaginate": { - "sFirst": MSG_DT_FIRST, - "sLast": MSG_DT_LAST, - "sNext": MSG_DT_NEXT, - "sPrevious": MSG_DT_PREVIOUS, - }, - "sEmptyTable": MSG_DT_EMPTY_TABLE, - "sInfo": MSG_DT_INFO, - "sInfoEmpty": MSG_DT_INFO_EMPTY, - "sInfoFiltered": MSG_DT_INFO_FILTERED, - "sLengthMenu": MSG_DT_LENGTH_MENU, - "sLoadingRecords": MSG_DT_LOADING_RECORDS, - "sProcessing": MSG_DT_PROCESSING, - "sSearch": MSG_DT_SEARCH, - "sZeroRecords": MSG_DT_ZERO_RECORDS, - }, + "oLanguage": dataTablesDefaults.oLanguage, "fnPreDrawCallback": function(oSettings) { return true; }, diff --git a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js index 169bdc4e36..3900a151fc 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/checkouts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/checkouts.js @@ -233,10 +233,11 @@ $(document).ready(function() { $('#issues-table').show(); $('#issues-table-actions').show(); + var msg_loading = __('Loading... you may continue scanning.'); issuesTable = KohaTable("issues-table", { "oLanguage": { - "sEmptyTable" : MSG_DT_LOADING_RECORDS, - "sProcessing": MSG_DT_LOADING_RECORDS, + "sEmptyTable" : msg_loading, + "sProcessing": msg_loading, }, "bAutoWidth": false, "dom": 'B<"clearfix">rt', diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index a31db0614d..10845eb8db 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -1,6 +1,5 @@ // These default options are for translation but can be used // for any other datatables settings -// MSG_DT_* variables comes from datatables.inc // To use it, write: // $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, { // // other settings @@ -8,26 +7,26 @@ var dataTablesDefaults = { "oLanguage": { "oPaginate": { - "sFirst" : window.MSG_DT_FIRST || "First", - "sLast" : window.MSG_DT_LAST || "Last", - "sNext" : window.MSG_DT_NEXT || "Next", - "sPrevious" : window.MSG_DT_PREVIOUS || "Previous" + "sFirst" : __('First'), + "sLast" : __('Last'), + "sNext" : __('Next'), + "sPrevious" : __('Previous'), }, - "sEmptyTable" : window.MSG_DT_EMPTY_TABLE || "No data available in table", - "sInfo" : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries", - "sInfoEmpty" : window.MSG_DT_INFO_EMPTY || "No entries to show", - "sInfoFiltered" : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)", - "sLengthMenu" : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries", - "sLoadingRecords" : window.MSG_DT_LOADING_RECORDS || "Loading...", - "sProcessing" : window.MSG_DT_PROCESSING || "Processing...", - "sSearch" : window.MSG_DT_SEARCH || "Search:", - "sZeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found", + "sEmptyTable" : __('No data available in table'), + "sInfo" : __('Showing _START_ to _END_ of _TOTAL_ entries'), + "sInfoEmpty" : __('No entries to show'), + "sInfoFiltered" : __('(filtered from _MAX_ total entries)'), + "sLengthMenu" : __('Show _MENU_ entries'), + "sLoadingRecords" : __('Loading...'), + "sProcessing" : __('Processing...'), + "sSearch" : __('Search:'), + "sZeroRecords" : __('No matching records found'), buttons: { - "copyTitle" : window.MSG_DT_COPY_TITLE || "Copy to clipboard", - "copyKeys" : window.MSG_DT_COPY_KEYS || "Press ctrl or + C to copy the table data
to your system clipboard.

To cancel, click this message or press escape.", + "copyTitle" : __('Copy to clipboard'), + "copyKeys" : __('Press ctrl or + C to copy the table data
to your system clipboard.

To cancel, click this message or press escape.'), "copySuccess": { - _: window.MSG_DT_COPY_SUCCESS_X || "Copied %d rows to clipboard", - 1: window.MSG_DT_COPY_SUCCESS_ONE || "Copied one row to clipboard" + _: __('Copied %d rows to clipboard'), + 1: __('Copied one row to clipboard'), } } }, @@ -35,9 +34,9 @@ var dataTablesDefaults = { "buttons": [{ fade: 100, className: "dt_button_clear_filter", - titleAttr: MSG_CLEAR_FILTER, + titleAttr: __('Clear filter'), enabled: false, - text: ' ' + MSG_CLEAR_FILTER + '', + text: ' ' + __('Clear filter') + '', available: function ( dt ) { // The "clear filter" button is made available if this test returns true if( dt.settings()[0].aanFeatures.f ){ // aanFeatures.f is null if there is no search form @@ -49,7 +48,7 @@ var dataTablesDefaults = { node.addClass("disabled"); } }], - "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]], + "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, __('All')]], "iDisplayLength": 20, initComplete: function( settings) { var tableId = settings.nTable.id @@ -356,8 +355,9 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { * from a configuration file (in English, "a," "an," and "the") */ - if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){ - var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" "); + var config_exclude_articles_from_sort = __('a an the'); + if (config_exclude_articles_from_sort){ + var articles = config_exclude_articles_from_sort.split(" "); var rpattern = ""; for(i=0;i\"\" "+ MSG_DT_LOADING_RECORDS +""; +var modal_loading = "
\"\" "+ __('Loading...') +"
"; var editing = 0; if( add_form == 1 && code !== '' ){ diff --git a/koha-tmpl/intranet-tmpl/prog/js/table_filters.js b/koha-tmpl/intranet-tmpl/prog/js/table_filters.js index d7c4dc8988..85519b0c70 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/table_filters.js +++ b/koha-tmpl/intranet-tmpl/prog/js/table_filters.js @@ -23,7 +23,7 @@ function activate_filters(id) { } $('#' + id + '_activate_filters') - .html(' ' + MSG_DEACTIVATE_FILTERS ) + .html(' ' + __('Deactivate filters') ) .unbind('click') .click(function() { deactivate_filters(id); @@ -41,7 +41,7 @@ function deactivate_filters(id) { filters_row.hide(); $('#' + id + '_activate_filters') - .html(' ' + MSG_ACTIVATE_FILTERS ) + .html(' ' + __('Activate filters') ) .unbind('click') .click(function() { activate_filters(id); -- 2.20.1