From 0ddc3aacc096b1a7472387c22436c7a4b973a276 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 26 Nov 2012 15:10:37 +0000 Subject: [PATCH] Multi-lang support git-svn-id: https://svn.fhem.de/fhem/trunk@2197 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/commandref_join.pl | 124 ++++++++++++++++--------------- fhem/contrib/commandref_split.pl | 103 ++++++++++++++++--------- 2 files changed, 133 insertions(+), 94 deletions(-) diff --git a/fhem/contrib/commandref_join.pl b/fhem/contrib/commandref_join.pl index fab5042e0..bd9a546f0 100755 --- a/fhem/contrib/commandref_join.pl +++ b/fhem/contrib/commandref_join.pl @@ -4,16 +4,9 @@ use strict; use warnings; # $Id$ - -my $docIn = "docs/commandref_frame.html"; -my $docOut = "docs/commandref.html"; -my @modDir = ("FHEM"); use constant TAGS => qw{ul li code}; - -open(IN, "$docIn") || die "Cant open $docIn: $!\n"; -open(OUT, ">$docOut") || die "Cant open $docOut: $!\n"; - my %mods; +my @modDir = ("FHEM"); foreach my $modDir (@modDir) { opendir(DH, $modDir) || die "Cant open $modDir: $!\n"; while(my $l = readdir DH) { @@ -25,63 +18,76 @@ foreach my $modDir (@modDir) { } } -# First run: check what is a command and what is a helper module -my $status; -my %noindex; -while(my $l = ) { - last if($l =~ m/

Introduction/); - $noindex{$1} = 1 if($l =~ m/href="#(.*)"/); -} -seek(IN,0,0); -# Second run: create the file -# Header -while(my $l = ) { - print OUT $l; - last if($l =~ m/#global/); -} +my @lang = ("EN", "DE"); -# index for devices. -foreach my $mod (sort keys %mods) { - next if($noindex{$mod}); - print OUT " $mod  \n"; -} +foreach my $lang (@lang) { + my $suffix = ($lang eq "EN" ? "" : "_$lang"); + my $docIn = "docs/commandref_frame$suffix.html"; + my $docOut = "docs/commandref$suffix.html"; -# Copy the middle part -while(my $l = ) { - last if($l =~ m/name="perl"/); - print OUT $l; -} + open(IN, "$docIn") || die "Cant open $docIn: $!\n"; + open(OUT, ">$docOut") || die "Cant open $docOut: $!\n"; -# Copy the doc part from the module -foreach my $mod (sort keys %mods) { - my $tag; - my %tagcount= (); - open(MOD, $mods{$mod}) || die("Cant open $mods{$mod}:$!\n"); - my $skip = 1; - while(my $l = ) { - if($l =~ m/^=begin html/) { - $skip = 0; - } elsif($l =~ m/^=end html/) { - $skip = 1; - } elsif(!$skip) { - # here we copy line by line from the module - print OUT $l; - foreach $tag (TAGS) { - $tagcount{$tag}+= ($l =~ /<$tag>/i); - $tagcount{$tag}-= ($l =~ /<\/$tag>/i); + # First run: check what is a command and what is a helper module + my $status; + my %noindex; + while(my $l = ) { + last if($l =~ m/

