This file is indexed.

/usr/bin/debconf-gettextize is in po-debconf 1.0.20.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/perl -w

=head1 NAME

debconf-gettextize - convert master and localized templates files to PO files

=cut

use strict;
use Debconf::Template::Transient;
use Getopt::Long;
use Text::Wrap;
use Text::Tabs;
use File::Spec;
use File::Path;
use File::Temp;

sub usage {
        print STDERR <<EOF;
Usage: debconf-gettextize [OPTIONS] master [master ...]
Options:
  -h,  --help          display this help message
  -v,  --verbose       enable verbose mode
       --podir=DIR     specify PO output directory
                       (Default: <master directory>/po)
       --choices       prepend two underscores before Choices fields
       --merge         merge extracted strings with existing PO files
EOF
        exit $_[0];
}

# Ignore the users locale settings.
Debconf::Template::Transient->i18n(0);

# Prevent a wrapped line from beginning with a space
$Text::Wrap::break = qr/\n|\s(?=\S)/;

my $help = 0;
my $verbose = 0;
my $podir = "";
my $choices = 0;
my $merge = 0;
GetOptions(
        'podir=s' => \$podir,
        'choices' => \$choices,
        'merge' => \$merge,
        'verbose|v' => \$verbose,
        'help|h' => \$help,
) or usage(1);
$help && usage(0);
$#ARGV >= 0 || usage(1);

$ENV{PODEBCONF_ENCODINGS} ||= "/usr/share/po-debconf/encodings";
$ENV{PODEBCONF_HEADER} ||= "/usr/share/po-debconf/pot-header";

if ($podir eq '') {
        $podir = $ARGV[0];
        if ($podir =~ m#/#) {
                $podir =~ s{/[^/]*$}{/po};
        } else {
                $podir = 'po';
        }
}

my $tmpdir = '';
my $oldpodir = '';
if ($merge) {
        die "Error: $podir subdirectory does not exist ...exiting\n"
                unless -d $podir;
        $oldpodir = $podir;
        $tmpdir = File::Temp::tempdir() or die "tmpdir() failed: $!\n";
        print STDERR "Running po2debconf --podir=$podir -e po -o $tmpdir/templates $ARGV[0]\n" if $verbose;
        system("po2debconf", "--podir=$podir", "-e", "po", "-o", $tmpdir."/templates", $ARGV[0]) == 0
                or die "po2debconf failed: $? $!\n";
        shift @ARGV;
        for (@ARGV) {
                system("po2debconf", "--podir=$podir", "-e", "po", "-o", $tmpdir."/templates.tmp", $_) == 0
                        or die "po2debconf failed: $!\n";
                local $/ = undef;
                open (IN, "<", $tmpdir."/templates.tmp");
                my $add = <IN>;
                close (IN);
                open (OUT, ">>", $tmpdir."/templates");
                print OUT "\n".$add;
                close (OUT);
                unlink $tmpdir."/templates.tmp";
        }
        @ARGV = ($tmpdir."/templates");
        $podir = $tmpdir."/po";
} else {
        die "Error: $podir subdirectory already exist ...exiting\n"
                if -d $podir;
}

#   Hacked version of the stringify routine from Debconf/Template.pm
#   It prepends an underscore to translatable entries
sub new_stringify {
        my $template = shift;
        my @needfields = @_;

        my @templatestrings;
        my $transfields = ','.join(',', @needfields).',';
        foreach (($template)) {
                my $data='';
                # Order the fields with Template and Type the top and the
                # rest sorted.
                foreach my $key ('template', 'type',
                        (grep { $_ ne 'template' && $_ ne 'type'} sort $_->fields)) {
                        next if $key=~/^extended_/;
                        # Do not output localized fields.
                        next if $key =~ m/-/;

                        if ($transfields =~ m/,$key,/) {
                                $data.='_';
                                $data.='_' if ($key eq 'choices' && $choices);
                        }
                        $data.=ucfirst($key).": ".$_->$key."\n";
                        my $e="extended_$key";
                        my $ext=$_->$e;
                        if (defined $ext) {
                                # Add extended field.
                                my $extended=expand(wrap(' ', ' ', $ext));
                                # The word wrapper sometimes outputs multiple
                                # " \n" lines, so collapse those into one.
                                $extended=~s/(\n )+\n/\n .\n/g;
                                $data.=$extended."\n" if length $extended;
                        }
                }
                push @templatestrings, $data;
        }
        return join("\n", @templatestrings);
}

sub escape_po {
        my $txt = shift;

        $txt =~ s/\\/\\\\/g;
        $txt =~ s/\n/\\n/g;
        $txt =~ s/"/\\"/g;

        return $txt;
}

my %out = ();
my %enc = ();
my %txt = ();
my @obsolete = ();
my @files = @ARGV;

