From 9d61144d3769c621b469909438210d11abe4e35f Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Sun, 8 Dec 2019 18:58:55 +0000
Subject: [PATCH] commandref_modular.pl: show german doc only if available
(Forum #105079)
git-svn-id: https://svn.fhem.de/fhem/trunk@20691 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/contrib/commandref_modular.pl | 24 +++++++++++++++++++-----
fhem/contrib/commandref_static.pl | 25 ++++++++++++++++++++-----
fhem/www/pgm2/fhemdoc_modular.js | 17 +++++++++++++++--
3 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/fhem/contrib/commandref_modular.pl b/fhem/contrib/commandref_modular.pl
index 94523523a..6de786576 100644
--- a/fhem/contrib/commandref_modular.pl
+++ b/fhem/contrib/commandref_modular.pl
@@ -56,6 +56,13 @@ for my $lang (@lang) {
}
}
}
+
+ if($l =~ m,
]*> ([^<]+)
,) {
+ for my $ml (split(" ", $1)) {
+ my ($n,$v) = split(/[:,]/,$ml,2);
+ $modData{$n}{modLangs} = $v;
+ }
+ }
}
close(FH);
}
@@ -66,18 +73,22 @@ for my $lang (@lang) {
my $mName = $1;
my $ts = (stat("$modDir/$fName"))[9];
if($protVersion != $fileVersion ||
- !$modData{$mName} || !$modData{$mName}{ts} || $modData{$mName}{ts}<$ts) {
+ !$modData{$mName} || !$modData{$mName}{ts} || $modData{$mName}{ts}<$ts ||
+ !$modData{$mName}{modLangs}) {
#print "Checking $fName for $lang short description\n";
$modData{$mName}{type}="device" if(!$modData{$mName}{type});
delete($modData{$mName}{modLinks});
open(FH, "$modDir/$fName") || die("Cant open $modDir/$fName: $!\n");
+ my @lang;
while(my $l = ) {
+ push @lang,($1 eq "" ? "EN":substr($1,1)) if($l =~ m/^=begin html(.*)/);
$modData{$mName}{type}=$1 if($l =~ m/^=item\s+(helper|command|device)/);
$modData{$mName}{$1} =$2 if($l =~ m/^=item\s+(summary[^ ]*)\s(.*)$/);
$modData{$mName}{modLinks}{$1} = 1
if($l =~ m//);
}
+ $modData{$mName}{modLangs} = join(",", @lang);
close(FH);
}
}
@@ -104,12 +115,15 @@ EOF
if($l =~ m,,) {
my @mList = sort {uc($a) cmp uc($b)} keys %modData;
if(!$linkDumped) {
- my $ml = "";
+ my ($mlink,$mlang) = ("","");
for my $m (@mList) {
- next if(!$modData{$m}{modLinks});
- $ml .= " $m:".join(",", keys(%{$modData{$m}{modLinks}}));
+ $mlink .= " $m:".join(",", keys(%{$modData{$m}{modLinks}}))
+ if($modData{$m}{modLinks});
+ $mlang .= " $m:$modData{$m}{modLangs}"
+ if($modData{$m}{modLangs});
}
- print OUT "$ml
\n";
+ print OUT "$mlink
\n";
+ print OUT "$mlang
\n";
$linkDumped = 1;
}
my $type = $1;
diff --git a/fhem/contrib/commandref_static.pl b/fhem/contrib/commandref_static.pl
index 8f457e297..4b6762c2f 100755
--- a/fhem/contrib/commandref_static.pl
+++ b/fhem/contrib/commandref_static.pl
@@ -66,6 +66,13 @@ for my $lang (@lang) {
}
}
}
+
+ if($l =~ m,]*> ([^<]+)
,) {
+ for my $ml (split(" ", $1)) {
+ my ($n,$v) = split(/[:,]/,$ml,2);
+ $modData{$n}{modLangs} = $v;
+ }
+ }
}
close(FH);
}
@@ -76,18 +83,23 @@ for my $lang (@lang) {
my $mName = $1;
my $ts = (stat("$modDir/$fName"))[9];
if($protVersion != $fileVersion || $rebuild ||
- !$modData{$mName} || !$modData{$mName}{ts} || $modData{$mName}{ts}<$ts) {
+ !$modData{$mName} || !$modData{$mName}{ts} || $modData{$mName}{ts}<$ts ||
+ !$modData{$mName}{modLangs}) {
+
#print "Checking $fName for $lang short description\n";
$modData{$mName}{type}="device" if(!$modData{$mName}{type});
delete($modData{$mName}{modLinks});
open(FH, "$modDir/$fName") || die("Cant open $modDir/$fName: $!\n");
+ my @lang;
while(my $l = ) {
+ push @lang,($1 eq "" ? "EN":substr($1,1)) if($l =~ m/^=begin html(.*)/);
$modData{$mName}{type}=$1 if($l =~ m/^=item\s+(helper|command|device)/);
$modData{$mName}{$1} =$2 if($l =~ m/^=item\s+(summary[^ ]*)\s(.*)$/);
$modData{$mName}{modLinks}{$1} = 1
if($l =~ m//);
}
+ $modData{$mName}{modLangs} = join(",", @lang);
close(FH);
my $output = _cref_search("$modDir/$fName",$sfx);
my $outFile = "docs/cref$sfx/$mName.cref";
@@ -118,12 +130,15 @@ EOF
if($l =~ m,,) {
my @mList = sort {uc($a) cmp uc($b)} keys %modData;
if(!$linkDumped) {
- my $ml = "";
+ my ($mlink,$mlang) = ("","");
for my $m (@mList) {
- next if(!$modData{$m}{modLinks});
- $ml .= " $m:".join(",", keys(%{$modData{$m}{modLinks}}));
+ $mlink .= " $m:".join(",", keys(%{$modData{$m}{modLinks}}))
+ if($modData{$m}{modLinks});
+ $mlang .= " $m:$modData{$m}{modLangs}"
+ if($modData{$m}{modLangs});
}
- print OUT "$ml
\n";
+ print OUT "$mlink
\n";
+ print OUT "$mlang
\n";
$linkDumped = 1;
}
my $type = $1;
diff --git a/fhem/www/pgm2/fhemdoc_modular.js b/fhem/www/pgm2/fhemdoc_modular.js
index c63ce7986..5d209bb4a 100644
--- a/fhem/www/pgm2/fhemdoc_modular.js
+++ b/fhem/www/pgm2/fhemdoc_modular.js
@@ -3,7 +3,7 @@
var fd_loadedHash={}, fd_loadedList=[], fd_all={}, fd_allCnt, fd_progress=0,
fd_lang, fd_offsets=[], fd_scrolled=0, fd_modLinks={}, csrfToken="X",
- fd_mode = "FHEM";
+ fd_modLangs={}, fd_mode = "FHEM";
var fd_otherSrc = { "usb":"autocreate", "createlog":"autocreate" };
@@ -182,7 +182,11 @@ checkScroll()
$("a#otherLang span.mod").html(mname);
$("a#otherLang span[lang="+l1+"]").hide();
$("a#otherLang span[lang="+l2+"]").show();
- $("a#otherLang").show();
+ if(fd_modLangs[mname] && fd_modLangs[mname][l2]) {
+ $("a#otherLang").show();
+ } else {
+ $("a#otherLang").hide();
+ }
}
}
@@ -233,6 +237,15 @@ $(document).ready(function(){
fd_modLinks[a2[i2]] = mName;
}
});
+ $("div#modLangs").each(function(){
+ var a1 = $(this).html().split(" ");
+ for(var i1=0; i1