Introduction/); + $noindex{$1} = 1 if($l =~ m/href="#(.*)"/); + } + seek(IN,0,0); + + # Second run: create the file + # Header + while(my $l = ) { + print OUT $l; + last if($l =~ m/#global/); + } + + # index for devices. + foreach my $mod (sort keys %mods) { + next if($noindex{$mod}); + print OUT " $mod  \n"; + } + + # Copy the middle part + while(my $l = ) { + last if($l =~ m/name="perl"/); + print OUT $l; + } + + # Copy the doc part from the module + foreach my $mod (sort keys %mods) { + my $tag; + my %tagcount= (); + open(MOD, $mods{$mod}) || die("Cant open $mods{$mod}:$!\n"); + my $skip = 1; + while(my $l = ) { + if($l =~ m/^=begin html$suffix$/) { + $l = ; # skip one line, to be able to repeat join+split + $skip = 0; + } elsif($l =~ m/^=end html$suffix/) { + $skip = 1; + } elsif(!$skip) { + # here we copy line by line from the module + print OUT $l; + foreach $tag (TAGS) { + $tagcount{$tag}+= ($l =~ /<$tag>/i); + $tagcount{$tag}-= ($l =~ /<\/$tag>/i); + } } } + close(MOD); + foreach $tag (TAGS) { + print("$lang $mods{$mod}: Unbalanced $tag\n") if($tagcount{$tag}); + } } - close(MOD); - foreach $tag (TAGS) { - print("$mods{$mod}: Unbalanced $tag\n") if($tagcount{$tag}); - } -} -# Copy the tail -print OUT '',"\n"; -while(my $l = ) { - print OUT $l; + # Copy the tail + print OUT '',"\n"; + while(my $l = ) { + print OUT $l; + } + close(OUT); } -close(OUT); diff --git a/fhem/contrib/commandref_split.pl b/fhem/contrib/commandref_split.pl index 4cf3d0396..37ea641cc 100644 --- a/fhem/contrib/commandref_split.pl +++ b/fhem/contrib/commandref_split.pl @@ -3,12 +3,8 @@ use strict; use warnings; -my $docIn = "docs/commandref.html"; -my $docOut = "docs/commandref_frame.html"; -my @modDir = ("FHEM", "contrib", "webfrontend/pgm5"); - -open(IN, "$docIn") || die "Cant open $docIn: $!\n"; -open(OUT, ">$docOut") || die "Cant open $docOut: $!\n"; +my @lang = ("EN", "DE"); +my @modDir = ("FHEM"); my %mods; foreach my $modDir (@modDir) { @@ -22,42 +18,79 @@ foreach my $modDir (@modDir) { } } + +my %doc; my %fnd; my $modFileName; -while(my $l = ) { - $l =~ s/[\r\n]//g; - if($l =~ m,^$,) { - if($modFileName) { - print MODOUT "=end html\n=cut\n"; - close(MODOUT); - rename "$modFileName.NEW", $modFileName; - } - my $mod = lc($1); - if($mods{$mod}) { - print "Double-Fnd: $mod\n" if($fnd{$mod}); - $fnd{$mod} = 1; - $modFileName = $mods{$mod}; - open(MODIN, "$modFileName") || die("Cant open $modFileName: $!\n"); - open(MODOUT, ">$modFileName.NEW") || die("Cant open $modFileName.NEW: $!\n"); - my $seen1; - while(my $l = ) { - $seen1 = 1 if($l =~ m/^1;[\r\n]*/); - last if($l =~ m/=pod/ && $seen1); - print MODOUT $l; +foreach my $lang (@lang) { + my $suffix = ($lang eq "EN" ? "" : "_$lang"); + + my $docIn = "docs/commandref$suffix.html"; + my $docOut = "docs/commandref_frame$suffix.html"; + #my @modDir = ("FHEM", "contrib", "webfrontend/pgm5"); + + open(IN, "$docIn") || die "Cant open $docIn: $!\n"; + open(OUT, ">$docOut") || die "Cant open $docOut: $!\n"; + + my $content = ""; + my $skipping; + + while(my $l = ) { + $l =~ s/[\r\n]//g; + if($l =~ m,^$,) { + if($modFileName) { + $doc{$modFileName}{$lang} = $content; + $content = ""; + } + my $mod = lc($1); + if($mods{$mod}) { + print "Double-Fnd: $mod\n" if($fnd{$mod}); + $fnd{$mod} = 1; + $modFileName = $mods{$mod}; + } else { + print "Not a module: $mod\n" if($lang eq "EN"); + $modFileName = ""; } - print MODOUT "\n\=pod\n=begin html\n\n"; - } else { - print "Not a module: $mod\n"; - $modFileName = ""; } - } - if($modFileName){ - print MODOUT "$l\n"; - } else { - print OUT "$l\n"; + if($l =~ m,href="#global",) { + print OUT "$l\n"; + $skipping = 1; + next; + } + $skipping = 0 if($skipping && $l =~ m,,); + next if($skipping); + + if($modFileName){ + $content .= "$l\n"; + } else { + print OUT "$l\n"; + } } } foreach my $mod (sort {$mods{$a} cmp $mods{$b}} keys %mods) { print "Missing doc for $mods{$mod}\n" if(!$fnd{$mod}); + $modFileName = $mods{$mod}; + open(IN, "$modFileName") || die("$modFileName: $!\n"); + open(OUT, ">$modFileName.NEW") || die("$modFileName.NEW: $!\n"); + while(my $l = ) { + print OUT $l; + if($l =~ m/^1;/) { + if($doc{$modFileName}) { + print OUT "\n=pod\n\n"; + foreach my $lang (@lang) { + next if(!$doc{$modFileName}{$lang}); + my $suffix = ($lang eq "EN" ? "" : "_$lang"); + print OUT "=begin html$suffix\n\n"; + print OUT $doc{$modFileName}{$lang}; + print OUT "=end html$suffix\n\n"; + } + print OUT "=cut\n"; + } + last; + } + } + close(IN); + close(OUT); + rename("$modFileName.NEW", $modFileName); }