Build resource file.

Generate expected_locale_keys from cmakefile
This commit is contained in:
Twan van Laarhoven
2020-04-10 14:23:54 +02:00
parent 6e7a4485a8
commit 4ebf0c51ee
4 changed files with 228 additions and 664 deletions
+27 -25
View File
@@ -3,10 +3,19 @@
# Determine the keys that should be in the locale file,
# and the number of arguments the keys should have
use strict;
use File::Find;
if (scalar @ARGV != 2) {
die("Usage: $0 <SRCDIR> <OUTFILE>")
}
my $indir = $ARGV[0];
my $outfile = $ARGV[1];
our %found;
use File::Find;
find(\&doit, '../../src');
find(\&doit, $indir);
sub arg_count {
return scalar split(/,/,$_[0]);
@@ -35,6 +44,7 @@ sub doit {
close F;
# Custom argument expansion
my $inparen;
$inparen = qr/[^()]|\((??{$inparen})*\)/; # recursive paren matching
$body =~ s/format_string\((_[A-Z]+)(_\([^)]+\)),($inparen+)/
$1 . "_" . arg_count($3) . $2
@@ -54,7 +64,7 @@ sub find_locale_calls {
# Find calls to locale functions
while ($body =~ /_(COMMENT_)?(MENU|HELP|TOOL|TOOLTIP|LABEL|BUTTON|TITLE|TYPE|ACTION|ERROR)_(?:([1-9])_)?\(\s*\"([^\"]+)\"/g) {
$argc = $3 ? $3 : 0;
my $argc = $3 ? $3 : 0;
if (defined($found{$2}{$4}{'argc'}) && $found{$2}{$4}{'argc'} != $argc) {
print "ERROR: key _$2_($4) used with different arities";
}
@@ -68,37 +78,29 @@ sub find_locale_calls {
\s* _ \(\" ([^\"]+) \"\)
@xg
) {
my $key;
($key = $2) =~ s/_/ /g;
foreach $type ("MENU","HELP","TOOL","TOOLTIP") {
foreach my $type ("MENU","HELP","TOOL","TOOLTIP") {
$found{$type}{$key}{'opt'} = $in_comment;
$found{$type}{$key}{'argc'} = 0;
}
}
}
# Now process the items we found, print out a list in MSE reader format
# Now process the items we found, write thea list in MSE reader format
my $result;
my $now = localtime;
$result .= "# This file contains the keys expected to be in MSE locales\n";
$result .= "# It was automatically generated by tools/locale/locale.pl\n";
$result .= "# Generated on " . $now . "\n\n";
open my $fh, "> $outfile";
print $fh "# This file contains the keys expected to be in MSE locales\n";
print $fh "# It was automatically generated by tools/locale/locale.pl\n";
print $fh "# Generated on " . localtime . "\n\n";
my @types = sort keys %found;
foreach $type (@types) {
$result .= lc($type) . ":\n";
foreach my $type (@types) {
print $fh lc($type) . ":\n";
my @keys = sort keys %{$found{$type}};
foreach $key (@keys) {
$argc = $found{$type}{$key}{'argc'};
$opt = $found{$type}{$key}{'opt'} ? 'optional, ' : '';
$result .= "\t$key:\t$opt$argc\n";
foreach my $key (@keys) {
my $argc = $found{$type}{$key}{'argc'};
my $opt = $found{$type}{$key}{'opt'} ? 'optional, ' : '';
print $fh "\t$key: $opt$argc\n";
}
}
# Write to file
open F, "> ../../src/resource/common/expected_locale_keys";
print F $result;
close F;
# and to stdout
#print $result;
}