Skip to content

Latest commit

 

History

History
executable file
·
189 lines (164 loc) · 5.45 KB

po2localization.pl

File metadata and controls

executable file
·
189 lines (164 loc) · 5.45 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl -w
use warnings;
use strict;
use Encode qw( decode_utf8 );
# Fixes unicode dumping to stdio...hopefully you have a utf-8 terminal by now.
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
my $now = `date '+%Y-%m-%d %H:%M:%S%z'`;
chomp($now);
Jul 29, 2008
Jul 29, 2008
15
16
my $hgver = `hg tip --template 'hg-{rev}:{node|short}' 2>/dev/null`;
$hgver = '???' if ($hgver eq '');
17
18
19
20
21
22
my %languages;
my %comments;
my %msgstrs;
my @strings;
my $saw_template = 0;
Feb 29, 2008
Feb 29, 2008
23
24
25
my $exportdate = '';
my $generator = '';
26
27
28
29
30
foreach (@ARGV) {
my $fname = $_;
my $template = /\.pot\Z/;
open(POIO, '<', $fname) or die("Failed to open $_: $!\n");
Mar 1, 2008
Mar 1, 2008
31
binmode(POIO, ":utf8");
32
33
34
35
36
37
38
39
if ($template) {
die("multiple .pot files specified\n") if ($saw_template);
$saw_template = 1;
}
my $comment = '';
my $currentlang = '';
Jun 18, 2015
Jun 18, 2015
40
my $fuzzy;
41
42
43
44
45
46
47
while (<POIO>) {
chomp;
s/\A\s+//;
s/\s+\Z//;
next if ($_ eq '');
Feb 29, 2008
Feb 29, 2008
48
49
50
51
52
53
if (s/\A\#\.\s*(.*)\Z/$1/) {
if ($template) {
my $txt = $_;
$txt = " $txt" if ($comment ne '');
$comment .= " -- $txt\n";
}
54
55
next;
}
Jun 18, 2015
Jun 18, 2015
56
57
58
59
if (/\A\#,.*\bfuzzy\b/) {
$fuzzy = 1;
next;
}
60
61
62
63
next if /\A\#/;
if (s/msgid\s*\"(.*?)\"\Z/$1/) {
Mar 5, 2008
Mar 5, 2008
64
if (($_ eq '') and ($currentlang eq '')) { # initial string.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
while (<POIO>) { # Skip most of the metadata.
chomp;
s/\A\s+//;
s/\s+\Z//;
last if ($_ eq '');
if (/\A\"Language-Team: (.*?) \<(.*?)\@.*?\>\\n"\Z/) {
$currentlang = $2;
if (defined $languages{$currentlang}) {
die("Same language twice: $currentlang\n");
} elsif ($currentlang eq 'en') {
die("Found an 'en' translation.\n");
} elsif ($currentlang eq 'en_US') {
die("Found an 'en_US' translation.\n");
}
$languages{$currentlang} = $1 if (not $template);
Feb 29, 2008
Feb 29, 2008
80
} elsif (s/\A\"(X-Launchpad-Export-Date: .*?)\\n\"/$1/) {
81
$exportdate = $_ if ($template);
Feb 29, 2008
Feb 29, 2008
82
83
} elsif (s/\A"(X-Generator: .*?)\\n\"\Z/$1/) {
$generator = $_ if ($template);
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
}
}
} elsif ($currentlang eq '') {
die("No current language!\n");
} else { # new string
my $msgstr = '';
my $msgid = $_;
while (<POIO>) { # check for multiline msgid strings.
chomp;
s/\A\s+//;
s/\s+\Z//;
if (s/\Amsgstr \"(.*?)\"\Z/$1/) {
$msgstr = $_;
last;
}
if (s/\A\"(.*?)\"\Z/$1/) {
$msgid .= $_;
} else {
die("unexpected line: $_\n");
}
}
while (<POIO>) { # check for multiline msgstr strings.
chomp;
s/\A\s+//;
s/\s+\Z//;
last if ($_ eq '');
if (s/\A\"(.*?)\"\Z/$1/) {
$msgstr .= $_;
} else {
die("unexpected line: $_\n");
}
}
Jun 18, 2015
Jun 18, 2015
116
$msgstr = '' if ($fuzzy);
117
118
119
120
121
122
123
124
125
if ($template) {
push @strings, $msgid; # This is a list, to keep original order.
$comments{$msgid} = $comment;
$comment = '';
} elsif ($msgstr ne '') {
$msgstrs{$currentlang}{$msgid} = $msgstr;
}
}
Jun 18, 2015
Jun 18, 2015
126
$fuzzy = undef;
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
}
}
close(POIO);
}
die("no template seen\n") if (not $saw_template);
print <<__EOF__;
-- MojoSetup; a portable, flexible installation application.
--
-- Please see the file LICENSE.txt in the source's root directory.
--
-- DO NOT EDIT BY HAND.
Jul 29, 2008
Jul 29, 2008
142
-- This file was generated with po2localization.pl, version $hgver ...
143
144
145
146
147
148
149
150
151
152
-- on $now
--
-- Your own installer's localizations go into app_localization.lua instead.
-- If you want to add strings to be translated to this file, contact Ryan
-- (icculus\@icculus.org). If you want to add or change a translation for
-- existing strings, please use our nice web interface here for your work:
--
-- https://translations.launchpad.net/mojosetup/
--
-- ...and that work eventually ends up in this file.
Feb 29, 2008
Feb 29, 2008
153
154
155
--
-- $exportdate
-- $generator
156
157
158
159
160
161
162
163
164
165
166
MojoSetup.languages = {
__EOF__
print " en_US = \"English (United States)\"";
foreach (sort keys %languages) {
my $k = $_;
my $v = $languages{$k};
print ",\n $k = \"$v\""
}
Feb 29, 2008
Feb 29, 2008
167
print "\n};\n\nMojoSetup.localization = {";
168
169
170
foreach (@strings) {
my $msgid = $_;
Feb 29, 2008
Feb 29, 2008
171
print "\n";
172
173
174
175
176
177
178
179
180
181
182
print $comments{$msgid};
print " [\"$msgid\"] = {\n";
my $first = 1;
foreach (sort keys %languages) {
my $k = $_;
my $str = $msgstrs{$k}{$msgid};
next if ((not defined $str) or ($str eq ''));
print ",\n" if (not $first);
print " $k = \"$str\"";
$first = 0;
}
Feb 29, 2008
Feb 29, 2008
183
print "\n };\n";
184
185
186
187
188
}
print "};\n\n-- end of localization.lua ...\n\n";
# end of po2localization.pl ...