Auftrags-Controller: Einheiten per Select ändern können und sellprice anpassen.
[kivitendo-erp.git] / scripts / locales.pl
index eb1d81b..2c31f87 100755 (executable)
@@ -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