]> wagnertech.de Git - mfinanz.git/blobdiff - scripts/locales.pl
Überreste von "gifi" entfernen (siehe 0daf163)
[mfinanz.git] / scripts / locales.pl
index cfb85d9a4655bbb0144ab57f90dfb3ab9cc28a16..b6665588abd2ce102ea897c490baa663758f1ba0 100755 (executable)
@@ -10,6 +10,7 @@ use utf8;
 use strict;
 
 use Carp;
 use strict;
 
 use Carp;
+use Cwd;
 use Data::Dumper;
 use English;
 use File::Slurp qw(slurp);
 use Data::Dumper;
 use English;
 use File::Slurp qw(slurp);
@@ -29,6 +30,7 @@ my $debug  = 0;
 
 parse_args();
 
 
 parse_args();
 
+my $locale;
 my $basedir      = "../..";
 my $locales_dir  = ".";
 my $bindir       = "$basedir/bin/mozilla";
 my $basedir      = "../..";
 my $locales_dir  = ".";
 my $bindir       = "$basedir/bin/mozilla";
@@ -36,12 +38,14 @@ my @progdirs     = ( "$basedir/SL" );
 my $dbupdir      = "$basedir/sql/Pg-upgrade";
 my $dbupdir2     = "$basedir/sql/Pg-upgrade2";
 my $menufile     = "menu.ini";
 my $dbupdir      = "$basedir/sql/Pg-upgrade";
 my $dbupdir2     = "$basedir/sql/Pg-upgrade2";
 my $menufile     = "menu.ini";
+my @javascript_dirs = ($basedir .'/js', $basedir .'/templates/webpages');
+my $javascript_output_dir = $basedir .'/js';
 my $submitsearch = qr/type\s*=\s*[\"\']?submit/i;
 our $self        = {};
 our $missing     = {};
 our @lost        = ();
 
 my $submitsearch = qr/type\s*=\s*[\"\']?submit/i;
 our $self        = {};
 our $missing     = {};
 our @lost        = ();
 
-my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit);
+my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit, %jslocale);
 my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER);
 
 init();
 my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER);
 
 init();
@@ -123,6 +127,10 @@ handle_file($_, $dbupdir)  for @dbplfiles;
 handle_file($_, $dbupdir2) for @dbplfiles2;
 scanmenu($_)               for @menufiles;
 
 handle_file($_, $dbupdir2) for @dbplfiles2;
 scanmenu($_)               for @menufiles;
 
+for my $file_name (map({find_files($_)} @javascript_dirs)) {
+  scan_javascript_file($file_name);
+}
+
 # merge entries to translate with entries from files 'missing' and 'lost'
 merge_texts();
 
 # merge entries to translate with entries from files 'missing' and 'lost'
 merge_texts();
 
@@ -134,6 +142,17 @@ generate_file(
   data_sub  => sub { _print_line($_, $self->{texts}{$_}, @_) for sort keys %alllocales },
 );
 
   data_sub  => sub { _print_line($_, $self->{texts}{$_}, @_) for sort keys %alllocales },
 );
 
