Bug 26244: Move translatable strings out of memberentrygen.tt and into JavaScript
authorOwen Leonard <oleonard@myacpl.org>
Wed, 19 Aug 2020 00:48:54 +0000 (00:48 +0000)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 12 Apr 2022 09:40:17 +0000 (11:40 +0200)
This patch removes the definition of translatable strings out of
templates and into the corresponding JavaScript file, using the new JS
i81n function.

Note: I was unable to trigger the confirmation message in the
check_form_borrowers function. I think the form is now structured in a
way that it is never triggered, thus a candidate for removal.

To test:

- Apply the patch and go to Patrons.
- Add or edit a patron.
- Select a date of birth at least one month in the past and confirm that
  the patron's age is displayed in the hint below.
- Test multiple variations to confirm that the singular and plural of
  'year' and 'month' display correctly. (e.g. 1 year 9 months, 2 years,
  etc).
- Set some patron messaging preferences for the patron.
- Change the patron category.
- You should get a confirmation: "Change messaging preferences to
  default for this category?"

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/members.js for translation, e.g.:

  msgid "%s years"
  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 strings should
  appear.

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/js/members.js
koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js

index 0185c6c..9f64400 100644 (file)
@@ -1774,24 +1774,6 @@ legend:hover {
             });
         });
 
-        var MSG_SEPARATOR = _("Separator must be / in field %s");
-        var MSG_INCORRECT_DAY = _("Invalid day entered in field %s");
-        var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s");
-        var MSG_INCORRECT_YEAR = _("Invalid year entered in field %s");
-        var MSG_DUPLICATE_PATRON = _("Warning: Duplicate patron");
-        var MSG_DUPLICATE_ORGANIZATION = _("Warning: Duplicate organization");
-        var MSG_LATE_EXPIRY = _("Warning: Expiration date falls before enrollment date");
-        var MSG_DUPLICATE_SUSPICION = _("Please confirm whether this is a duplicate patron");
-        var MSG_MONTH = _("%s month")
-        var MSG_MONTHS = _("%s months")
-        var MSG_YEAR = _("%s year")
-        var MSG_YEARS = _("%s years")
-        var LABEL_CHANGE = _("Change");
-        var LABEL_SET_TO_PATRON = _("Set to patron");
-        var LABEL_AGE = _("Age");
-        var MSG_MESSAGING_DFEAULTS = _("Change messaging preferences to default for this category?");
-        var MSG_PASSWORD_LENGTH = _("Minimum password length: %s");
-
         [% IF quickadd && opadd  && !check_member %]
             $(document).ready(function () {
 
index 946af76..7a9f844 100644 (file)
@@ -17,7 +17,7 @@ function check_form_borrowers(nav){
     //patrons form to test if you checked no to the question of double
     if (statut!=1 && document.form.check_member.value > 0 ) {
         if (!(document.form.answernodouble.checked)){
-            message_champ+= MSG_DUPLICATE_SUSPICION;
+            message_champ += __("Please confirm whether this is a duplicate patron");
             statut=1;
             document.form.nodouble.value=0;
         } else {
@@ -72,7 +72,7 @@ function update_category_code(category_code) {
     //Change password length hint
     var hint = $("#password").siblings(".hint").first();
     var min_length = $('select'+category_selector+' option:selected').data('pwdLength');
-    var hint_string = MSG_PASSWORD_LENGTH.format(min_length);
+    var hint_string = __("Minimum password length: %s").format(min_length);
     hint.html(hint_string);
 }
 
@@ -159,16 +159,16 @@ function write_age() {
 
     var age_string;
     if (age.year || age.month) {
-        age_string = LABEL_AGE + ": ";
+        age_string = __("Age") + ": ";
     }
 
     if (age.year) {
-        age_string += age.year > 1 ? MSG_YEARS.format(age.year) : MSG_YEAR.format(age.year);
+        age_string += age.year > 1 ? __("%s years").format(age.year) : __("%s year").format(age.year);
         age_string += " ";
     }
 
     if (age.month) {
-        age_string += age.month > 1 ? MSG_MONTHS.format(age.month) : MSG_MONTH.format(age.month);
+        age_string += age.month > 1 ? __("%s months").format(age.month) : __("%s month").format(age.month);
     }
 
     hint.html(age_string);
index 489d69d..9fc1eb0 100644 (file)
@@ -17,7 +17,7 @@ $(document).ready(function(){
             messaging_prefs_loading.show();
             var categorycode = $(this).val();
             if (message_prefs_dirty) {
-                if (!confirm( MSG_MESSAGING_DFEAULTS )) {
+                if (!confirm( __("Change messaging preferences to default for this category?") )) {
                     // Not loading messaging defaults. Hide loading indicator
                     messaging_prefs_loading.hide();
                     return;