my $dbupdir2 = "$basedir/sql/Pg-upgrade2";
my $menufile = "menu.ini";
my $submitsearch = qr/type\s*=\s*[\"\']?submit/i;
+our $self = {};
+our $missing = {};
+our @lost = ();
my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit);
my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER);
return @files;
}
+sub merge_texts {
+# overwrite existing entries with the ones from 'missing'
+ $self->{texts}->{$_} = $missing->{$_} for grep { $missing->{$_} } keys %alllocales;
+
+ # try to set missing entries from lost ones
+ my %lost_by_text = map { ($_->{text} => $_->{translation}) } @lost;
+ $self->{texts}->{$_} = $lost_by_text{$_} for grep { !$self->{texts}{$_} } keys %alllocales;
+}
+
my @bindir_files = find_files($bindir);
my @progfiles = map { m:^(.+)/([^/]+)$:; [ $2, $1 ] } grep { /\.pl$/ && !/_custom/ } @bindir_files;
my @customfiles = grep /_custom/, @bindir_files;
my @dbplfiles2 = grep { /\.pl$/ } keys %dir_h;
# slurp the translations in
-our $self = {};
-our $missing = {};
-our @missing = ();
-our @lost = ();
-
if (-f "$locales_dir/all") {
require "$locales_dir/all";
}
handle_file($_, $dbupdir2) for @dbplfiles2;
scanmenu($_) for @menufiles;
+# merge entries to translate with entries from files 'missing' and 'lost'
+merge_texts();
+
# generate all
generate_file(
file => "$locales_dir/all",
data_sub => sub { _print_line($_, $self->{texts}{$_}, @_) for sort keys %alllocales },
);
+ foreach my $text (keys %$missing) {
+ if ($locale{$text} || $htmllocale{$text}) {
+ unless ($self->{texts}{$text}) {
+ $self->{texts}{$text} = $missing->{$text};
+ }
+ }
+ }
+
+
# calc and generate missing
-push @missing, grep { !$self->{texts}{$_} } sort keys %alllocales;
+my @new_missing = grep { !$self->{texts}{$_} } sort keys %alllocales;
-if (@missing) {
+if (@new_missing) {
generate_file(
file => "$locales_dir/missing",
header => $MISSING_HEADER,
data_name => '$missing',
- data_sub => sub { _print_line($_, '', @_) for @missing },
+ data_sub => sub { _print_line($_, '', @_) for @new_missing },
);
}
search_unused_htmlfiles() if $opt_c;
my $count = scalar keys %alllocales;
-my $notext = scalar @missing;
+my $notext = scalar @new_missing;
my $per = sprintf("%.1f", ($count - $notext) / $count * 100);
print "\n$trlanguage - ${per}%";
print " - $notext/$count missing" if $notext;
}
$file =~ s/\.pl//;
-
- foreach my $text (keys %$missing) {
- if ($locale{$text} || $htmllocale{$text}) {
- unless ($self->{texts}{$text}) {
- $self->{texts}{$text} = $missing->{$text};
- }
- }
- }
}
sub extract_text_between_parenthesis {
# is this a template call?
if (/(?:parse_html_template2?|render)\s*\(\s*[\"\']([\w\/]+)\s*[\"\']/) {
- my $newfile = "$basedir/templates/webpages/$1.html";
+ my $new_file_base = "$basedir/templates/webpages/$1.";
if (/parse_html_template2/) {
- print "E: " . strip_base($file) . " is still using 'parse_html_template2' for " . strip_base($newfile) . ".\n";
+ print "E: " . strip_base($file) . " is still using 'parse_html_template2' for " . strip_base("${new_file_base}html") . ".\n";
+ }
+
+ my $found_one = 0;
+ foreach my $ext (qw(html js json)) {
+ my $new_file = "${new_file_base}${ext}";
+ if (-f $new_file) {
+ $cached{$file}{scanh}{$new_file} = 1;
+ print "." if $opt_v;
+ $found_one = 1;
+ }
}
- if (-f $newfile) {
- $cached{$file}{scanh}{$newfile} = 1;
- print "." if $opt_v;
- } elsif ($opt_c) {
- print "W: missing HTML template: " . strip_base($newfile) . " (referenced from " . strip_base($file) . ")\n";
+
+ if ($opt_c && !$found_one) {
+ print "W: missing HTML template: " . strip_base($new_file_base) . "{html,json,js} (referenced from " . strip_base($file) . ")\n";
}
}
}
# exit loop if there are no more locales on this line
- ($rc) = ($postmatch =~ /locale->text/);
+ ($rc) = ($postmatch =~ /locale->text | \b t8/x);
if ( ($postmatch =~ />/)
|| (!$found && ($sub_line_no != $line_no) && />/)) {
=head1 NAME
-locales.pl - Collect strings for translation in Lx-Office
+locales.pl - Collect strings for translation in kivitendo
=head1 SYNOPSIS