X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Flocales.pl;h=105ca7caefa8e605c38c84cc6551b466275fa687;hb=36ca259b22d6db98fc7a1bedef95d5f0e618c444;hp=b1927142e1a25af70b22878b1385f70e73e1ac4b;hpb=1b415045be9b397d54937443d2f8e0efa1a336ac;p=kivitendo-erp.git diff --git a/scripts/locales.pl b/scripts/locales.pl index b1927142e..105ca7cae 100755 --- a/scripts/locales.pl +++ b/scripts/locales.pl @@ -10,8 +10,11 @@ use utf8; use strict; BEGIN { - unshift(@INC, 'modules/override'); # Use our own versions of various modules (e.g. YAML). - push (@INC, 'modules/fallback'); # Only use our own versions of modules if there's no system version. + use FindBin; + + unshift(@INC, $FindBin::Bin . '/../modules/override'); # Use our own versions of various modules (e.g. YAML). + push (@INC, $FindBin::Bin . '/..'); + push (@INC, $FindBin::Bin . '/../modules/fallback'); # Only use our own versions of modules if there's no system version. } use Carp; @@ -25,6 +28,10 @@ use IO::Dir; use List::MoreUtils qw(apply); use List::Util qw(first); use Pod::Usage; +use YAML (); +use YAML::Loader (); # YAML tries to load Y:L at runtime, but can't find it after we chdir'ed +use SL::DBUpgrade2; +use SL::System::Process; $OUTPUT_AUTOFLUSH = 1; @@ -41,7 +48,7 @@ my $basedir = "../.."; my $locales_dir = "."; my $bindir = "$basedir/bin/mozilla"; my @progdirs = ( "$basedir/SL" ); -my @menufiles = <${basedir}/menus/*.ini>; +my @menufiles = glob("${basedir}/menus/*/*"); my @javascript_dirs = ($basedir .'/js', $basedir .'/templates/webpages'); my $javascript_output_dir = $basedir .'/js'; my $submitsearch = qr/type\s*=\s*[\"\']?submit/i; @@ -50,7 +57,7 @@ our $missing = {}; our @lost = (); my %ignore_unused_templates = ( - map { $_ => 1 } qw(ct/testpage.html generic/autocomplete.html oe/periodic_invoices_email.txt part/testpage.html t/render.html t/render.js task_server/failure_notification_email.txt + map { $_ => 1 } qw(ct/testpage.html oe/periodic_invoices_email.txt part/testpage.html t/render.html t/render.js task_server/failure_notification_email.txt failed_background_jobs_report/email.txt) ); @@ -98,13 +105,6 @@ push @progfiles, map { m:^(.+)/([^/]+)$:; [ $2, $1 ] } grep { /\.pm$/ } map { fi # put customized files into @customfiles my %dir_h; -if ($opt_n) { - @customfiles = (); -} else { - tie %dir_h, 'IO::Dir', $basedir; - push @menufiles, map { "$basedir/$_" } grep { /.*_menu.ini$/ } keys %dir_h; -} - my @dbplfiles; foreach my $sub_dir ("Pg-upgrade2", "Pg-upgrade2-auth") { my $dir = "$basedir/sql/$sub_dir"; @@ -116,6 +116,18 @@ foreach my $sub_dir ("Pg-upgrade2", "Pg-upgrade2-auth") { if (-f "$locales_dir/all") { require "$locales_dir/all"; } +# load custom translation (more_texts) +for my $file (glob("${locales_dir}/more/*")) { + if (open my $in, "<", "$file") { + local $/ = undef; + my $code = <$in>; + eval($code); + close($in); + $self->{more_texts_temp}{$_} = $self->{more_texts}{$_} for keys %{ $self->{more_texts} }; + } +} +$self->{more_texts} = delete $self->{more_texts_temp}; + if (-f "$locales_dir/missing") { require "$locales_dir/missing" ; unlink "$locales_dir/missing"; @@ -130,6 +142,7 @@ my %old_texts = %{ $self->{texts} || {} }; handle_file(@{ $_ }) for @progfiles; handle_file(@{ $_ }) for @dbplfiles; scanmenu($_) for @menufiles; +scandbupgrades(); for my $file_name (grep { /\.(?:js|html)$/i } map({find_files($_)} @javascript_dirs)) { scan_javascript_file($file_name); @@ -167,7 +180,8 @@ close($js_file); # calc and generate missing -my @new_missing = grep { !$self->{texts}{$_} } sort keys %alllocales; +# don't add missing ones if we have a translation in more_texts +my @new_missing = grep { !$self->{more_texts}{$_} && !$self->{texts}{$_} } sort keys %alllocales; if (@new_missing) { if ($opt_c) { @@ -520,24 +534,31 @@ sub scanfile { sub scanmenu { my $file = shift; - my $fh = new FileHandle; - open $fh, '<:encoding(utf8)', $file or die "$! : $file"; + my $menu = YAML::LoadFile($file); - my @a = grep m/^\[/, <$fh>; - close($fh); + for my $node (@$menu) { + # possible for override files + next unless exists $node->{name}; + + $locale{$node->{name}} = 1; + $alllocales{$node->{name}} = 1; + $cached{$file}{all}{$node->{name}} = 1; + } +} + +sub scandbupgrades { + # we only need to do this for auth atm, because only auth scripts can include new rights, which are translateable + my $auth = 1; - # strip [] - grep { s/(\[|\])//g } @a; + my $dbu = SL::DBUpgrade2->new(auth => $auth, path => SL::System::Process->exe_dir . '/sql/Pg-upgrade2-auth'); - foreach my $item (@a) { - my @b = split /--/, $item; - foreach my $string (@b) { - chomp $string; + for my $upgrade ($dbu->sort_dbupdate_controls) { + for my $string (@{ $upgrade->{locales} || [] }) { $locale{$string} = 1; $alllocales{$string} = 1; + $cached{$upgrade->{tag}}{all}{$string} = 1; } } - } sub unescape_template_string { @@ -611,7 +632,7 @@ sub scanhtmlfile { } while ($line =~ m/\[\% # Template-Start-Tag - [\-~#]? # Whitespace-Unterdrückung + [\-~#]* # Whitespace-Unterdrückung \s* # Optional beliebig viele Whitespace (?: # Die erkannten Template-Direktiven PROCESS @@ -780,7 +801,7 @@ Be more verbose. =head1 DESCRIPTION -This script collects strings from Perl files, the menu.ini file and +This script collects strings from Perl files, the menu files and HTML templates and puts them into the file "all" for translation. =cut