Revision 224291dd
Von Thomas Heck vor mehr als 11 Jahren hinzugefügt
scripts/locales.pl | ||
---|---|---|
36 | 36 |
my $dbupdir = "$basedir/sql/Pg-upgrade"; |
37 | 37 |
my $dbupdir2 = "$basedir/sql/Pg-upgrade2"; |
38 | 38 |
my $menufile = "menu.ini"; |
39 |
my @javascript_dirs = ($basedir .'/js', $basedir .'/templates/webpages'); |
|
39 | 40 |
my $submitsearch = qr/type\s*=\s*[\"\']?submit/i; |
40 | 41 |
our $self = {}; |
41 | 42 |
our $missing = {}; |
42 | 43 |
our @lost = (); |
43 | 44 |
|
44 |
my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit); |
|
45 |
my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit, %jslocale);
|
|
45 | 46 |
my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER); |
46 | 47 |
|
47 | 48 |
init(); |
... | ... | |
123 | 124 |
handle_file($_, $dbupdir2) for @dbplfiles2; |
124 | 125 |
scanmenu($_) for @menufiles; |
125 | 126 |
|
127 |
for my $file_name (map({find_files($_)} @javascript_dirs)) { |
|
128 |
scan_javascript_file($file_name); |
|
129 |
} |
|
130 |
|
|
126 | 131 |
# merge entries to translate with entries from files 'missing' and 'lost' |
127 | 132 |
merge_texts(); |
128 | 133 |
|
... | ... | |
134 | 139 |
data_sub => sub { _print_line($_, $self->{texts}{$_}, @_) for sort keys %alllocales }, |
135 | 140 |
); |
136 | 141 |
|
142 |
open(my $js_file, '>:encoding(utf8)', $locales_dir .'/js.js') || die; |
|
143 |
print $js_file '{'."\n"; |
|
144 |
my $first_entry = 1; |
|
145 |
for my $key (sort(keys(%jslocale))) { |
|
146 |
print $js_file (!$first_entry ? ',' : '') . _double_quote($key) .':'. _double_quote($self->{texts}{$key}) ."\n"; |
|
147 |
$first_entry = 0; |
|
148 |
} |
|
149 |
print $js_file '}'."\n"; |
|
150 |
close($js_file); |
|
151 |
|
|
137 | 152 |
foreach my $text (keys %$missing) { |
138 | 153 |
if ($locale{$text} || $htmllocale{$text}) { |
139 | 154 |
unless ($self->{texts}{$text}) { |
... | ... | |
385 | 400 |
while ($rc) { |
386 | 401 |
if (/Locale/) { |
387 | 402 |
unless (/^use /) { |
388 |
my ($null, $country) = split /,/;
|
|
403 |
my ($null, $country) = split(/,/);
|
|
389 | 404 |
$country =~ s/^ +[\"\']//; |
390 | 405 |
$country =~ s/[\"\'].*//; |
391 | 406 |
} |
... | ... | |
577 | 592 |
$referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}}; |
578 | 593 |
} |
579 | 594 |
|
595 |
sub scan_javascript_file { |
|
596 |
my ($file) = @_; |
|
597 |
|
|
598 |
open(my $fh, $file) || die('can not open file: '. $file); |
|
599 |
|
|
600 |
while( my $line = readline($fh) ) { |
|
601 |
while( $line =~ m/ |
|
602 |
kivi.t8 |
|
603 |
\s* |
|
604 |
\( |
|
605 |
\s* |
|
606 |
([\'\"]) |
|
607 |
(.*?) |
|
608 |
(?<!\\)\1 |
|
609 |
/ixg ) |
|
610 |
{ |
|
611 |
my $text = unescape_template_string($2); |
|
612 |
|
|
613 |
$jslocale{$text} = 1; |
|
614 |
$alllocales{$text} = 1; |
|
615 |
} |
|
616 |
} |
|
617 |
|
|
618 |
close($fh); |
|
619 |
} |
|
580 | 620 |
sub search_unused_htmlfiles { |
581 | 621 |
my @unscanned_dirs = ('../../templates/webpages'); |
582 | 622 |
|
... | ... | |
610 | 650 |
return "'" . $val . "'"; |
611 | 651 |
} |
612 | 652 |
|
653 |
sub _double_quote { |
|
654 |
my $val = shift; |
|
655 |
$val =~ s/(\"|\\$)/\\$1/g; |
|
656 |
return '"'. $val .'"'; |
|
657 |
} |
|
658 |
|
|
613 | 659 |
sub _print_line { |
614 | 660 |
my $key = _single_quote(shift); |
615 | 661 |
my $text = _single_quote(shift); |
Auch abrufbar als: Unified diff
scripts/locales.pl um JS-Übersetzung erweitert