X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=scripts%2Flocales.pl;h=16f2b3e850062defe8fed3f83b84b7eb5b2eefff;hb=fa438d5021131074e3e10e71eb8f31887fa69f9d;hp=f2bf87000e4f408fca5aa1643bda0da6155e3583;hpb=984d50b3e31de17611c296885b151dee7198a47f;p=kivitendo-erp.git diff --git a/scripts/locales.pl b/scripts/locales.pl index f2bf87000..16f2b3e85 100755 --- a/scripts/locales.pl +++ b/scripts/locales.pl @@ -6,6 +6,7 @@ # this version of locles processes not only all required .pl files # but also all parse_html_templated files. +use utf8; use strict; use Data::Dumper; @@ -30,6 +31,7 @@ parse_args(); my $basedir = "../.."; my $locales_dir = "."; my $bindir = "$basedir/bin/mozilla"; +my @progdirs = ( "$basedir/SL/Template/Plugin" ); my $dbupdir = "$basedir/sql/Pg-upgrade"; my $dbupdir2 = "$basedir/sql/Pg-upgrade2"; my $menufile = "menu.ini"; @@ -41,11 +43,17 @@ my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER); init(); opendir DIR, "$bindir" or die "$!"; -my @progfiles = grep { /\.pl$/ && !/(_custom|^\.)/ } readdir DIR; +my @progfiles = map { [ $_, $bindir ] } grep { /\.pl$/ && !/(_custom|^\.)/ } readdir DIR; seekdir DIR, 0; my @customfiles = grep /_custom/, readdir DIR; closedir DIR; +foreach my $dir (@progdirs) { + opendir DIR, $dir or die "$!"; + push @progfiles, map { [ $_, $dir ] } grep { /\.pm$/ } readdir DIR; + closedir DIR; +} + # put customized files into @customfiles my @menufiles; @@ -85,9 +93,12 @@ if (-f "$locales_dir/lost") { unlink "$locales_dir/lost"; } +my $charset = slurp("$locales_dir/charset") || 'utf-8'; +chomp $charset; + my %old_texts = %{ $self->{texts} || {} }; -map({ handle_file($_, $bindir); } @progfiles); +map({ handle_file(@{ $_ }); } @progfiles); map({ handle_file($_, $dbupdir); } @dbplfiles); map({ handle_file($_, $dbupdir2); } @dbplfiles2); @@ -125,7 +136,7 @@ if (scalar @lost) { delim => '()', data_name => '@lost', data_sub => sub { - _print_line($_->{text}, $_->{translation}, @_, template => " { 'text' => %s, 'translation' => %s },") for @lost; + _print_line($_->{text}, $_->{translation}, @_, template => " { 'text' => %s, 'translation' => %s },\n") for @lost; }, ); } @@ -157,8 +168,8 @@ EOL # add the missing texts and run locales.pl to rebuild EOL $LOST_HEADER = <{$plugin} = 1 if (first { $_ eq $plugin } qw(HTML LxERP JavaScript MultiColumnIterator)); + $plugins{needed}->{$plugin} = 1 if (first { $_ eq $plugin } qw(HTML LxERP JavaScript MultiColumnIterator L)); } while ($line =~ m/(?: # Start von Variante 1: LxERP.t8('...'); ohne darumliegende [% ... %]-Tags (LxERP\.t8)\( # LxERP.t8( ::Parameter $1:: - ([\'\"]) # Anfang des zu übersetzenden Strings ::Parameter $2:: - (.*?) # Der zu übersetzende String ::Parameter $3:: - (?', $file or die "$! : $file"; + open my $fh, '>:encoding(utf8)', $file or die "$! : $file"; - print $fh "#!/usr/bin/perl\n\n"; + $charset =~ s/\r?\n//g; + my $emacs_charset = lc $charset; + + print $fh "#!/usr/bin/perl\n# -*- coding: $emacs_charset; -*-\n# vim: fenc=$charset\n\nuse utf8;\n\n"; print $fh $header, "\n" if $header; print $fh "$data_name = $delim[0]\n" if $data_name; @@ -608,6 +622,11 @@ sub generate_file { close $fh; } +sub slurp { + my $file = shift; + do { local ( @ARGV, $/ ) = $file; <> } +} + __END__ =head1 NAME @@ -616,7 +635,7 @@ locales.pl - Collect strings for translation in Lx-Office =head1 SYNOPSIS -locales.pl [options] +locales.pl [options] lang_code Options: -n, --no-custom-files Do not process files whose name contains "_" @@ -647,7 +666,6 @@ Be more verbose. =head1 DESCRIPTION This script collects strings from Perl files, the menu.ini file and -HTML templates and puts them into the file "all" for translation. It -also distributes those translations back to the individual files. +HTML templates and puts them into the file "all" for translation. =cut