You are here: Foswiki>Tasks Web>Item13790 (23 Nov 2015, GeorgeClark)Edit Attach

Item13790: Backport i18n for extensions to 1.1.x.

pencil
Priority: Enhancement
Current State: Closed
Released In: 1.1.10
Target Release: patch
Applies To: Engine
Component: I18N
Branches: Release01x01
Reported By: MichaelDaum
Waiting For:
Last Change By: GeorgeClark
Below patch allows translations for plugins

--- Release01x01/core/lib/Foswiki/I18N.pm       2013-01-02 14:46:13.506245622 +0100
+++ foswiki/lib/Foswiki/I18N.pm 2014-05-21 17:22:24.000000000 +0200
@@ -54,6 +54,35 @@
     return $tag;
 }

+sub _loadLexicon {
+    my ( $lang, $dir ) = @_;
+
+    $dir ||= $Foswiki::cfg{LocalesDir};
+
+    my $langFile = "$dir/$lang.po";
+
+    #print STDERR "langFile=$langFile\n";
+
+    # Use the compressed version if it exists
+    if ( $langFile =~ m/^(.*)\.po$/
+        && -f "$1.mo" )
+    {
+        $langFile = "$1.mo";
+    }
+    if ( -f $langFile ) {
+        unless (
+            eval {
+                Locale::Maketext::Lexicon->import(
+                    { $lang => [ Gettext => $langFile ] } );
+                1;
+            }
+          )
+        {
+            push( @initErrors, "I18N - Error loading language $lang: $@\n" );
+        }
+    }
+}
+
 # initialisation block
 BEGIN {

@@ -98,34 +127,17 @@
               . "Install Locale::Maketext::Lexicon or turn off {UserInterfaceInternationalisation}"
         );
     }
-    foreach my $lang (@languages) {
-        my $langFile = "$Foswiki::cfg{LocalesDir}/$lang.po";

-        # Use the compressed version if it exists
-        if ( $langFile =~ m/^(.*)\.po$/
-            && -f "$1.mo" )
-        {
-            $langFile = "$1.mo";
-        }
-        if ( -f $langFile ) {
-            unless (
-                eval {
-                    Locale::Maketext::Lexicon->import(
-                        { $lang => [ Gettext => $langFile ] } );
-                    1;
-                }
-              )
-            {
-                push( @initErrors,
-                    "I18N - Error loading language $lang: $@\n" );
-            }
-        }
-        else {
-            push( @initErrors,
-"I18N - Ignoring enabled language $lang as $langFile does not exist.\n"
-            );
-        }
+    opendir( my $dh, "$Foswiki::cfg{LocalesDir}/" ) || next;
+    my @subDirs =
+      grep { !/^\./ && -d "$Foswiki::cfg{LocalesDir}/$_" } readdir $dh;
+    closedir $dh;
+
+    foreach my $lang (@languages) {
+        _loadLexicon($lang);
+        _loadLexicon( $lang, "$Foswiki::cfg{LocalesDir}/$_" ) foreach @subDirs;
     }
+
 }

-- MichaelDaum - 05 Oct 2015

 

ItemTemplate edit

Summary Backport i18n for extensions to 1.1.x.
ReportedBy MichaelDaum
Codebase 1.1.9
SVN Range
AppliesTo Engine
Component I18N
Priority Enhancement
CurrentState Closed
WaitingFor
Checkins distro:7724b6ff5d09
TargetRelease patch
ReleasedIn 1.1.10
CheckinsOnBranches Release01x01
trunkCheckins
masterCheckins
ItemBranchCheckins
Release01x01Checkins distro:7724b6ff5d09
Topic revision: r4 - 23 Nov 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy