diff options
Diffstat (limited to 'perl-install/share/po/help_xml2pm.pl')
-rwxr-xr-x | perl-install/share/po/help_xml2pm.pl | 183 |
1 files changed, 79 insertions, 104 deletions
diff --git a/perl-install/share/po/help_xml2pm.pl b/perl-install/share/po/help_xml2pm.pl index 8976fb396..4f2a04e0c 100755 --- a/perl-install/share/po/help_xml2pm.pl +++ b/perl-install/share/po/help_xml2pm.pl @@ -4,6 +4,7 @@ use XML::Parser; use MDK::Common; use utf8; +my $help; my $dir = "doc/manualB/modules"; my $xsltproc = "/usr/bin/xsltproc"; @@ -12,81 +13,73 @@ if ( ! -x "$xsltproc" ){ print "so type \"urpmi libxslt-proc\" please.\n"; exit 1; } +my @langs = grep { !/ru|pt/ } grep { /^..$/ && -e "$dir/$_/drakx-chapter.xml" } all($dir) or die "no XML help found in $dir\n"; my %helps = map { my $lang = $_; - my @l = grep { !/drakx-MNF-chapter/ } map { /(drakx-.*).xml$/ } all("$dir/$lang"); - if (@l < 20) { () } else { - my $template_file = "$dir/$lang/drakx.xml"; - my $file = "$dir/$lang/drakx_full.xml"; - output($template_file, template($lang, @l)); - system("$xsltproc id.xsl $template_file > $file") == 0 or die "$xsltproc id.xsl $template_file failed\n"; + my $file = "$dir/$lang/drakx_full.xml"; + my $template_file = "$dir/$lang/drakx.xml"; + + output($template_file, do { (my $s = $template) =~ s/__LANG__/$lang/g; $s }); + system("$xsltproc id.xsl $template_file > $file") == 0 or die "$xsltproc id.xsl $template_file failed\n"; - my $p = new XML::Parser(Style => 'Tree'); - my $tree = $p->parsefile($file); + my $p = new XML::Parser(Style => 'Tree'); + my $tree = $p->parsefile($file); - $lang => rewrite2(rewrite1(@$tree), $lang); - } -} all($dir); + $lang => rewrite2(rewrite1(@$tree), $lang); +} @langs; my $base = delete $helps{en} || die; save_help($base); foreach my $lang (keys %helps) { print "Now transforming: $lang\n"; + local *F; my ($charset) = cat_("$lang.po") =~ /charset=([^\\]+)/ or die "missing charset in $lang.po\n"; - open(my $F, ">:encoding($charset)", "help-$lang.pot"); - print $F <<EOF; -msgid "" -msgstr "" -"Content-Type: text/plain; charset=$charset\\n" - -EOF + open F, ">:encoding($charset)", "help-$lang.pot"; + print F "\n"; foreach my $id (keys %{$helps{$lang}}) { -# warn "Writing id=$id in lang=$lang\n"; $base->{$id} or warn "$lang:$id doesn't exist in english\n", next; - print $F qq(# DO NOT BOTHER TO MODIFY HERE, SEE:\n# cvs.mandrakesoft.com:/cooker/$dir/$lang/drakx-chapter.xml\n); - print_in_PO($F, to_ascii($base->{$id}[0]), $helps{$lang}{$id}[0]); + print F qq(# DO NOT BOTHER TO MODIFY HERE, SEE:\n# cvs.mandrakesoft.com:/cooker/$dir/$lang/drakx-chapter.xml\n); + print F qq(msgid ""\n"); + print F join(qq(\\n"\n"), split "\n", to_ascii($base->{$id})); + print F qq("\nmsgstr ""\n"); + print F join(qq(\\n"\n"), split "\n", $helps{$lang}{$id}); + print F qq("\n\n); } } unlink(".memdump"); -sub print_in_PO { - my ($F, $msgid, $msgstr) = @_; - - print $F qq(msgid ""\n"); - print $F join(qq(\\n"\n"), split "\n", $msgid); - print $F qq("\nmsgstr ""\n"); - print $F join(qq(\\n"\n"), split "\n", $msgstr); - print $F qq("\n\n); -} - sub save_help { - my ($help, $inside_strings) = @_; - - open(my $F, ">:encoding(ascii)", "../../help.pm"); - print $F <<'EOF'; -package help; + my ($help) = @_; + + #- HACK, don't let this one disappear + $help->{configureXxdm} = +'Finally, you will be asked whether you want to see the graphical interface +at boot. Note this question will be asked even if you chose not to test the +configuration. Obviously, you want to answer \"No\" if your machine is to +act as a server, or if you were not successful in getting the display +configured.'; + + local *F; + open F, ">:encoding(ascii)", "../../help.pm"; + print F q{package help; use common; -1; - # IMPORTANT: Don't edit this File - It is automatically generated # from the manuals !!! # Write a mail to <documentation@mandrakesoft.com> if # you want it changed. -EOF + +%steps = ( +empty => '', +}; foreach (sort keys %$help) { - my ($main, @inside) = map { '"' . to_ascii($_) . '"' } @{$help->{$_}}; - my $s = join(', ', $main, map { qq(N($_)) } @inside); + my $s = to_ascii($help->{$_}); print STDERR "Writing id=$_\n"; - print $F <<EOF; -sub $_() { - N($s); -} -EOF - my @nb = $main =~ /\%s/g; @nb == @inside or die "bad \%s in $_\n"; + print F qq(\n$_ => \n__("$s"),\n); } + print F ");\n"; } # i don't like the default tree format given by XML::Parser, @@ -116,18 +109,17 @@ sub rewrite1 { } # return the list of nodes named $tag -sub find_tag { +sub find { my ($tag, $tree) = @_; if (!ref($tree)) { (); } elsif ($tree->{tag} eq $tag) { $tree; } else { - map { find_tag($tag, $_) } @{$tree->{children}}; + map { find($tag, $_) } @{$tree->{children}}; } } -my $help; sub rewrite2 { my ($tree, $lang) = @_; our $i18ned_open_text_quote = $ {{ @@ -156,21 +148,13 @@ sub rewrite2 { $help; } -my @inside_strings; sub rewrite2_ { - my ($tree, @parents) = @_; + my ($tree) = @_; ref($tree) or return $tree; !$tree->{attr}{condition} || $tree->{attr}{condition} !~ /no-inline-help/ or return ''; - my @prev_inside_strings; - my ($id) = $tree->{attr}{id} ? $tree->{attr}{id} =~ /drakxid-([^-]+)$/ : (); - if ($id) { - @prev_inside_strings = @inside_strings; - @inside_strings = (); - } - my $text = do { - my @l = map { rewrite2_($_, $tree, @parents) } @{$tree->{children}}; + my @l = map { rewrite2_($_) } @{$tree->{children}}; my $text = ""; foreach (@l) { s/^ // if $text =~ /\s$/; @@ -181,19 +165,6 @@ sub rewrite2_ { $text; }; - if ($id) { - my $t = $text; - $t =~ s/^\s+//; - - my @footnotes = map { - my $s = rewrite2_({ %$_, tag => 'para' }); - $s =~ s/^\s+//; - "(*) $s"; - } find_tag('footnote', $tree); - $help->{$id} = [ aerate($t . join('', @footnotes)), @inside_strings ]; - unshift @inside_strings, @prev_inside_strings; - } - if (0) { } elsif (member($tree->{tag}, 'formalpara', 'para', 'itemizedlist', 'orderedlist')) { $text =~ s/^\s(?!\s)//; @@ -203,12 +174,8 @@ sub rewrite2_ { } elsif (member($tree->{tag}, 'quote', 'citetitle', 'foreignphrase')) { $text =~ s/^\Q$i18ned_open_label_quote\E(.*)\Q$i18ned_close_label_quote\E$/$1/ if $i18ned_open_label_quote; ($i18ned_open_text_quote || "``") . $text . ($i18ned_close_text_quote || "''"); - } elsif (member($tree->{tag}, 'literal', 'filename')) { + } elsif (member($tree->{tag}, 'guilabel', 'guibutton', 'guimenu', 'literal', 'filename')) { ($i18ned_open_label_quote || "\\\"") . $text . ($i18ned_close_label_quote || "\\\""); - } elsif (member($tree->{tag}, 'guilabel', 'guibutton', 'guimenu')) { - $text =~ s/\s+$//; - push @inside_strings, $text; - ($i18ned_open_label_quote || "\\\"") . "%s" . ($i18ned_close_label_quote || "\\\""); } elsif ($tree->{tag} eq 'command') { ($i18ned_open_command_quote || "\\\"") . $text . ($i18ned_close_command_quote || "\\\""); } elsif ($tree->{tag} eq 'userinput') { @@ -224,26 +191,38 @@ sub rewrite2_ { $text =~ s/(\s+)$/ !!$1/; $text; } elsif ($tree->{tag} eq 'listitem') { - my $cnt = (any { $_->{tag} eq 'variablelist' } @parents) ? 1 : 0; + my $cnt; $text =~ s/^\s+//; $text =~ s/^/' ' . ($cnt++ ? ' ' : '* ')/emg; "\n$text\n"; + } elsif (member($tree->{tag}, 'acronym', 'application', 'emphasis', - 'keycombo', 'note', 'sect1', 'sect2', + 'keycombo', 'note', 'superscript', 'systemitem', - 'tip', 'ulink', 'xref', 'varlistentry', 'variablelist', 'term', + 'tip', 'ulink', 'xref' )) { # ignored tags $text; } elsif (member($tree->{tag}, qw(title article primary secondary indexterm revnumber - date authorinitials revision revhistory revremark chapterinfo + date authorinitials revision revhistory chapterinfo imagedata imageobject mediaobject figure - abstract book chapter) + book chapter) )) { # dropped tags ''; + } elsif ($tree->{tag} =~ /sect[12]/) { + my $id = $tree->{attr}{id} && $tree->{attr}{id} =~ /drakxid-(.*)/ ? $1 : return; + $text =~ s/^\s+//; + + my @footnotes = map { + my $s = rewrite2_({ %$_, tag => 'para' }); + $s =~ s/^\s+//; + "(*) $s"; + } find('footnote', $tree); + $help->{$id} = aerate($text . join('', @footnotes)); + ''; } elsif ($tree->{tag} eq 'screen') { qq(\n$text\n); } else { @@ -268,45 +247,41 @@ sub to_ascii { $_; } -sub template { - my ($lang, @l) = @_; - my $entities = join("\n", map { qq(<!ENTITY $_ SYSTEM '$_.xml'>) } @l); - my $body = join("\n", map { '&' . $_ . ';' } @l); - - <<EOF; +BEGIN { + $template = <<'EOF'; <?xml version='1.0' encoding='ISO-8859-1'?> <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "/usr/share/sgml/docbook/xml-dtd-4.1.2/docbookx.dtd"[ -$entities +<!ENTITY drakx-chapter SYSTEM 'drakx-chapter.xml'> -<!ENTITY % params.ent SYSTEM "../../manuals/Starter/$lang/params.ent"> +<!ENTITY % params.ent SYSTEM "../../manuals/Starter/__LANG__/params.ent"> %params.ent; -<!ENTITY % strings.ent SYSTEM "../../manuals/Starter/$lang/strings.ent"> +<!ENTITY % strings.ent SYSTEM "../../manuals/Starter/__LANG__/strings.ent"> %strings.ent; <!ENTITY step-only-for-expert ""> -<!ENTITY % acronym-list SYSTEM "../../entities/$lang/acronym_list.ent" > +<!ENTITY % acronym-list SYSTEM "../../entities/__LANG__/acronym_list.ent" > %acronym-list; -<!ENTITY % button-list SYSTEM "../../entities/$lang/button_list.ent" > +<!ENTITY % button-list SYSTEM "../../entities/__LANG__/button_list.ent" > %button-list; -<!ENTITY % companies SYSTEM "../../entities/$lang/companies.ent" > +<!ENTITY % companies SYSTEM "../../entities/__LANG__/companies.ent" > %companies; -<!ENTITY % icon-list SYSTEM "../../entities/$lang/icon_list.ent" > +<!ENTITY % icon-list SYSTEM "../../entities/__LANG__/icon_list.ent" > %icon-list; -<!ENTITY % menu-list SYSTEM "../../entities/$lang/menu_list.ent" > +<!ENTITY % menu-list SYSTEM "../../entities/__LANG__/menu_list.ent" > %menu-list; -<!ENTITY % tab-list SYSTEM "../../entities/$lang/tab_list.ent" > +<!ENTITY % tab-list SYSTEM "../../entities/__LANG__/tab_list.ent" > %tab-list; -<!ENTITY % tech SYSTEM "../../entities/$lang/tech.ent" > +<!ENTITY % tech SYSTEM "../../entities/__LANG__/tech.ent" > %tech; -<!ENTITY % text-field-list SYSTEM "../../entities/$lang/text_field_list.ent" > +<!ENTITY % text-field-list SYSTEM "../../entities/__LANG__/text_field_list.ent" > %text-field-list; -<!ENTITY % titles SYSTEM "../../entities/$lang/titles.ent" > +<!ENTITY % titles SYSTEM "../../entities/__LANG__/titles.ent" > %titles; -<!ENTITY % typo SYSTEM "../../entities/$lang/typo.ent" > +<!ENTITY % typo SYSTEM "../../entities/__LANG__/typo.ent" > %typo; <!ENTITY % common SYSTEM "../../entities/common.ent" > %common; @@ -315,14 +290,14 @@ $entities <!ENTITY % prog-list SYSTEM "../../entities/prog_list.ent" > %prog-list; -<!ENTITY lang '$lang'> +<!ENTITY lang '__LANG__'> ]> <book> <title>DrakX Documentation</title> -$body + &drakx-chapter; </book> EOF |