Bug 26065: Move translatable strings out of marc_modification_templates.tt and into...
authorOwen Leonard <oleonard@myacpl.org>
Sat, 25 Jul 2020 15:10:24 +0000 (15:10 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 18 Aug 2020 13:45:49 +0000 (15:45 +0200)
This patch removes the <script> block in the MARC modification
templates template in which strings are defined for translation
purposes.

Strings are now in place in the JavaScript file and wrapped in the new
__() function.

To test, apply the patch and clear your browser cache if necessary.

- Perform some actions which will trigger translated strings, for
  example:
  - Create a new template
  - Add an action to the template and then delete it.
    - The confirmation should appear correctly
  - Add an action. Select "Copy" as the operation and click "Add action"
    without filling in any fields.
    - You should see a message, "Both subfield values should be filled
      or empty"

TESTING TRANSLATABILITY

- Update a translation, e.g. fr-FR:

> cd misc/translator
> perl translate update fr-FR

- Open the corresponding .po file for JavaScript strings, e.g.
  misc/translator/po/fr-FR-messages-js.po
- Locate strings pulled from
  koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js for
  translation, e.g.:

  msgid "Both subfield values should be filled or empty."
  msgstr ""

- Edit the "msgstr" string however you want (it's just for testing).
- Install the updated translation:

> perl translate install fr-FR

- Switch to your newly translated language in the staff client and
  repeat the test plan above. The translated string should appear.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt
koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js

index 9098bda..f692b42 100644 (file)
 
 [% MACRO jsinclude BLOCK %]
     [% Asset.js("js/tools-menu.js") | $raw %]
+    [% Asset.js("js/marc_modification_templates.js") | $raw %]
     <script>
-        var MSG_MMT_SUBFIELDS_MATCH = _("Both subfield values should be filled or empty.");
-        var MSG_MMT_DESTINATION_REQUIRED = _("The destination should be filled.");
-        var MSG_MMT_CONTROL_FIELD_EMPTY = _("If the field is a control field, the subfield should be empty");
-        var MSG_MMT_CONTROL_FIELD = _("A control field cannot be used with a regular field.");
-        var MSG_MMT_SOURCE_SUBFIELD = _("The source subfield should be filled for update.");
-        var MSG_MMT_SOURCE_FIELD = _("The source field should be filled.");
-        var MSG_MMT_EVERY = _("Every");
-        var MSG_MMT_ALL = _("All");
-        var MSG_MMT_CONFIRM_DEL_TEMPLATE = _("Are you sure you wish to delete this template?");
-        var MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION = _("Are you sure you wish to delete this template action?");
-        var MSG_MMT_EDIT_ACTION = _("Edit action %s");
-        var MSG_MMT_UPDATE_ACTION = _("Update action");
-        var MSG_MMT_CONDITIONAL_FIELD_REQUIRED = _("The conditional field should be filled.");
-        var MSG_MMT_CONDITIONAL_COMPARISON_REQUIRED = _("The conditional comparison operator should be filled.");
-        var MSG_MMT_CONDITIONAL_VALUE_REQUIRED = _("The conditional value should be filled.");
-        var MSG_MMT_CONDITIONAL_VALUE_REGEX_REQUIRED = _("The conditional regular expression should be filled.");
         var mmtas = [% ActionsLoop.json | $raw %]
     </script>
-    [% Asset.js("js/marc_modification_templates.js") | $raw %]
 [% END %]
 
 [% INCLUDE 'intranet-bottom.inc' %]
index bde3803..4f33c33 100644 (file)
@@ -1,3 +1,4 @@
+/* global __ */
 $(document).ready(function() {
     window.modaction_legend_innerhtml = $("#modaction_legend").text();
     window.action_submit_value = $("#action_submit").val();
@@ -13,50 +14,50 @@ $(document).ready(function() {
         var action = $("#action").val();
         if ( action == 'move_field' || action == 'copy_field' || action == 'copy_and_replace_field') {
             if ( $("#from_subfield").val().length != $("#to_subfield").val().length ) {
-                alert( MSG_MMT_SUBFIELDS_MATCH );
+                alert( __("Both subfield values should be filled or empty.") );
                 return false;
             }
             if ( $("#to_field").val().length <= 0 ) {
-                alert( MSG_MMT_DESTINATION_REQUIRED );
+                alert( __("The destination should be filled.") );
                 return false;
             }
             if ( ( $("#to_field").val()   < 10 && $("#to_subfield").val().length   > 0 ) ||
-                 ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
-                 alert( MSG_MMT_CONTROL_FIELD_EMPTY );
-                 return false;
+                ( $("#from_field").val() < 10 && $("#from_subfield").val().length > 0 ) ) {
+                alert( __("If the field is a control field, the subfield should be empty") );
+                return false;
             }
             if ( ( $("#from_field").val() < 10 && $("#to_field").val()   >= 10 ) ||
                  ( $("#to_field").val()   < 10 && $("#from_field").val() >= 10 ) ) {
-                alert( MSG_MMT_CONTROL_FIELD );
+                alert( __("A control field cannot be used with a regular field.") );
                 return false;
-             }
+            }
         }
         if ( action == 'update_field' ) {
             if ( $("#from_subfield").val().length <= 0 ) {
-                alert( MSG_MMT_SOURCE_SUBFIELD );
+                alert( __("The source subfield should be filled for update.") );
                 return false;
             }
         }
         if ( $("#from_field").val().length <= 0 ) {
-            alert( MSG_MMT_SOURCE_FIELD );
+            alert( __("The source field should be filled.") );
             return false;
         }
         if ( $("#conditional").val() == 'if' || $("#conditional").val() == 'unless' ) {
             if ( $("#conditional_field").val() == '' ) {
-                alert( MSG_MMT_CONDITIONAL_FIELD_REQUIRED );
+                alert( __("The conditional field should be filled.") );
                 return false;
             }
             if ( $("#conditional_comparison").val() == '' ) {
-                alert( MSG_MMT_CONDITIONAL_COMPARISON_REQUIRED );
+                alert( __("The conditional comparison operator should be filled.") );
                 return false
             }
             if ( $("#conditional_value").val() == '' &&
                  ( $("#conditional_comparison").val() == 'equals' || $("#conditional_comparison").val() == 'not_equals' ) ) {
                 if ( document.getElementById('conditional_regex').checked == true ) {
-                    alert( MSG_MMT_CONDITIONAL_VALUE_REGEX_REQUIRED );
+                    alert( __("The conditional regular expression should be filled.") );
                     return false;
                 } else {
-                    alert( MSG_MMT_CONDITIONAL_VALUE_REQUIRED );
+                    alert( __("The conditional value should be filled.") );
                     return false;
                 }
             }
@@ -112,9 +113,9 @@ $(document).ready(function() {
 function updateAllEvery(){
     if ( $("#conditional_field").is(":visible") ) {
         if ( $("#conditional_field").val() == $("#from_field").val() && $("#from_field").val().length > 0 ) {
-            $("#field_number option[value='0']").html( MSG_MMT_EVERY );
+            $("#field_number option[value='0']").html( __("Every") );
         } else {
-            $("#field_number option[value='0']").html( MSG_MMT_ALL );
+            $("#field_number option[value='0']").html( __("All") );
         }
     }
 }
@@ -256,11 +257,11 @@ function clearFormElements(divId) {
 }
 
 function confirmDeleteAction() {
-    return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE_ACTION );
+    return confirm( __("Are you sure you wish to delete this template action?") );
 }
 
 function confirmDelete() {
-    return confirm( MSG_MMT_CONFIRM_DEL_TEMPLATE );
+    return confirm( __("Are you sure you wish to delete this template?") );
 }
 
 var modaction_legend_innerhtml;
@@ -306,10 +307,10 @@ function editAction( mmta ) {
     document.getElementById('description').value = mmta['description'];
 
     window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerHTML;
-    document.getElementById('modaction_legend').innerHTML = MSG_MMT_EDIT_ACTION.format(mmta['ordering']);
+    document.getElementById('modaction_legend').innerHTML = __("Edit action %s").format(mmta['ordering']);
 
     window.action_submit_value = document.getElementById('action_submit').value;
-    document.getElementById('action_submit').value = MSG_MMT_UPDATE_ACTION;
+    document.getElementById('action_submit').value = __("Update action");
 }
 
 function cancelEditAction() {