From 3e0a049e40f2d68ed4d5f7c623afed5e85b8c017 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 23 Jun 2010 13:34:36 +0200 Subject: [PATCH] locales.pl strict machen -- Teil 1 Conflicts: locale/de/locales.pl --- locale/de/locales.pl | 150 +++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 71 deletions(-) diff --git a/locale/de/locales.pl b/locale/de/locales.pl index c7112eb1d..09b88cf9d 100755 --- a/locale/de/locales.pl +++ b/locale/de/locales.pl @@ -6,27 +6,35 @@ # this version of locles processes not only all required .pl files # but also all parse_html_templated files. +use strict; + use Data::Dumper; +use English; use FileHandle; use Getopt::Long; use List::Util qw(first); use POSIX; use Pod::Usage; -$| = 1; +$OUTPUT_AUTOFLUSH = 1; + +my $basedir = "../.."; +my $bindir = "$basedir/bin/mozilla"; +my $dbupdir = "$basedir/sql/Pg-upgrade"; +my $dbupdir2 = "$basedir/sql/Pg-upgrade2"; +my $menufile = "menu.ini"; +my $submitsearch = qr/type\s*=\s*[\"\']?submit/i; -$basedir = "../.."; -$bindir = "$basedir/bin/mozilla"; -$dbupdir = "$basedir/sql/Pg-upgrade"; -$dbupdir2 = "$basedir/sql/Pg-upgrade2"; -$menufile = "menu.ini"; -$submitsearch = qr/type\s*=\s*[\"\']?submit/i; +my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit, %subrt); -%referenced_html_files = (); +my $count = 0; +my $notext = 0; -my $opt_v = 0; -my $opt_n = 0; -my $opt_c = 0; +my $debug = 0; + +my $opt_v = 0; +my $opt_n = 0; +my $opt_c = 0; sub parse_args { my ($help, $man); @@ -51,12 +59,13 @@ sub parse_args { parse_args(); opendir DIR, "$bindir" or die "$!"; -@progfiles = grep { /\.pl$/ && !/(_|^\.)/ } readdir DIR; +my @progfiles = grep { /\.pl$/ && !/(_|^\.)/ } readdir DIR; seekdir DIR, 0; -@customfiles = grep /_/, readdir DIR; +my @customfiles = grep /_/, readdir DIR; closedir DIR; # put customized files into @customfiles +my @menufiles; if ($opt_n) { @customfiles = (); @@ -69,19 +78,32 @@ if ($opt_n) { } opendir DIR, $dbupdir or die "$!"; -@dbplfiles = grep { /\.pl$/ } readdir DIR; +my @dbplfiles = grep { /\.pl$/ } readdir DIR; closedir DIR; opendir DIR, $dbupdir2 or die "$!"; -@dbplfiles2 = grep { /\.pl$/ } readdir DIR; +my @dbplfiles2 = grep { /\.pl$/ } readdir DIR; closedir DIR; # slurp the translations in +my $self = {}; +my $missing = {}; +my @missing = (); +my @lost = (); + if (-f 'all') { - require "all"; + require 'all'; +} +if (-f 'missing') { + require 'missing' ; + unlink 'missing'; +} +if (-f 'lost') { + require 'lost'; + unlink 'lost'; } -my %old_texts = %{ $self->{texts} }; +my %old_texts = %{ $self->{texts} || {} }; # Read HTML templates. #%htmllocale = (); @@ -97,14 +119,14 @@ map({ handle_file($_, $dbupdir2); } @dbplfiles2); sub handle_file { my ($file, $dir) = @_; print "\n$file" if $opt_v; - %locale = (); - %submit = (); - %subrt = (); + my %locale = (); + my %submit = (); + my %subrt = (); &scanfile("$dir/$file"); # scan custom_{module}.pl or {login}_{module}.pl files - foreach $customfile (@customfiles) { + foreach my $customfile (@customfiles) { if ($customfile =~ /_$file/) { if (-f "$dir/$customfile") { &scanfile("$dir/$customfile"); @@ -114,13 +136,13 @@ sub handle_file { # if this is the menu.pl file if ($file eq 'menu.pl') { - foreach $item (@menufiles) { + foreach my $item (@menufiles) { &scanmenu("$basedir/$item"); } } if ($file eq 'menunew.pl') { - foreach $item (@menufiles) { + foreach my $item (@menufiles) { &scanmenu("$basedir/$item"); print "." if $opt_v; } @@ -128,10 +150,7 @@ sub handle_file { $file =~ s/\.pl//; - eval { require 'missing'; }; - unlink 'missing'; - - foreach $text (keys %$missing) { + foreach my $text (keys %$missing) { if ($locale{$text} || $htmllocale{$text}) { unless ($self->{texts}{$text}) { $self->{texts}{$text} = $missing->{$text}; @@ -146,18 +165,14 @@ sub handle_file { $self->{texts} = { |; - foreach $key (sort keys %locale) { - if ($self->{texts}{$key}) { - $text = $self->{texts}{$key}; - } else { - $text = $key; - } - $text =~ s/'/\\'/g; - $text =~ s/\\$/\\\\/; + foreach my $key (sort keys %locale) { + my $text = $self->{texts}{$key} || $key; + $text =~ s/'/\\'/g; + $text =~ s/\\$/\\\\/; - $keytext = $key; - $keytext =~ s/'/\\'/g; - $keytext =~ s/\\$/\\\\/; + my $keytext = $key; + $keytext =~ s/'/\\'/g; + $keytext =~ s/\\$/\\\\/; print FH qq| '$keytext'| . (' ' x (27 - length($keytext))) @@ -169,26 +184,26 @@ $self->{texts} = { $self->{subs} = { |; - foreach $key (sort keys %subrt) { - $text = $key; - $text =~ s/'/\\'/g; - $text =~ s/\\$/\\\\/; + foreach my $key (sort keys %subrt) { + my $text = $key; + $text =~ s/'/\\'/g; + $text =~ s/\\$/\\\\/; print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '$text',\n|; } - foreach $key (sort keys %submit) { - $text = ($self->{texts}{$key}) ? $self->{texts}{$key} : $key; - $text =~ s/'/\\'/g; - $text =~ s/\\$/\\\\/; + foreach my $key (sort keys %submit) { + my $text = ($self->{texts}{$key}) ? $self->{texts}{$key} : $key; + $text =~ s/'/\\'/g; + $text =~ s/\\$/\\\\/; - $english_sub = $key; - $english_sub =~ s/'/\\'/g; - $english_sub =~ s/\\$/\\\\/; - $english_sub = lc $key; + my $english_sub = $key; + $english_sub =~ s/'/\\'/g; + $english_sub =~ s/\\$/\\\\/; + $english_sub = lc $key; - $translated_sub = lc $text; - $english_sub =~ s/( |-|,)/_/g; - $translated_sub =~ s/( |-|,)/_/g; + my $translated_sub = lc $text; + $english_sub =~ s/( |-|,)/_/g; + $translated_sub =~ s/( |-|,)/_/g; print FH qq| '$translated_sub'| . (' ' x (27 - length($translated_sub))) . qq| => '$english_sub',\n|; @@ -221,8 +236,8 @@ print FH q|#!/usr/bin/perl $self->{texts} = { |; -foreach $key (sort keys %alllocales) { - $text = $self->{texts}{$key}; +foreach my $key (sort keys %alllocales) { + my $text = $self->{texts}{$key}; $count++; @@ -257,7 +272,7 @@ if (@missing) { $missing = { |; - foreach $text (@missing) { + foreach my $text (@missing) { print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '',\n|; } @@ -270,14 +285,7 @@ $missing = { } -@lost = (); - -if (-f "lost") { - require "lost"; - unlink "lost"; -} - -while (($text, $translation) = each %old_texts) { +while (my ($text, $translation) = each %old_texts) { next if ($alllocales{$text}); push @lost, { 'text' => $text, 'translation' => $translation }; @@ -292,7 +300,7 @@ if (scalar @lost) { "# This file will be auto-generated by locales.pl. Do not edit it.\n\n" . "\@lost = (\n"; - foreach $entry (@lost) { + foreach my $entry (@lost) { $entry->{text} =~ s/\'/\\\'/g; $entry->{translation} =~ s/\'/\\\'/g; print FH " { 'text' => '$entry->{text}', 'translation' => '$entry->{translation}' },\n"; @@ -303,9 +311,9 @@ if (scalar @lost) { } open(FH, "LANGUAGE"); -@language = ; +my @language = ; close(FH); -$trlanguage = $language[0]; +my $trlanguage = $language[0]; chomp $trlanguage; if ($opt_c) { @@ -313,7 +321,7 @@ if ($opt_c) { search_translated_htmlfiles_wo_master(); } -$per = sprintf("%.1f", ($count - $notext) / $count * 100); +my $per = sprintf("%.1f", ($count - $notext) / $count * 100); print "\n$trlanguage - ${per}%"; print " - $notext/$count missing" if $notext; print "\n"; @@ -430,7 +438,7 @@ sub scanfile { # is this a sub ? if (/^sub /) { next if ($dont_include_subs); - ($null, $subrt) = split / +/; + my $subrt = (split / +/)[1]; # $subrt{$subrt} = 1; $cached{$file}{subr}{$subrt} = 1; next; @@ -525,8 +533,8 @@ sub scanmenu { grep { s/(\[|\])//g } @a; foreach my $item (@a) { - @b = split /--/, $item; - foreach $string (@b) { + my @b = split /--/, $item; + foreach my $string (@b) { chomp $string; $locale{$string} = 1; $alllocales{$string} = 1; -- 2.20.1