tomb

the crypto undertaker
git clone git://parazyd.org/tomb.git
Log | Files | Refs | README | LICENSE

generate_translatable_strings.pl (1903B)


      1 use strict;
      2 use warnings;
      3 
      4 my $FILE = '../../tomb';
      5 my $FUNCPATTERN = '_(success|warning|failure|message|print)';
      6 my $STRINGPATTERN = '(".*?[^\\\]")';
      7 
      8 my $date = localtime;
      9 print '
     10 # Tomb - The Crypto Undertaker.
     11 # Copyright (C) 2007-2014 Dyne.org Foundation
     12 # Denis Roio <jaromil@dyne.org>, 2013.
     13 #
     14 #, fuzzy
     15 msgid ""
     16 msgstr ""
     17 "PO-Revision-Date: ', $date, '\n"
     18 "Last-Translator: Denis Roio <jaromil@dyne.org>\n"
     19 "Language: English\n"
     20 "Language-Team: Tomb developers <crypto@lists.dyne.org>\n"
     21 "MIME-Version: 1.0\n"
     22 "Content-Type: text/plain; charset=UTF-8\n"
     23 "Content-Transfer-Encoding: 8bit\n"
     24 
     25 ';
     26 
     27 my @blacklist = ('"--"', '"\\\\000"', '`.*`', '$\(.*\)');
     28 
     29 # Translatable strings that can't be automatically detected yet
     30 my %undetectable = (
     31     124 => '[sudo] Enter password for user ::1 user:: to gain superuser privileges'
     32 );
     33 
     34 open my $handle, $FILE or die "Failed to open $FILE";
     35 my @lines = <$handle>;
     36 close $handle;
     37 
     38 my %seen;
     39 my $index = 0;
     40 my $fold;
     41 my $func;
     42 my $force;
     43 my $str;
     44 
     45 foreach (@lines) {
     46     $index++;
     47     $force = 0;
     48 
     49     # It's a fold title
     50     if (m/^# +\{\{\{ +(.*)$/) {
     51         $fold = $1;
     52         next;
     53     }
     54 
     55     # It's a function name
     56     if (m/^(.*)\(\) *{$/) {
     57         $func = $1;
     58         next;
     59     }
     60 
     61     # Force if it's undetectable
     62     $force = 1 if exists($undetectable{$index});
     63 
     64     # Next if there is no print function
     65     next unless $force or m/$FUNCPATTERN +$STRINGPATTERN/;
     66 
     67     # Get string from the $undetectable hash or via regex
     68     if ($force) {
     69         $str = "\"$undetectable{$index}\"";
     70     }
     71     else {
     72         $str = $2;
     73     }
     74 
     75     # Remove conflicting quotes (\)
     76     $str =~ s/\\\$/\$/g;
     77 
     78     # Next if it was seen before
     79     $seen{$str}++;
     80     next if $seen{$str} > 1;
     81 
     82     # Next if it's blacklisted
     83     next if grep {$str =~ m/$_/} @blacklist;
     84 
     85     print "#: tomb:$fold:$func:$index\n";
     86     print "msgid $str\n";
     87     print "msgstr \"\"\n\n";
     88 }