Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions tools/checkkeys.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,48 @@
##############################################################################

use open qw(:std :utf8);
use XML::Simple qw(:strict);
use XML::LibXML;
use Data::Dumper;

my %keys;

my $doneeng = 0;
my $language;

while ($ts = <*.ts>) {
my $xs = XMLin($ts, KeyAttr => {}, ForceArray => ['context', 'message']);
my $dom = XML::LibXML->load_xml(location => $ts);

# print Data::Dumper->Dump([$xs], [qw(xs)]);

printf "Language: %s\n", $xs->{language};
foreach my $TS ($dom->findnodes('//TS/@language')) {
$language = $TS->to_literal();
printf "Language: %s\n", $language;
}

foreach $context (@{$xs->{context}}) {
# printf "\n========================================\nContext: %s\n", $context->{name};
my $contextname = $context->{name};
$contextname =~ s/Base$//; # merge base class with its child
foreach my $context ($dom->findnodes('//context')) {
my $contextname = $context->findvalue('./name');
# printf "\n========================================\nContext: %s\n", $contextname;
$contextname =~ s/Base$//; # merge base class with its child
$contextname = 'CClientDlg+CHelpMenu' if ($contextname eq 'CClientDlg' || $contextname eq 'CHelpMenu');

foreach $message (@{$context->{message}}) {
# printf " Msg: %s\n", $message->{source};
next if $message->{translation}{type} eq 'obsolete';
next if $message->{translation}{type} eq 'vanished';
#next if $message->{translation}{type} eq 'unfinished'; # don't skip unfinished strings, as they may still get used
MESSAGE: foreach my $message ($context->findnodes('./message')) {
my $source = $message->findvalue('./source');
# printf " Msg: %s\n", $source;

next unless $message->{source} =~ /\&(.)/;
foreach my $translation ($message->findnodes('./translation')) {
my $type = $translation->{type};
next MESSAGE if $type eq 'obsolete';
next MESSAGE if $type eq 'vanished';
#next MESSAGE if $type eq 'unfinished'; # don't skip unfinished strings, as they may still get used

push @{$keys{en}{$contextname}{uc $1}}, $message->{source} unless $doneeng;
# skip messages without an accelerator key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we're still skipping even if the translation has an accelerator but the English doesn't.

Shouldn't we

  1. Check that both English and translation have accelerators or both don't (for documentation consistency) -- or is this done elsewhere?
  2. Then skip if both don't

If the "both the same" is done elsewhere, this is okay -- but I'd suggest mentioning that in the comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, we're still skipping even if the translation has an accelerator but the English doesn't.

I'll check, but I think that's the same with the existing tool.

Shouldn't we

  1. Check that both English and translation have accelerators or both don't (for documentation consistency) -- or is this done elsewhere?
  1. Then skip if both don't

That is probably a good idea, but out of scope for this PR, which was only concerned with changing XML library.

If the "both the same" is done elsewhere, this is okay -- but I'd suggest mentioning that in the comment.

There are other improvements that could be done to this tool too, but I would do them, and the good suggestions above, separately. At the moment, the output of the tool is just a starting point to aid manual review as part of the release process.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it does change the flow, which raises the questions over what the old was doing and what the new is doing.

next MESSAGE unless $source =~ /\&(.)/;

if (exists($message->{translation}{content})) {
if ($message->{translation}{content} =~ /\&(.)/) {
push @{$keys{$xs->{language}}{$contextname}{uc $1}}, $message->{translation}{content} . " (" . $message->{source} . ")";
push @{$keys{en}{$contextname}{uc $1}}, $source unless $doneeng;

my $content = $translation->to_literal();
if ($content =~ /\&(.)/) {
push @{$keys{$language}{$contextname}{uc $1}}, $content . " (" . $source . ")";
}
} elsif ($message->{translation} =~ /\&(.)/) {
push @{$keys{$xs->{language}}{$contextname}{uc $1}}, $message->{translation} . " (" . $message->{source} . ")";
}

}
}

Expand Down
Loading