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