Bug 24662: Remove global variables MSG_* from datatables.inc
authorJulian Maurice <julian.maurice@biblibre.com>
Fri, 14 Feb 2020 09:44:39 +0000 (10:44 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 11 Mar 2020 13:49:15 +0000 (13:49 +0000)
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 <bgkriegel@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/en/includes/datatables.inc
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt
koha-tmpl/intranet-tmpl/prog/js/checkouts.js
koha-tmpl/intranet-tmpl/prog/js/datatables.js
koha-tmpl/intranet-tmpl/prog/js/letter.js
koha-tmpl/intranet-tmpl/prog/js/table_filters.js

index cf0043e..a545868 100644 (file)
@@ -2,28 +2,4 @@
 [% USE Asset %]
 [% INCLUDE 'format_price.inc' %]
 [% Asset.js("lib/datatables/datatables.min.js") | $raw %]
-<script>
-    var MSG_DT_FIRST = _("First");
-    var MSG_DT_LAST = _("Last");
-    var MSG_DT_NEXT = _("Next");
-    var MSG_DT_PREVIOUS = _("Previous");
-    var MSG_DT_EMPTY_TABLE = _("No data available in table");
-    var MSG_DT_INFO = _("Showing _START_ to _END_ of _TOTAL_");
-    var MSG_DT_INFO_EMPTY = _("No entries to show");
-    var MSG_DT_INFO_FILTERED = _("(filtered from _MAX_ total entries)");
-    var MSG_DT_LENGTH_MENU = _("Show _MENU_ entries");
-    var MSG_DT_LOADING_RECORDS = _("Loading...");
-    var MSG_DT_PROCESSING = _("Processing...");
-    var MSG_DT_SEARCH = _("Search:");
-    var MSG_DT_ZERO_RECORDS = _("No matching records found");
-    var MSG_DT_ALL = _("All");
-    var CONFIG_EXCLUDE_ARTICLES_FROM_SORT = _("a an the");
-    var MSG_DT_COPY_TITLE = _("Copy to clipboard");
-    var MSG_DT_COPY_KEYS = _("Press ctrl or ⌘ + C to copy the table data<br>to your system clipboard.<br><br>To cancel, click this message or press escape.");
-    var MSG_DT_COPY_SUCCESS_ONE = _("Copied one row to clipboard");
-    var MSG_DT_COPY_SUCCESS_X = _("Copied %d rows to clipboard");
-    var MSG_CLEAR_FILTER = _("Clear filter");
-    var MSG_ACTIVATE_FILTERS = _("Activate filters");
-    var MSG_DEACTIVATE_FILTERS = _("Deactivate filters");
-</script>
 [% Asset.js("js/datatables.js") | $raw %]
index 718ad01..568eb59 100644 (file)
         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 %]";
index 6191b02..bf910d2 100644 (file)
                                         { "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;
                 },
index 169bdc4..3900a15 100644 (file)
@@ -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',
index a31db06..10845eb 100644 (file)
@@ -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 <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>To cancel, click this message or press escape.",
+            "copyTitle"     : __('Copy to clipboard'),
+            "copyKeys"      : __('Press <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>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: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + MSG_CLEAR_FILTER + '</span>',
+        text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __('Clear filter') + '</span>',
         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<articles.length;i++){
             rpattern += "^" + articles[i] + " ";
index f4824ab..7f4cb2e 100644 (file)
@@ -1,7 +1,7 @@
 /* Variables defined in letter.tt: */
-/* global _ module add_form copy_form no_op_set MSG_EMPTY_TITLE_AND_CONTENT MSG_EMPTY_TEMPLATES code MSG_CODE_EXISTS MSG_CODE_EXISTS_FOR_LIBRARY MSG_DT_LOADING_RECORDS MSG_NO_NOTICE_FOUND interface theme KohaTable columns_settings */
+/* global _ module add_form copy_form no_op_set MSG_EMPTY_TITLE_AND_CONTENT MSG_EMPTY_TEMPLATES code MSG_CODE_EXISTS MSG_CODE_EXISTS_FOR_LIBRARY MSG_NO_NOTICE_FOUND interface theme KohaTable columns_settings */
 
-var modal_loading = "<div id=\"loading\"><img src=\"" + interface + "/" + theme + "/img/spinner-small.gif\" alt=\"\" /> "+ MSG_DT_LOADING_RECORDS +"</div>";
+var modal_loading = "<div id=\"loading\"><img src=\"" + interface + "/" + theme + "/img/spinner-small.gif\" alt=\"\" /> "+ __('Loading...') +"</div>";
 
 var editing = 0;
 if( add_form == 1 && code !== '' ){
index d7c4dc8..85519b0 100644 (file)
@@ -23,7 +23,7 @@ function activate_filters(id) {
     }
 
     $('#' + id + '_activate_filters')
-        .html('<i class="fa fa-filter"></i> ' + MSG_DEACTIVATE_FILTERS )
+        .html('<i class="fa fa-filter"></i> ' + __('Deactivate filters') )
         .unbind('click')
         .click(function() {
             deactivate_filters(id);
@@ -41,7 +41,7 @@ function deactivate_filters(id) {
     filters_row.hide();
 
     $('#' + id + '_activate_filters')
-        .html('<i class="fa fa-filter"></i> ' + MSG_ACTIVATE_FILTERS )
+        .html('<i class="fa fa-filter"></i> ' + __('Activate filters') )
         .unbind('click')
         .click(function() {
             activate_filters(id);