[OPEN-ILS-DEV] prototype staff client, feedback/4

steven schan at vcn.bc.ca
Thu Feb 6 15:00:50 EST 2014


The following code fragment is found in
templates/staff/circ/checking/index.tt2 of the prototype staff client.

I've properly indented it and applied a suggestion from Dan Wells (3 Feb 2014,
dev list).

<script>
// this could live in a .tt2 file instead -- if it gets large
angular.module('egCoreMod').factory('egCheckinStrings', function() {
     return {
         UNCAT_ALERT_DIALOG: '[% l('Copy "[_1]" was mis-scanned or is not cataloged', '{{copy_barcode}}') %]',
         COPY_ALERT_MSG_DIALOG_TITLE: '[% l('Copy Alert Message for [_1]', '{{copy_barcode}}') %]'
     };
});
</script>

The inline Javascript within a script tag defines an Angularjs module
containing the translation of a couple of text strings.  Each of the translated
text strings has a component that needs to be substituted with an expression
('copy_barcode') which will evaluate at run-time.  The module is intended to be
used by the Javascript run-time environment to replace English text to text
specific to the current locale setting.  An example of using the module in the
checkin controller is as follows.

egAlertDialog.open(egCheckinStrings.UNCAT_ALERT_DIALOG, args);

The egCheckinStrings module has been injected into the checkin controller.  If
an abnormal event has occurred that requires showing a message to the user, the
translation map will be used to access one of the relevant text.  .

Questions/observations:

   - How will the copy_barcode substitution work in the Javascript environment?
     Perhaps its due to my superficial knowledge of Angularjs, but I can't see
     how or when the subsitution can be properly done.

   - The translation map seems too tightly coupled to the controller code.  The
     text phrases are binding a particular expression to themselves.  If we want
     to change the name of the expression of an existing text, or if we want to
     bind the same phrase to another expression, user barcode instead of copy
     barcode, for example, then we would need to change the translation map.

   - I'm assuming the Perl environment is handling the esoteric l10n issues,
     such as date, time, currency formats, and so on, using Perl modules
     available on the server.  Do we want the Javascript environment to handle
     the same l10n issues for run-time values of these data types?  and if so,
     how will that be done? I can't see any way to do it except to download l10n
     rules from the server.

Suggestions to make the code pattern more readable:

   - Using the English phrase as the object key instead of another generic text
     string would make the code more readable.  If there is a component that
     needs substitution, use a facsimile that corresponds to the run-time
     expression.  (Use a short generic text string only if the English phrase is
     very long.)

     egAlertDialog.open(egCheckinStrings['Copy copy_barcode was mis-scanned or is not cataloged'], args);

   - Whenever the module is used, mapping the module name to a constant name like
     l10n instead of a unique name would also make the code more readable.

     egAlertDialog.open(l10n['Copy copy_barcode was mis-scanned or is not cataloged'], args);

   - Defining all the translation maps in a separate module, maybe egI18NMod,
     instead of egCoreMod, would help software maintenance, because the
     i18n/l10n issue is important enough to be assigned its own module.

The resultant inline Javascript with the above suggestions would look as follows.

<script>
angular.module('egi18nMod').factory('egCheckinStrings', function() {
     return {
         'Copy copy_barcode was mis-scanned or is not cataloged': '[% l('Copy "[_1]" was mis-scanned or is not cataloged', '{{copy_barcode}}') %]',
         'Copy Alert Message for copy_barcode': '[% l('Copy Alert Message for [_1]', '{{copy_barcode}}') %]'
     };
});
</script>

-- 
steven <steven.chan at bc.libraries.coop>
bc libraries co-op/sitka


More information about the Open-ils-dev mailing list