+open(my $js_file, '>:encoding(utf8)', $javascript_output_dir .'/locale/'. $locale .'.js') || die;
+print $js_file 'namespace("kivi").setupLocale({';
+my $first_entry = 1;
+for my $key (sort(keys(%jslocale))) {
+  print $js_file ((!$first_entry ? ',' : '') ."\n". _double_quote($key) .':'. _double_quote($self->{texts}{$key}));
+  $first_entry = 0;
+}
+print $js_file ("\n");
+print $js_file ('});'."\n");
+close($js_file);
+
   foreach my $text (keys %$missing) {
     if ($locale{$text} || $htmllocale{$text}) {
       unless ($self->{texts}{$text}) {
   foreach my $text (keys %$missing) {
     if ($locale{$text} || $htmllocale{$text}) {
       unless ($self->{texts}{$text}) {
@@ -233,6 +252,9 @@ sub parse_args {
     my $ok  = 0;
     foreach my $dir ("../locale/$arg", "locale/$arg", "../$arg", $arg) {
       next unless -d $dir && -f "$dir/all" && -f "$dir/LANGUAGE";
     my $ok  = 0;
     foreach my $dir ("../locale/$arg", "locale/$arg", "../$arg", $arg) {
       next unless -d $dir && -f "$dir/all" && -f "$dir/LANGUAGE";
+
+      $locale = $arg;
+
       $ok = chdir $dir;
       last;
     }
       $ok = chdir $dir;
       last;
     }
@@ -247,6 +269,9 @@ sub parse_args {
       .   "and no locale directory name was given.\n";
     exit 1;
   }
       .   "and no locale directory name was given.\n";
     exit 1;
   }
+
+  $locale ||=  (grep { $_ } split m:/:, getcwd())[-1];
+  $locale   =~ s/\.+$//;
 }
 
 sub handle_file {
 }
 
 sub handle_file {
@@ -392,7 +417,7 @@ sub scanfile {
       while ($rc) {
         if (/Locale/) {
           unless (/^use /) {
       while ($rc) {
         if (/Locale/) {
           unless (/^use /) {
-            my ($null, $country) = split /,/;
+            my ($null, $country) = split(/,/);
             $country =~ s/^ +[\"\']//;
             $country =~ s/[\"\'].*//;
           }
             $country =~ s/^ +[\"\']//;
             $country =~ s/[\"\'].*//;
           }
@@ -511,7 +536,7 @@ sub scanhtmlfile {
 
       while ($line =~ m/\[\%[^\w]*(\w+)\.\w+\(/g) {
         my $plugin = $1;
 
       while ($line =~ m/\[\%[^\w]*(\w+)\.\w+\(/g) {
         my $plugin = $1;
-        $plugins{needed}->{$plugin} = 1 if (first { $_ eq $plugin } qw(HTML LxERP JavaScript MultiColumnIterator JSON L P));
+        $plugins{needed}->{$plugin} = 1 if (first { $_ eq $plugin } qw(HTML LxERP JavaScript JSON L P));
       }
 
       $plugins{needed}->{T8} = 1 if $line =~ m/\[\%.*\|.*\$T8/;
       }
 
       $plugins{needed}->{T8} = 1 if $line =~ m/\[\%.*\|.*\$T8/;
@@ -586,6 +611,31 @@ sub scanhtmlfile {
   $referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}};
 }
 
   $referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}};
 }
 
+sub scan_javascript_file {
+  my ($file) = @_;
+
+  open(my $fh, $file) || die('can not open file: '. $file);
+
+  while( my $line = readline($fh) ) {
+    while( $line =~ m/
+                    kivi.t8
+                    \s*
+                    \(
+                    \s*
+                    ([\'\"])
+                    (.*?)
+                    (?<!\\)\1
+                    /ixg )
+    {
+      my $text = unescape_template_string($2);
+
+      $jslocale{$text} = 1;
+      $alllocales{$text} = 1;
+    }
+  }
+
+  close($fh);
+}
 sub search_unused_htmlfiles {
   my @unscanned_dirs = ('../../templates/webpages');
 
 sub search_unused_htmlfiles {
   my @unscanned_dirs = ('../../templates/webpages');
 
@@ -619,6 +669,12 @@ sub _single_quote {
   return  "'" . $val .  "'";
 }
 
   return  "'" . $val .  "'";
 }
 
+sub _double_quote {
+  my $val = shift;
+  $val =~ s/(\"|\\$)/\\$1/g;
+  return  '"'. $val .'"';
+}
+
 sub _print_line {
   my $key      = _single_quote(shift);
   my $text     = _single_quote(shift);
 sub _print_line {
   my $key      = _single_quote(shift);
   my $text     = _single_quote(shift);