mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-14 15:39:12 +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:
parent
9144d48fab
commit
0ddc3aacc0
@ -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 = <IN>) {
|
||||
last if($l =~ m/<h3>Introduction/);
|
||||
$noindex{$1} = 1 if($l =~ m/href="#(.*)"/);
|
||||
}
|
||||
seek(IN,0,0);
|
||||
|
||||
# Second run: create the file
|
||||
# Header
|
||||
while(my $l = <IN>) {
|
||||
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 " <a href='#$mod'>$mod</a> \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 = <IN>) {
|
||||
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 = <MOD>) {
|
||||
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 = <IN>) {
|
||||
last if($l =~ m/<h3>Introduction/);
|
||||
$noindex{$1} = 1 if($l =~ m/href="#(.*)"/);
|
||||
}
|
||||
seek(IN,0,0);
|
||||
|
||||
# Second run: create the file
|
||||
# Header
|
||||
while(my $l = <IN>) {
|
||||
print OUT $l;
|
||||
last if($l =~ m/#global/);
|
||||
}
|
||||
|
||||
# index for devices.
|
||||
foreach my $mod (sort keys %mods) {
|
||||
next if($noindex{$mod});
|
||||
print OUT " <a href='#$mod'>$mod</a> \n";
|
||||
}
|
||||
|
||||
# Copy the middle part
|
||||
while(my $l = <IN>) {
|
||||
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 = <MOD>) {
|
||||
if($l =~ m/^=begin html$suffix$/) {
|
||||
$l = <MOD>; # 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 '<a name="perl"></a>',"\n";
|
||||
while(my $l = <IN>) {
|
||||
print OUT $l;
|
||||
# Copy the tail
|
||||
print OUT '<a name="perl"></a>',"\n";
|
||||
while(my $l = <IN>) {
|
||||
print OUT $l;
|
||||
}
|
||||
close(OUT);
|
||||
}
|
||||
close(OUT);
|
||||
|
@ -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 = <IN>) {
|
||||
$l =~ s/[\r\n]//g;
|
||||
if($l =~ m,^<a name="(.*)"></a>$,) {
|
||||
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 = <MODIN>) {
|
||||
$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 = <IN>) {
|
||||
$l =~ s/[\r\n]//g;
|
||||
if($l =~ m,^<a name="(.*)"></a>$,) {
|
||||
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,</ul>,);
|
||||
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 = <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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user