my $opt_v = 0;
my $opt_n = 0;
my $opt_c = 0;
-my $lang;
my $debug = 0;
parse_args();
-my $basedir = ".";
-my $locales_dir = "$basedir/locale/$lang";
+my $basedir = "../..";
+my $locales_dir = ".";
my $bindir = "$basedir/bin/mozilla";
my $dbupdir = "$basedir/sql/Pg-upgrade";
my $dbupdir2 = "$basedir/sql/Pg-upgrade2";
unlink "$locales_dir/lost";
}
+my $charset = slurp("$locales_dir/charset") || 'utf-8';
+chomp $charset;
+
my %old_texts = %{ $self->{texts} || {} };
map({ handle_file($_, $bindir); } @progfiles);
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;
},
);
}
# 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
}
exit 0;
}
- $lang = shift @ARGV || croak 'need language code as argument';
+ if (@ARGV) {
+ my $arg = shift @ARGV;
+ my $ok = 0;
+ foreach my $dir ("../locale/$arg", "locale/$arg", "../$arg", $arg) {
+ next unless -d $dir && -f "$dir/all" && -f "$dir/LANGUAGE";
+ $ok = chdir $dir;
+ last;
+ }
+
+ if (!$ok) {
+ print "The locale directory '$arg' could not be found.\n";
+ exit 1;
+ }
+
+ } elsif (!-f 'all' || !-f 'LANGUAGE') {
+ print "locales.pl was not called from a locale/* subdirectory,\n"
+ . "and no locale directory name was given.\n";
+ exit 1;
+ }
}
sub handle_file {
open my $fh, '>', $file or die "$! : $file";
- print $fh "#!/usr/bin/perl\n\n";
+ print $fh "#!/usr/bin/perl\n# -*- coding: $charset; -*-\n# vim: fenc=$charset\n\n";
print $fh $header, "\n" if $header;
print $fh "$data_name = $delim[0]\n" if $data_name;
close $fh;
}
+sub slurp {
+ my $file = shift;
+ do { local ( @ARGV, $/ ) = $file; <> }
+}
+
__END__
=head1 NAME
=head1 SYNOPSIS
-locales.pl [options]
+locales.pl [options] lang_code
Options:
-n, --no-custom-files Do not process files whose name contains "_"
=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