#     Initialization
foreach my $master (@ARGV) {
        die "Invalid master file: $master ...exiting\n".
  "templates.* file names are reserved for localized templates files, you\n".
  "should rename master files before running debconf-gettextize.\n".
  "When finished, you can rename new master files into templates.in and\n".
  "update POTFILES.in accordingly.\n\n"
                if $master =~ m#templates\.([^./]+)$#;
        die "File $master.old already exist ...exiting\n"
                if -e "$master.old";
        push (@obsolete, "$master.old");
        push (@files, glob ("$master.?? $master.??_??"));
        push (@obsolete, glob ("$master.?? $master.??_??"));
}

-d $podir || mkdir ($podir, 0755) || die "Can't create directory $podir: $!\n";

#     Fix relative links
foreach (@ARGV) {
        $_ = File::Spec->abs2rel($_, $podir);
        s/^\.\.\///;
}

#     Load master files
my %templates = ();
foreach my $fn (@files) {
        next if $fn =~ m#templates\.([^./]+)$#;
        $txt{$fn} = '';
        my %master = map { $_->template => $_ } Debconf::Template::Transient->load($fn);
        foreach (keys %master) {
                $templates{$_} = $master{$_};
        }
}

#     Parse master and localized templates files
foreach my $fn (@files) {
        print STDERR "Reading $fn\n" if $verbose;

        my $filelang = ($fn=~m#templates\.([^./]+)$# ? lc($1) : undef);
        foreach my $in (Debconf::Template::Transient->load($fn)) {
                next unless exists $templates{$in->template};
                my $master=$templates{$in->template};

                # Work out what fields need to be translated.
                my @needfields=qw{description extended_description};
                if ($master->type !~ /^((multi)?select|note|boolean)$/) {
                        push @needfields, 'default' if defined $master->default;
                }
                if ($master->type =~ /(multi)?select/) {
                        push @needfields, 'choices';
                }

                # Parse the translated material
                foreach my $field ($in->fields) {
                        next if $field eq 'template';
                        if ($field =~ m/^(.*?)-(.+)$/) {
                                my $origin_field=$1;
                                my $lang=$2;
                                if ($lang =~ s/\.(.*)//) {
                                        die "Multiple encoding found for language: $lang ... exiting\n"
                                                if (defined ($enc{$lang}) && $enc{$lang} ne uc ($1));
                                        $enc{$lang} = uc ($1);
                                }
                                # Skip fields that are for some other language.
                                if (!defined($filelang) || $lang eq $filelang) {
                                        $out{$lang} = []
                                                unless (defined($out{$lang}));

                                        my $label = $origin_field;
                                        $label =~ s/extended_//;
                                        $label = ucfirst($label);
                                        my $origmaster = $master->$origin_field || '';
                                        my @orig = split(/\n\n+/, $origmaster);
                                        my $orignew = $in->$origin_field || '';
                                        my @trans = split(/\n\n+/, $in->$field());
                                        if ($label eq 'Choices' && $choices) {
                                                @orig = ();
                                                for my $value (split(/(?<!\\), */, $origmaster, 0))
                                                {
                                                        $value =~ s/\\,/,/g;
                                                        push @orig, $value;
                                                }
                                                @trans = ();
                                                for my $value (split(/(?<!\\), */, $in->$field(), 0))
                                                {
                                                        $value =~ s/\\,/,/g;
                                                        push @trans, $value;
                                                }
                                        }
                                        $origmaster =~ s/[\n\s]+//g;
                                        $orignew =~ s/[\n\s]+//g;
                                        my $fuzzy = ($origmaster ne $orignew) || (scalar @orig != scalar @trans);
                                        if (scalar @orig <= scalar @trans) {
                                                foreach (@orig) {
                                                        push @{$out{$lang}}, $label, $fuzzy, $_, shift(@trans);
                                                }
                                        } else {
                                                foreach (@trans) {
                                                        push @{$out{$lang}}, $label, 1, shift(@orig), $_;
                                                }
                                                foreach (@orig) {
                                                        push @{$out{$lang}}, $label, 1, $_, '';
                                                }
                                        }
                                }
                        }
                }

                $txt{$fn} .= new_stringify($in, @needfields)."\n"
                        unless defined $filelang;
        }
        $txt{$fn} =~ s/\s*$/\n/s unless defined $filelang;
}

if (-f $ENV{PODEBCONF_ENCODINGS}) {
        open(ENC, "<", $ENV{PODEBCONF_ENCODINGS})
                || die "Can't open $ENV{PODEBCONF_ENCODINGS} for reading: $!\n";
        while (<ENC>) {
                chomp;
                next unless s/^([a-z][a-z](_[A-Z][A-Z])?)\s+//;
                $enc{lc $1} ||= $_;
        }
        close(ENC);
}
foreach my $lang (sort keys %out) {
        $enc{$lang} ||= 'CHARSET';
}

my $unknown_encoding = 0;
foreach my $lang (sort keys %out) {
        my $polang = $lang;
        $polang =~ s/_(..)$/_\U$1\E/;
        $polang .= '.po';
        print STDERR "Creating $podir/$polang\n" if $verbose;

        my $header = '';
        unless (-e "$podir/$polang") {
                if (open (TOP, "<", $ENV{PODEBCONF_HEADER})) {
                        while (<TOP>) {
                                $header .= $_;
                        }
                        close (TOP);
                }
                $header .= "#\n"
                 ."#, fuzzy\n"
                 ."msgid \"\"\n"
                 ."msgstr \"\"\n"
                 ."\"Project-Id-Version: PACKAGE VERSION\\n\"\n"
                 ."\"Report-Msgid-Bugs-To: \\n\"\n"
                 ."\"POT-Creation-Date: ".localtime()."\\n\"\n"
                 ."\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n"
                 ."\"Last-Translator: FULL NAME <EMAIL\@ADDRESS>\\n\"\n"
                 ."\"Language-Team: LANGUAGE <LL\@li.org>\\n\"\n"
                 ."\"MIME-Version: 1.0\\n\"\n"
                 ."\"Content-Type: text/plain; charset=".$enc{$lang}."\\n\"\n"
                 ."\"Content-Transfer-Encoding: 8bit\\n\"\n\n";
        }

        open (OUT, ">>", "$podir/$polang")
                || die "Can't open $podir/$polang for writing: $!\n";
        binmode(OUT);
        print OUT $header;
        while (@{$out{$lang}}) {
                print OUT "#: ".(shift @{$out{$lang}})."\n";
                print OUT "#, fuzzy\n" if (shift @{$out{$lang}});
                print OUT "msgid \"".
                          escape_po(shift @{$out{$lang}}).
                          "\"\n";
                print OUT "msgstr \"".
                          escape_po(shift @{$out{$lang}}).
                          "\"\n\n";
        }
        close (OUT) || die "Can't write $podir/$polang: $!\n";
        if ($enc{$lang} eq 'CHARSET') {
                $unknown_encoding = 1;
                warn "Warning: Encoding for language $lang is unknown.\n".
                     "Warning: This must be fixed before running po2debconf, so\n".
                     "Warning:   $podir/$polang is renamed into $podir/$polang.unknown\n".
                     "Warning: in order not to break other languages.\n".
                     "Warning: Do not forget to rename it after having fixed its ".
                     "encoding declaration!\n";
                rename "$podir/$polang", "$podir/$polang.unknown";
        } else {
                system("msguniq", "--use-first", "-o", "$podir/$polang.tmp", "$podir/$polang") == 0 or die "msguniq failed: $!\n";
                rename "$podir/$polang.tmp", "$podir/$polang";
        }
}

foreach my $master (keys %txt) {
        rename $master, "$master.old"
                or die "Unable to rename $master into $master.old\n";
        print STDERR "Creating $master\n" if $verbose;
        open (NEW, ">", $master) ||
                die "Can't open $master for writing: $!\n";
        print NEW $txt{$master};
        close (NEW);
}

my $current = '';
if (-e "$podir/POTFILES.in") {
        local $/ = undef;
        open (LIST, "<",  "$podir/POTFILES.in") ||
                die "Can't read $podir/POTFILES.in: $!\n";
        $current = <LIST>;
        close (LIST);
}
print STDERR "Create $podir/POTFILES.in\n" if $verbose;
open (LIST, ">", "$podir/POTFILES.in") ||
        die "Can't open $podir/POTFILES.in for writing: $!\n";
print LIST $current;
foreach (@ARGV) {
        print LIST "[type: gettext/rfc822deb] $_\n"
                unless $current =~ m/ $_\b/m;
}
close (LIST) || die "Can't open write $podir/POTFILES.in$!\n";

if ($merge) {
        foreach my $lang (keys %out) {
                my $polang = $lang;
                $polang =~ s/_(..)$/_\U$1\E/;
                if (-f "$oldpodir/$polang.po") {
                        unlink "$podir/temp";
                        system("msgcat", "--use-first", "-o", "$podir/temp", "$oldpodir/$polang.po", "$podir/$polang.po") == 0 && system("cp", "$podir/temp", "$oldpodir/$polang.po");
                } else {
                        system("cp", "$podir/$polang.po", "$oldpodir/$polang.po");
                }
        }
        File::Path::rmtree($tmpdir, 0, 1);
        print "\n".
                "  To complete conversion, you must:\n".
                "    a. Adjust _Choices or __Choices fields in master templates file.\n".
                "    b. Run debconf-updatepo\n";
} else {
        print STDERR "Running debconf-updatepo --podir=$podir\n" if $verbose;
        system("debconf-updatepo", "--podir=$podir");

        print "\n".
                "  To complete conversion, you must:\n".
                "    a. Check that new templates files contain all the localized fields\n".
                "    b. Add po-debconf to Build-Depends or Build-Depends-Indep in debian/control\n".
                "    c. Remove obsolete files:\n".
                wrap('         ', '         ', join(' ', @obsolete))."\n".
                "    d. Edit debian/rules to generate the localized templates file, either\n".
                "       with dh_installdebconf or directly with po2debconf\n";
        print   "    e. Check encoding in $podir/*.po.unknown files\n"
                if ($unknown_encoding);
}

exit 0;

=head1 AUTHORS

Martin Quinson <martin.quinson@ens-lyon.fr>
Denis Barbier <barbier@linuxfr.org>

=cut