Changeset 153976 in webkit


Ignore:
Timestamp:
Aug 12, 2013 10:53:05 PM (11 years ago)
Author:
mitz@apple.com
Message:

extract-localizable-strings doesn't know how to verify an existing strings file
https://bugs.webkit.org/show_bug.cgi?id=119704

Reviewed by Darin Adler.

  • Scripts/extract-localizable-strings: Added an --exceptions option for specifying the

exceptions file, changing the way “no exceptions file” is expressed from passing “-” as the
exceptions file name to omitting the --exceptions option. Added a --skip option, changing
the way directories to skip are specified from prefixing the directory with a “-” to
specifying it with --skip.
Finally, added a --verify option. When specified, the strings file is not written to, but
instead read in and checked for consistency with the comments, keys and values derived from
the source files and the exceptions file. Missing keys, unused keys, mismatching values and
mismatching comments are reported as errors.

  • Scripts/update-webkit-localizable-strings: Updated for the new way of specifying

directories to skip and no exceptions file.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r153973 r153976  
     12013-08-12  Dan Bernstein  <mitz@apple.com>
     2
     3        extract-localizable-strings doesn't know how to verify an existing strings file
     4        https://bugs.webkit.org/show_bug.cgi?id=119704
     5
     6        Reviewed by Darin Adler.
     7
     8        * Scripts/extract-localizable-strings: Added an --exceptions option for specifying the
     9        exceptions file, changing the way “no exceptions file” is expressed from passing “-” as the
     10        exceptions file name to omitting the --exceptions option. Added a --skip option, changing
     11        the way directories to skip are specified from prefixing the directory with a “-” to
     12        specifying it with --skip.
     13        Finally, added a --verify option. When specified, the strings file is not written to, but
     14        instead read in and checked for consistency with the comments, keys and values derived from
     15        the source files and the exceptions file. Missing keys, unused keys, mismatching values and
     16        mismatching comments are reported as errors.
     17        * Scripts/update-webkit-localizable-strings: Updated for the new way of specifying
     18        directories to skip and no exceptions file.
     19
    1202013-08-12  Alexey Proskuryakov  <ap@apple.com>
    221
  • trunk/Tools/Scripts/extract-localizable-strings

    r153348 r153976  
    4444
    4545use strict;
     46use Getopt::Long;
    4647no warnings 'deprecated';
    4748
     
    5051my %isDebugMacro = ( ASSERT_WITH_MESSAGE => 1, LOG_ERROR => 1, ERROR => 1, NSURL_ERROR => 1, FATAL => 1, LOG => 1, LOG_WARNING => 1, UI_STRING_LOCALIZE_LATER => 1, UI_STRING_LOCALIZE_LATER_KEY => 1, LPCTSTR_UI_STRING_LOCALIZE_LATER => 1, UNLOCALIZED_STRING => 1, UNLOCALIZED_LPCTSTR => 1, dprintf => 1, NSException => 1, NSLog => 1, printf => 1 );
    5152
    52 @ARGV >= 2 or die "Usage: extract-localizable-strings <exceptions file> <file to update> [ directory... ]\nDid you mean to run update-webkit-localizable-strings instead?\n";
    53 
    54 my $exceptionsFile = shift @ARGV;
    55 -f $exceptionsFile or die "Couldn't find exceptions file $exceptionsFile\n" unless $exceptionsFile eq "-";
     53my $verify;
     54my $exceptionsFile;
     55my @directoriesToSkip = ();
     56
     57my %options = (
     58    'verify' => \$verify,
     59    'exceptions=s' => \$exceptionsFile,
     60    'skip=s' => \@directoriesToSkip,
     61);
     62
     63GetOptions(%options);
     64
     65@ARGV >= 2 or die "Usage: extract-localizable-strings [--verify] [--exceptions <exceptions file>] <file to update> [--skip directory | directory]...\nDid you mean to run update-webkit-localizable-strings instead?\n";
     66
     67-f $exceptionsFile or die "Couldn't find exceptions file $exceptionsFile\n" unless !defined $exceptionsFile;
    5668
    5769my $fileToUpdate = shift @ARGV;
    5870-f $fileToUpdate or die "Couldn't find file to update $fileToUpdate\n";
    5971
    60 my $warnAboutUnlocalizedStrings = $exceptionsFile ne "-";
     72my $warnAboutUnlocalizedStrings = defined $exceptionsFile;
    6173
    6274my @directories = ();
    63 my @directoriesToSkip = ();
    6475if (@ARGV < 1) {
    6576    push(@directories, ".");
    6677} else {
    6778    for my $dir (@ARGV) {
    68         if ($dir =~ /^-(.*)$/) {
    69             push @directoriesToSkip, $1;
    70         } else {
    71             push @directories, $dir;
    72         }
     79        push @directories, $dir;
    7380    }
    7481}
     
    8491my %usedException;
    8592
    86 if ($exceptionsFile ne "-" && open EXCEPTIONS, $exceptionsFile) {
     93if (defined $exceptionsFile && open EXCEPTIONS, $exceptionsFile) {
    8794    while (<EXCEPTIONS>) {
    8895        chomp;
     
    380387}
    381388
    382 # Write out the strings file as UTF-8
    383389if (-e "$fileToUpdate") {
    384     open STRINGS, ">", "$fileToUpdate" or die;
    385     print STRINGS $localizedStrings;
    386     close STRINGS;
     390    if (!$verify) {
     391        # Write out the strings file as UTF-8
     392        open STRINGS, ">", "$fileToUpdate" or die;
     393        print STRINGS $localizedStrings;
     394        close STRINGS;
     395    } else {
     396        open STRINGS, $fileToUpdate or die;
     397
     398        my $lastComment;
     399
     400        while (<STRINGS>) {
     401            chomp;
     402
     403            next if (/^\s*$/);
     404
     405            if (/^\/\* (.*) \*\/$/) {
     406                $lastComment = $1;
     407            } elsif (/^"((?:[^\\]|\\[^"])*)"\s*=\s*"((?:[^\\]|\\[^"])*)";$/) #
     408            {
     409                my $string = delete $stringByKey{$1};
     410                if (!defined $string) {
     411                    print "error: $fileToUpdate contains unused key \"$1\" (preceding comment: /* $lastComment */)\n";
     412                    $sawError = 1;
     413                } else {
     414                    if (!($string eq $2)) {
     415                        print "error: $fileToUpdate contains unexpected value \"$2\" for key \"$1\" (expected \"$string\")\n";
     416                        $sawError = 1;
     417                    }
     418                    if (!($lastComment eq $commentByKey{$1})) {
     419                        print "error: $fileToUpdate contains unexpected comment /* $lastComment */ for key \"$1\" (expected /* $commentByKey{$1} */)\n";
     420                    }
     421                }
     422            } else {
     423                print "error: $fileToUpdate contains line with unexpected format: $_\n";
     424                $sawError = 1;
     425            }
     426        }
     427
     428        for my $missing (keys %stringByKey) {
     429            print "error: $fileToUpdate is missing key \"$missing\"\n";
     430            $sawError = 1;
     431        }
     432
     433        if ($sawError) {
     434            print "\nerror: $fileToUpdate is not up to date.\n";
     435            exit 1;
     436        }
     437    }
    387438} else {
    388439    print "$fileToUpdate does not exist\n";
  • trunk/Tools/Scripts/update-webkit-localizable-strings

    r152870 r153976  
    3636
    3737# WebKit and WebKit2 strings go into WebCore's Localizable.strings.
    38 my @webKitDirectoriesToScan = ("Source/WebCore", "Source/WebKit/mac", "Source/WebKit/win", "Source/WebKit2", "-Source/WebCore/icu", "-Source/WebKit/mac/icu");
     38my @webKitDirectoriesToScan = ("Source/WebCore", "Source/WebKit/mac", "Source/WebKit/win", "Source/WebKit2", "--skip", "Source/WebCore/icu", "--skip", "Source/WebKit/mac/icu");
    3939my @webInspectorUIDirectoriesToScan = ("Source/WebInspectorUI/UserInterface");
    4040
     
    4646chdirWebKit();
    4747
    48 system "Tools/Scripts/extract-localizable-strings", "-", $webCoreFileToUpdate, @webKitDirectoriesToScan;
     48system "Tools/Scripts/extract-localizable-strings", $webCoreFileToUpdate, @webKitDirectoriesToScan;
    4949system "Tools/Scripts/extract-localizable-js-strings", $webInspectorUIFileToUpdate, @webInspectorUIDirectoriesToScan;
Note: See TracChangeset for help on using the changeset viewer.