This question about Not sure...: Answered

How would I implement multi language form labels?

If I want the labels of my data forms be specific to my users language settings: What are the best practices for multi language supporting Wiki pages?

-- FranzJosefGigler - 18 Aug 2014

Foswiki core does not support this. I'd recommend to use FlexFormPlugin to render forms. Example:

<form ... >
%RENDERFOREDIT{
   form="topic holding the data form definition" .... or topic="topic with a data form already attached"
   SomeFormfield_title="%MAKETEXT{"Here is my english title"}%" .... or SomeFormfield_title="%TRANSLATE{en="Here is my english title" de="Hier ist mein deutscher Titel"}%"
   ...
}%
</form>

Custom translation strings in %MAKETEXT may be provided by your own extensions starting with Foswiki-1.2.0 ... or by using below patch to Foswiki-1.1.9

--- a//lib/Foswiki/I18N.pm
+++ b/lib/Foswiki/I18N.pm
@@ -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;
     }
+
 }

The solution using an inline translations via %TRANSLATE require MultiLingualPlugin.

-- MichaelDaum - 19 Aug 2014
 

QuestionForm edit

Subject Not sure...
Extension
Version Foswiki 1.1.9
Status Answered
Related Topics
Topic revision: r2 - 19 Aug 2014, MichaelDaum - This page was cached on 16 Nov 2018 - 19:16.

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