CSV-Export mit UTF-8 als Encoding gefixt
[kivitendo-erp.git] / scripts / locales.pl
index f2bf870..ff2cab3 100755 (executable)
@@ -85,6 +85,9 @@ 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);
@@ -125,7 +128,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 +160,8 @@ EOL
 # add the missing texts and run locales.pl to rebuild
 EOL
   $LOST_HEADER  = <<EOL;
-# The last 50 texts that have been removed.
-# This file will be auto-generated by locales.pl. Do not edit it.
+# The last 50 text strings, that have been removed.
+# This file has been auto-generated by locales.pl. Please don't edit!
 EOL
 }
 
@@ -471,7 +474,7 @@ sub scanhtmlfile {
 
       while ($line =~ m/\[\%[^\w]*(\w+)\.\w+\(/g) {
         my $plugin = $1;
-        $plugins{needed}->{$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
@@ -573,7 +576,7 @@ sub strip_base {
 
 sub _single_quote {
   my $val = shift;
-  $val =~ s/('|\\$)/\\$1/g;
+  $val =~ s/(\'|\\$)/\\$1/g;
   return  "'" . $val .  "'";
 }
 
@@ -598,7 +601,9 @@ sub generate_file {
 
   open my $fh, '>', $file or die "$! : $file";
 
-  print $fh "#!/usr/bin/perl\n\n";
+  my $emacs_charset = lc $charset;
+
+  print $fh "#!/usr/bin/perl\n# -*- coding: $emacs_charset; -*-\n# vim: fenc=$charset\n\n";
   print $fh $header, "\n" if $header;
   print $fh "$data_name = $delim[0]\n" if $data_name;
 
@@ -608,6 +613,11 @@ sub generate_file {
   close $fh;
 }
 
+sub slurp {
+  my $file = shift;
+  do { local ( @ARGV, $/ ) = $file; <> }
+}
+
 __END__
 
 =head1 NAME
@@ -616,7 +626,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 +657,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