|
25 | 25 | ############################################################################## |
26 | 26 |
|
27 | 27 | use open qw(:std :utf8); |
28 | | -use XML::Simple qw(:strict); |
| 28 | +use XML::LibXML; |
29 | 29 | use Data::Dumper; |
30 | 30 |
|
31 | 31 | my %keys; |
32 | 32 |
|
33 | 33 | my $doneeng = 0; |
| 34 | +my $language; |
34 | 35 |
|
35 | 36 | while ($ts = <*.ts>) { |
36 | | - my $xs = XMLin($ts, KeyAttr => {}, ForceArray => ['context', 'message']); |
| 37 | + my $dom = XML::LibXML->load_xml(location => $ts); |
37 | 38 |
|
38 | | - # print Data::Dumper->Dump([$xs], [qw(xs)]); |
39 | | - |
40 | | - printf "Language: %s\n", $xs->{language}; |
| 39 | + foreach my $TS ($dom->findnodes('//TS/@language')) { |
| 40 | + $language = $TS->to_literal(); |
| 41 | + printf "Language: %s\n", $language; |
| 42 | + } |
41 | 43 |
|
42 | | - foreach $context (@{$xs->{context}}) { |
43 | | - # printf "\n========================================\nContext: %s\n", $context->{name}; |
44 | | - my $contextname = $context->{name}; |
45 | | - $contextname =~ s/Base$//; # merge base class with its child |
| 44 | + foreach my $context ($dom->findnodes('//context')) { |
| 45 | + my $contextname = $context->findvalue('./name'); |
| 46 | + # printf "\n========================================\nContext: %s\n", $contextname; |
| 47 | + $contextname =~ s/Base$//; # merge base class with its child |
46 | 48 | $contextname = 'CClientDlg+CHelpMenu' if ($contextname eq 'CClientDlg' || $contextname eq 'CHelpMenu'); |
47 | 49 |
|
48 | | - foreach $message (@{$context->{message}}) { |
49 | | - # printf " Msg: %s\n", $message->{source}; |
50 | | - next if $message->{translation}{type} eq 'obsolete'; |
51 | | - next if $message->{translation}{type} eq 'vanished'; |
52 | | - #next if $message->{translation}{type} eq 'unfinished'; # don't skip unfinished strings, as they may still get used |
| 50 | + MESSAGE: foreach my $message ($context->findnodes('./message')) { |
| 51 | + my $source = $message->findvalue('./source'); |
| 52 | + # printf " Msg: %s\n", $source; |
53 | 53 |
|
54 | | - next unless $message->{source} =~ /\&(.)/; |
| 54 | + foreach my $translation ($message->findnodes('./translation')) { |
| 55 | + my $type = $translation->{type}; |
| 56 | + next MESSAGE if $type eq 'obsolete'; |
| 57 | + next MESSAGE if $type eq 'vanished'; |
| 58 | + #next MESSAGE if $type eq 'unfinished'; # don't skip unfinished strings, as they may still get used |
55 | 59 |
|
56 | | - push @{$keys{en}{$contextname}{uc $1}}, $message->{source} unless $doneeng; |
| 60 | + # skip messages without an accelerator key |
| 61 | + next MESSAGE unless $source =~ /\&(.)/; |
57 | 62 |
|
58 | | - if (exists($message->{translation}{content})) { |
59 | | - if ($message->{translation}{content} =~ /\&(.)/) { |
60 | | - push @{$keys{$xs->{language}}{$contextname}{uc $1}}, $message->{translation}{content} . " (" . $message->{source} . ")"; |
| 63 | + push @{$keys{en}{$contextname}{uc $1}}, $source unless $doneeng; |
| 64 | + |
| 65 | + my $content = $translation->to_literal(); |
| 66 | + if ($content =~ /\&(.)/) { |
| 67 | + push @{$keys{$language}{$contextname}{uc $1}}, $content . " (" . $source . ")"; |
61 | 68 | } |
62 | | - } elsif ($message->{translation} =~ /\&(.)/) { |
63 | | - push @{$keys{$xs->{language}}{$contextname}{uc $1}}, $message->{translation} . " (" . $message->{source} . ")"; |
64 | 69 | } |
65 | | - |
66 | 70 | } |
67 | 71 | } |
68 | 72 |
|
|
0 commit comments