X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Flocales.pl;h=2c31f87b35647d9ba6314c9c5517f5dd7968799c;hb=refs%2Fheads%2Forder_controller;hp=eb1d81b676c1c37316c0afb6c7c2a4d51487fe93;hpb=8c4f656c35da0888f5c19438064bd5c76b41c875;p=kivitendo-erp.git diff --git a/scripts/locales.pl b/scripts/locales.pl index eb1d81b67..2c31f87b3 100755 --- a/scripts/locales.pl +++ b/scripts/locales.pl @@ -22,8 +22,12 @@ use File::Slurp qw(slurp); use FileHandle; use Getopt::Long; 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; $OUTPUT_AUTOFLUSH = 1; @@ -40,7 +44,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; @@ -97,13 +101,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"; @@ -129,6 +126,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); @@ -180,9 +178,11 @@ if (@new_missing) { if ($opt_f) { for my $string (@new_missing) { print "new string '$string' in files:\n"; - for my $file (keys %cached) { - print " $file", $/ if $cached{$file}{all}{$string}; - } + print join "", + map { " $_\n" } + apply { s{^(?:\.\./)+}{} } + grep { $cached{$_}{all}{$string} } + keys %cached; } } @@ -517,24 +517,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}; - # strip [] - grep { s/(\[|\])//g } @a; + $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; - foreach my $item (@a) { - my @b = split /--/, $item; - foreach my $string (@b) { - chomp $string; + my $dbu = SL::DBUpgrade2->new(auth => $auth, path => '../../sql/Pg-upgrade2-auth'); + + 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 { @@ -608,7 +615,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 @@ -777,7 +784,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