[open-ils-commits] [GIT] Evergreen ILS branch master updated. 41dc920959cf4f793e993839b3108b5ae257773c

Evergreen Git git at git.evergreen-ils.org
Wed Sep 20 19:41:42 EDT 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  41dc920959cf4f793e993839b3108b5ae257773c (commit)
      from  d07e88235a50dfb7f7ddca8fc265cb94eac69891 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 41dc920959cf4f793e993839b3108b5ae257773c
Author: Mike Rylander <mrylander at gmail.com>
Date:   Wed Sep 20 10:47:01 2017 -0400

    LP#1717777: absorb all PO files for a locale
    
    We assumed only one file per locale, but apache <Location>s because are not
    independent WRT locale helpers in mod_perl, we need to load all files from
    all <Location> directives for a given locale.
    
    NOTE: there is a risk of translation collision, where the same key string in
    two PO files have different translations, but in our context that is almost
    surely a mistake.
    
    Signed-off-by: Mike Rylander <mrylander at gmail.com>
    Signed-off-by: Ben Shum <ben at evergreener.net>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
index adc3438..965c7ca 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm
@@ -220,8 +220,8 @@ sub load_context {
     my @template_paths = uniq $r->dir_config->get('OILSWebTemplatePath');
     $ctx->{template_paths} = [ reverse @template_paths ];
 
-    my %locales = $r->dir_config->get('OILSWebLocale');
-    load_locale_handlers($ctx, %locales);
+    my @locales = $r->dir_config->get('OILSWebLocale');
+    load_locale_handlers($ctx, @locales);
 
     $ctx->{locales} = \%registered_locales;
 
@@ -373,7 +373,13 @@ sub find_template {
 # Each module creates its own MakeText lexicon by parsing .po/.mo files
 sub load_locale_handlers {
     my $ctx = shift;
-    my %locales = @_;
+    my @raw = @_;
+    my %locales;
+    while (@raw) {
+        my ($l,$file) = (shift(@raw),shift(@raw)); 
+        $locales{$l} ||= [];
+        push @{$locales{$l}}, $file;
+    }
 
     my $editor = new_editor();
     my @locale_tags = sort { length($a) <=> length($b) } keys %locales;
@@ -384,7 +390,7 @@ sub load_locale_handlers {
     for my $idx (0..$#locale_tags) {
 
         my $tag = $locale_tags[$idx];
-        next if grep { $_ eq $tag } keys %registered_locales;
+        my $parent_tag = 'OpenILS::WWW::EGWeb::I18N';
 
         my $res = $editor->json_query({
             "from" => [
@@ -396,7 +402,6 @@ sub load_locale_handlers {
         my $locale_name = $res->[0]->{"name"} if exists $res->[0]->{"name"};
         next unless $locale_name;
 
-        my $parent_tag = '';
         my $sub_idx = $idx;
 
         # find the parent locale if possible.  It will be 
@@ -404,34 +409,38 @@ sub load_locale_handlers {
         while( --$sub_idx >= 0 ) {
             my $ptag = $locale_tags[$sub_idx];
             if( substr($tag, 0, length($ptag)) eq $ptag ) {
-                $parent_tag = "::$ptag";
+                $parent_tag .= "::$ptag";
                 last;
             }
         }
 
-        my $messages = $locales{$tag} || '';
-
-        # TODO Can we do this without eval?
-        my $eval = <<"        EVAL";
+        my $eval = <<"        EVAL"; # Dynamic part
             package OpenILS::WWW::EGWeb::I18N::$tag;
-            use base 'OpenILS::WWW::EGWeb::I18N$parent_tag';
-            if(\$messages) {
+            use base '$parent_tag';
+        EVAL
+
+        $eval .= <<'        EVAL';
+            our %Lexicon;
+            if(@{$locales{$tag}}) {
                 use Locale::Maketext::Lexicon {
                     _decode => 1
                 };
                 use Locale::Maketext::Lexicon::Gettext;
-                if(open F, '$messages') {
-                    our %Lexicon = (%Lexicon, %{ Locale::Maketext::Lexicon::Gettext->parse(<F>) });
-                    close F;
-                } else {
-                    warn "EGWeb: unable to open messages file: $messages"; 
+                for my $messages (@{$locales{$tag}}) {
+                    if(open F, $messages) {
+                        %Lexicon = (%Lexicon, %{ Locale::Maketext::Lexicon::Gettext->parse(<F>) });
+                        close F;
+                    } else {
+                        warn "EGWeb: unable to open messages file: $messages"; 
+                    }
                 }
             }
         EVAL
+
         eval $eval;
 
         if ($@) {
-            warn "$@\n" if $@;
+            warn "$@\n";
         } else {
             $registered_locales{"$tag"} = $locale_name;
         }

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm |   45 ++++++++++++++---------
 1 files changed, 27 insertions(+), 18 deletions(-)


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list