2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-21 20:06:18 +00:00

Multi-lang support

git-svn-id: https://svn.fhem.de/fhem/trunk@2197 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-11-26 15:10:37 +00:00
parent 9144d48fab
commit 0ddc3aacc0
2 changed files with 133 additions and 94 deletions

View File

@ -4,16 +4,9 @@ use strict;
use warnings; use warnings;
# $Id$ # $Id$
my $docIn = "docs/commandref_frame.html";
my $docOut = "docs/commandref.html";
my @modDir = ("FHEM");
use constant TAGS => qw{ul li code}; 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 %mods;
my @modDir = ("FHEM");
foreach my $modDir (@modDir) { foreach my $modDir (@modDir) {
opendir(DH, $modDir) || die "Cant open $modDir: $!\n"; opendir(DH, $modDir) || die "Cant open $modDir: $!\n";
while(my $l = readdir DH) { while(my $l = readdir DH) {
@ -25,44 +18,56 @@ foreach my $modDir (@modDir) {
} }
} }
# First run: check what is a command and what is a helper module
my $status; my @lang = ("EN", "DE");
my %noindex;
while(my $l = <IN>) { foreach my $lang (@lang) {
my $suffix = ($lang eq "EN" ? "" : "_$lang");
my $docIn = "docs/commandref_frame$suffix.html";
my $docOut = "docs/commandref$suffix.html";
open(IN, "$docIn") || die "Cant open $docIn: $!\n";
open(OUT, ">$docOut") || die "Cant open $docOut: $!\n";
# First run: check what is a command and what is a helper module
my $status;
my %noindex;
while(my $l = <IN>) {
last if($l =~ m/<h3>Introduction/); last if($l =~ m/<h3>Introduction/);
$noindex{$1} = 1 if($l =~ m/href="#(.*)"/); $noindex{$1} = 1 if($l =~ m/href="#(.*)"/);
} }
seek(IN,0,0); seek(IN,0,0);
# Second run: create the file # Second run: create the file
# Header # Header
while(my $l = <IN>) { while(my $l = <IN>) {
print OUT $l; print OUT $l;
last if($l =~ m/#global/); last if($l =~ m/#global/);
} }
# index for devices. # index for devices.
foreach my $mod (sort keys %mods) { foreach my $mod (sort keys %mods) {
next if($noindex{$mod}); next if($noindex{$mod});
print OUT " <a href='#$mod'>$mod</a> &nbsp;\n"; print OUT " <a href='#$mod'>$mod</a> &nbsp;\n";
} }
# Copy the middle part # Copy the middle part
while(my $l = <IN>) { while(my $l = <IN>) {
last if($l =~ m/name="perl"/); last if($l =~ m/name="perl"/);
print OUT $l; print OUT $l;
} }
# Copy the doc part from the module # Copy the doc part from the module
foreach my $mod (sort keys %mods) { foreach my $mod (sort keys %mods) {
my $tag; my $tag;
my %tagcount= (); my %tagcount= ();
open(MOD, $mods{$mod}) || die("Cant open $mods{$mod}:$!\n"); open(MOD, $mods{$mod}) || die("Cant open $mods{$mod}:$!\n");
my $skip = 1; my $skip = 1;
while(my $l = <MOD>) { while(my $l = <MOD>) {
if($l =~ m/^=begin html/) { if($l =~ m/^=begin html$suffix$/) {
$l = <MOD>; # skip one line, to be able to repeat join+split
$skip = 0; $skip = 0;
} elsif($l =~ m/^=end html/) { } elsif($l =~ m/^=end html$suffix/) {
$skip = 1; $skip = 1;
} elsif(!$skip) { } elsif(!$skip) {
# here we copy line by line from the module # here we copy line by line from the module
@ -75,13 +80,14 @@ foreach my $mod (sort keys %mods) {
} }
close(MOD); close(MOD);
foreach $tag (TAGS) { foreach $tag (TAGS) {
print("$mods{$mod}: Unbalanced $tag\n") if($tagcount{$tag}); print("$lang $mods{$mod}: Unbalanced $tag\n") if($tagcount{$tag});
}
} }
}
# Copy the tail # Copy the tail
print OUT '<a name="perl"></a>',"\n"; print OUT '<a name="perl"></a>',"\n";
while(my $l = <IN>) { while(my $l = <IN>) {
print OUT $l; print OUT $l;
}
close(OUT);
} }
close(OUT);

View File

@ -3,12 +3,8 @@
use strict; use strict;
use warnings; use warnings;
my $docIn = "docs/commandref.html"; my @lang = ("EN", "DE");
my $docOut = "docs/commandref_frame.html"; my @modDir = ("FHEM");
my @modDir = ("FHEM", "contrib", "webfrontend/pgm5");
open(IN, "$docIn") || die "Cant open $docIn: $!\n";
open(OUT, ">$docOut") || die "Cant open $docOut: $!\n";
my %mods; my %mods;
foreach my $modDir (@modDir) { foreach my $modDir (@modDir) {
@ -22,42 +18,79 @@ foreach my $modDir (@modDir) {
} }
} }
my %doc;
my %fnd; my %fnd;
my $modFileName; my $modFileName;
while(my $l = <IN>) { 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 = <IN>) {
$l =~ s/[\r\n]//g; $l =~ s/[\r\n]//g;
if($l =~ m,^<a name="(.*)"></a>$,) { if($l =~ m,^<a name="(.*)"></a>$,) {
if($modFileName) { if($modFileName) {
print MODOUT "=end html\n=cut\n"; $doc{$modFileName}{$lang} = $content;
close(MODOUT); $content = "";
rename "$modFileName.NEW", $modFileName;
} }
my $mod = lc($1); my $mod = lc($1);
if($mods{$mod}) { if($mods{$mod}) {
print "Double-Fnd: $mod\n" if($fnd{$mod}); print "Double-Fnd: $mod\n" if($fnd{$mod});
$fnd{$mod} = 1; $fnd{$mod} = 1;
$modFileName = $mods{$mod}; $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 = <MODIN>) {
$seen1 = 1 if($l =~ m/^1;[\r\n]*/);
last if($l =~ m/=pod/ && $seen1);
print MODOUT $l;
}
print MODOUT "\n\=pod\n=begin html\n\n";
} else { } else {
print "Not a module: $mod\n"; print "Not a module: $mod\n" if($lang eq "EN");
$modFileName = ""; $modFileName = "";
} }
} }
if($l =~ m,href="#global",) {
print OUT "$l\n";
$skipping = 1;
next;
}
$skipping = 0 if($skipping && $l =~ m,</ul>,);
next if($skipping);
if($modFileName){ if($modFileName){
print MODOUT "$l\n"; $content .= "$l\n";
} else { } else {
print OUT "$l\n"; print OUT "$l\n";
} }
}
} }
foreach my $mod (sort {$mods{$a} cmp $mods{$b}} keys %mods) { foreach my $mod (sort {$mods{$a} cmp $mods{$b}} keys %mods) {
print "Missing doc for $mods{$mod}\n" if(!$fnd{$mod}); 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 = <IN>) {
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);
} }