~ubuntu-branches/ubuntu/maverick/tsclient/maverick

« back to all changes in this revision

Viewing changes to intltool-update.in

  • Committer: Bazaar Package Importer
  • Author(s): Kilian Krause, Clément Hermann, debian/patches/15_missing-include.patch, debian/patches/14_spanish-translation-encoding.patch, debian/patches/99_autogen.patch, debian/patches/10_remote_disk_mapping.patch, debian/patches/14_manpage_whatis.patch, debian/patches/15_fix-outdated-desktop-entry.patch, Loic Minier, Josselin Mouette, Kilian Krause
  • Date: 2007-11-07 23:24:42 UTC
  • mfrom: (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20071107232442-z1xgsdg9whmkxp4j
Tags: 0.150-1
[ Clément Hermann ]
* New upstream release (Closes: #411465, #393976, #415583, #312506).
* Remove obsoletes patches. Included upstream.
  [debian/patches/15_missing-include.patch]
  [debian/patches/14_spanish-translation-encoding.patch]
  [debian/patches/99_autogen.patch]
* Add remote disk mapping support.
  [debian/patches/10_remote_disk_mapping.patch] (Closes: #449144)
* Fix lintian warning : manpage-has-bad-whatis-entry.
  [debian/patches/14_manpage_whatis.patch]
* Fix lintian warning : desktop-entry-contains-unknown-key.
  desktop entry specification 1.0.0 doesn't support [Actions]
  [debian/patches/15_fix-outdated-desktop-entry.patch]

[ Loic Minier ]
* Add a get-orig-source target to retrieve the upstream tarball.
* Set maintainer to Debian GNOME Maintainers.
* Wrap build-deps and deps.

[ Josselin Mouette ]
* Remove generated files in the clean target. Closes: #442751.

[ Kilian Krause ]
* Add Clément Hermann to Uploaders.
* Fix debian/watch (Closes: #449629)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!@INTLTOOL_PERL@ -w
 
2
# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4  -*-
2
3
 
3
4
#
4
5
#  The Intltool Message Updater
29
30
 
30
31
## Release information
31
32
my $PROGRAM = "intltool-update";
32
 
my $VERSION = "0.27.2";
 
33
my $VERSION = "0.35.5";
33
34
my $PACKAGE = "intltool";
34
35
 
35
36
## Loaded modules
58
59
# Regular expressions to categorize file types.
59
60
# FIXME: Please check if the following is correct
60
61
 
61
 
my $xml_extension =
62
 
"xml(\.in)*|".          # .in is not required
63
 
"ui|".
64
 
"lang|".
65
 
"glade2?(\.in)*|".      # .in is not required
66
 
"scm(\.in)*|".          # .in is not required
67
 
"oaf(\.in)+|".
68
 
"etspec|".
69
 
"server(\.in)+|".
70
 
"sheet(\.in)+|".
71
 
"schemas(\.in)+|".
72
 
"pong(\.in)+";
73
 
 
74
 
my $ini_extension =
75
 
"desktop(\.in)+|".
76
 
"caves(\.in)+|". 
77
 
"directory(\.in)+|".
78
 
"soundlist(\.in)+|".
79
 
"keys(\.in)+|".
80
 
"theme(\.in)+";
 
62
my $xml_support =
 
63
"xml(?:\\.in)*|".       # http://www.w3.org/XML/ (Note: .in is not required)
 
64
"ui|".                  # Bonobo specific - User Interface desc. files
 
65
"lang|".                # ?
 
66
"glade2?(?:\\.in)*|".   # Glade specific - User Interface desc. files (Note: .in is not required)
 
67
"scm(?:\\.in)*|".       # ? (Note: .in is not required)
 
68
"oaf(?:\\.in)+|".       # DEPRECATED: Replaces by Bonobo .server files 
 
69
"etspec|".              # ?
 
70
"server(?:\\.in)+|".    # Bonobo specific
 
71
"sheet(?:\\.in)+|".     # ?
 
72
"schemas(?:\\.in)+|".   # GConf specific
 
73
"pong(?:\\.in)+|".      # DEPRECATED: PONG is not used [by GNOME] any longer.
 
74
"kbd(?:\\.in)+";        # GOK specific. 
 
75
 
 
76
my $ini_support =
 
77
"icon(?:\\.in)+|".      # http://www.freedesktop.org/Standards/icon-theme-spec
 
78
"desktop(?:\\.in)+|".   # http://www.freedesktop.org/Standards/menu-spec
 
79
"caves(?:\\.in)+|".     # GNOME Games specific
 
80
"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
 
81
"soundlist(?:\\.in)+|". # GNOME specific
 
82
"keys(?:\\.in)+|".      # GNOME Mime database specific
 
83
"theme(?:\\.in)+|".     # http://www.freedesktop.org/Standards/icon-theme-spec
 
84
"service(?:\\.in)+";    # DBus specific
 
85
 
 
86
my $buildin_gettext_support = 
 
87
"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
81
88
 
82
89
## Always flush buffer when printing
83
90
$| = 1;
84
91
 
 
92
## Sometimes the source tree will be rooted somewhere else.
 
93
my $SRCDIR = $ENV{"srcdir"} || ".";
 
94
my $POTFILES_in;
 
95
 
 
96
$POTFILES_in = "<$SRCDIR/POTFILES.in";
 
97
 
 
98
my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
 
99
 
85
100
## Handle options
86
101
GetOptions 
87
102
(
95
110
 "verbose|x"           => \$VERBOSE,
96
111
 "gettext-package|g=s" => \$GETTEXT_PACKAGE,
97
112
 "output-file|o=s"     => \$OUTPUT_FILE,
98
 
 ) or &print_error_invalid_option;
 
113
 ) or &Console_WriteError_InvalidOption;
99
114
 
100
 
&print_help if $HELP_ARG;
101
 
&print_version if $VERSION_ARG;
 
115
&Console_Write_IntltoolHelp if $HELP_ARG;
 
116
&Console_Write_IntltoolVersion if $VERSION_ARG;
102
117
 
103
118
my $arg_count = ($DIST_ARG > 0)
104
119
    + ($POT_ARG > 0)
106
121
    + ($MAINTAIN_ARG > 0)
107
122
    + ($REPORT_ARG > 0);
108
123
 
109
 
&print_help if $arg_count > 1;
 
124
&Console_Write_IntltoolHelp if $arg_count > 1;
 
125
 
 
126
my $PKGNAME = FindPackageName ();
110
127
 
111
128
# --version and --help don't require a module name
112
 
my $MODULE = $GETTEXT_PACKAGE || &find_package_name;
 
129
my $MODULE = $GETTEXT_PACKAGE || $PKGNAME || "unknown";
113
130
 
114
131
if ($POT_ARG)
115
132
{
116
 
    &generate_headers;
117
 
    &generate_po_template;
 
133
    &GenerateHeaders;
 
134
    &GeneratePOTemplate;
118
135
}
119
136
elsif ($HEADERS_ARG)
120
137
{
121
 
    &generate_headers;
 
138
    &GenerateHeaders;
122
139
}
123
140
elsif ($MAINTAIN_ARG)
124
141
{
125
 
    &find_leftout_files;
 
142
    &FindLeftoutFiles;
126
143
}
127
144
elsif ($REPORT_ARG)
128
145
{
129
 
    &generate_headers;
130
 
    &generate_po_template;
131
 
    &print_report;
 
146
    &GenerateHeaders;
 
147
    &GeneratePOTemplate;
 
148
    &Console_Write_CoverageReport;
132
149
}
133
150
elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
134
151
{
136
153
 
137
154
    ## Report error if the language file supplied
138
155
    ## to the command line is non-existent
139
 
    &print_error_not_existing("$lang.po") if ! -s "$lang.po";
 
156
    &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
 
157
        if ! -s "$SRCDIR/$lang.po";
140
158
 
141
159
    if (!$DIST_ARG)
142
160
    {
143
161
        print "Working, please wait..." if $VERBOSE;
144
 
        &generate_headers;
145
 
        &generate_po_template;
 
162
        &GenerateHeaders;
 
163
        &GeneratePOTemplate;
146
164
    }
147
 
    &update_po_file ($lang, $OUTPUT_FILE);
148
 
    &print_status ($lang, $OUTPUT_FILE);
 
165
    &POFile_Update ($lang, $OUTPUT_FILE);
 
166
    &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
149
167
150
168
else 
151
169
{
152
 
    &print_help;
 
170
    &Console_Write_IntltoolHelp;
153
171
}
154
172
 
155
173
exit;
156
174
 
157
175
#########
158
176
 
159
 
sub print_version
 
177
sub Console_Write_IntltoolVersion
160
178
{
161
179
    print <<_EOF_;
162
180
${PROGRAM} (${PACKAGE}) $VERSION
169
187
    exit;
170
188
}
171
189
 
172
 
sub print_help
 
190
sub Console_Write_IntltoolHelp
173
191
{
174
192
    print <<_EOF_;
175
193
Usage: ${PROGRAM} [OPTION]... LANGCODE
199
217
    exit;
200
218
}
201
219
 
202
 
sub determine_type ($) 
 
220
sub echo_n
 
221
{
 
222
    my $str = shift;
 
223
    my $ret = `echo "$str"`;
 
224
 
 
225
    $ret =~ s/\n$//; # do we need the "s" flag?
 
226
 
 
227
    return $ret;
 
228
}
 
229
 
 
230
sub POFile_DetermineType ($) 
203
231
{
204
232
   my $type = $_;
205
233
   my $gettext_type;
206
234
 
207
 
   # FIXME: Use $xml_extension, and maybe do all this even nicer
208
 
   my $xml_regex = 
209
 
       "(?:xml(\.in)*|ui|lang|oaf(?:\.in)+|server(?:\.in)+|sheet(?:\.in)+|".
210
 
       "pong(?:\.in)+|etspec|schemas(?:\.in)+)";
211
 
   my $ini_regex =
212
 
       "(?:desktop(?:\.in)+|theme(?:\.in)+|caves(?:\.in)+|directory(?:\.in)+|".
213
 
       "soundlist(?:\.in)+)";
 
235
   my $xml_regex     = "(?:" . $xml_support . ")";
 
236
   my $ini_regex     = "(?:" . $ini_support . ")";
 
237
   my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
214
238
 
215
239
   if ($type =~ /\[type: gettext\/([^\]].*)]/) 
216
240
   {
220
244
   {
221
245
        $gettext_type="schemas";
222
246
   }
223
 
   elsif ($type =~ /$xml_regex$/) 
224
 
   {
225
 
       $gettext_type="xml";
226
 
   }
227
247
   elsif ($type =~ /glade2?(\.in)*$/) 
228
248
   {
229
249
       $gettext_type="glade";
230
250
   }
231
 
   elsif ($type =~ /$ini_regex$/) 
232
 
   { 
233
 
       $gettext_type="ini";
234
 
   }
235
251
   elsif ($type =~ /scm(\.in)*$/) 
236
252
   {
237
253
       $gettext_type="scheme";
240
256
   {
241
257
       $gettext_type="keys";
242
258
   }
243
 
   else 
244
 
   { 
245
 
       $gettext_type=""; 
 
259
 
 
260
   # bucket types
 
261
 
 
262
   elsif ($type =~ /$xml_regex$/) 
 
263
   {
 
264
       $gettext_type="xml";
 
265
   }
 
266
   elsif ($type =~ /$ini_regex$/) 
 
267
   { 
 
268
       $gettext_type="ini";
 
269
   }
 
270
   elsif ($type =~ /$buildin_regex$/) 
 
271
   {
 
272
       $gettext_type="buildin";
 
273
   }
 
274
   else
 
275
   { 
 
276
       $gettext_type="unknown"; 
246
277
   }
247
278
 
248
279
   return "gettext\/$gettext_type";
249
280
}
250
281
 
251
 
sub determine_code ($) 
 
282
sub TextFile_DetermineEncoding ($) 
252
283
{
253
284
    my $gettext_code="ASCII"; # All files are ASCII by default
254
285
    my $filetype=`file $_ | cut -d ' ' -f 2`;
268
299
    return $gettext_code;
269
300
}
270
301
 
271
 
 
272
 
sub find_leftout_files
 
302
sub isNotValidMissing
 
303
{
 
304
    my ($file) = @_;
 
305
 
 
306
    return if $file =~ /^\{arch\}\/.*$/;
 
307
    return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
 
308
}
 
309
 
 
310
sub FindLeftoutFiles
273
311
{
274
312
    my (@buf_i18n_plain,
275
313
        @buf_i18n_xml,
279
317
        @buf_potfiles_ignore,
280
318
        @buf_allfiles,
281
319
        @buf_allfiles_sorted,
282
 
        @buf_potfiles_sorted
 
320
        @buf_potfiles_sorted,
 
321
        @buf_potfiles_ignore_sorted
283
322
    );
284
323
 
285
324
    ## Search and find all translatable files
286
325
    find sub { 
287
 
        push @buf_i18n_plain,        "$File::Find::name" if /\.(c|y|cc|cpp|c\+\+|h|gob)$/;
288
 
        push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_extension)$/;
289
 
        push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_extension)$/;
 
326
        push @buf_i18n_plain,        "$File::Find::name" if /\.($buildin_gettext_support)$/;
 
327
        push @buf_i18n_xml,          "$File::Find::name" if /\.($xml_support)$/;
 
328
        push @buf_i18n_ini,          "$File::Find::name" if /\.($ini_support)$/;
290
329
        push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
291
330
        }, "..";
292
331
 
293
332
 
294
 
    open POTFILES, "<POTFILES.in" or die "$PROGRAM:  there's no POTFILES.in!\n";
 
333
    open POTFILES, $POTFILES_in or die "$PROGRAM:  there's no POTFILES.in!\n";
295
334
    @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
296
335
    close POTFILES;
297
336
 
305
344
    ## comparing with POTFILES.in
306
345
    foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
307
346
    {
308
 
        (-s $ignore) or next;
 
347
        (-s "$SRCDIR/$ignore") or next;
309
348
 
310
349
        if ("$ignore" eq "POTFILES.ignore")
311
350
        {
314
353
        }
315
354
 
316
355
        print "Found $ignore: Ignoring files...\n" if $VERBOSE;
317
 
        open FILE, "<$ignore" or die "ERROR: Failed to open $ignore!\n";
 
356
        open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
318
357
            
319
358
        while (<FILE>)
320
359
        {
322
361
        }
323
362
        close FILE;
324
363
 
325
 
        @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
 
364
        @buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
326
365
    }
327
366
 
328
367
    foreach my $file (@buf_i18n_plain)
380
419
                }
381
420
            }       
382
421
 
383
 
            if (/_\(QUOTEDTEXT/)
384
 
            {
385
 
                ## Remove the first 3 chars and add newline
386
 
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
422
            if (/\w\.GetString *\(QUOTEDTEXT/)
 
423
            {
 
424
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
425
                    ## Remove the first 3 chars and add newline
 
426
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
427
                }
 
428
                last;
 
429
            }
 
430
 
 
431
            ## N_ Q_ and _ are the three macros defined in gi8n.h
 
432
            if (/[NQ]?_ *\(QUOTEDTEXT/)
 
433
            {
 
434
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
435
                    ## Remove the first 3 chars and add newline
 
436
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
437
                }
387
438
                last;
388
439
            }
389
440
        }
397
448
        while (<FILE>) 
398
449
        {
399
450
            # FIXME: share the pattern matching code with intltool-extract
400
 
            if (/\s_(.*)=\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
 
451
            if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
401
452
            {
402
 
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
453
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
454
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
455
                }
403
456
                last;
404
457
            }
405
458
        }
413
466
        {
414
467
            if (/_(.*)=/)
415
468
            {
416
 
                push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
469
                if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
470
                    push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
471
                }
417
472
                last;
418
473
            }
419
474
        }
422
477
 
423
478
    foreach my $file (@buf_i18n_xml_unmarked)
424
479
    {
425
 
        push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
480
        if (defined isNotValidMissing (unpack("x3 A*", $file))) {
 
481
            push @buf_allfiles, unpack("x3 A*", $file) . "\n";
 
482
        }
426
483
    }
427
484
 
428
485
 
435
492
        $in2{$_} = 1;
436
493
    }
437
494
 
 
495
    foreach (@buf_potfiles_ignore_sorted) 
 
496
    {
 
497
        $in2{$_} = 1;
 
498
    }
 
499
 
438
500
    my @result;
439
501
 
440
502
    foreach (@buf_allfiles_sorted)
450
512
    foreach (@buf_potfiles_sorted)
451
513
    {
452
514
        chomp (my $dummy = $_);
453
 
        if ("$dummy" ne "" and ! -f "../$dummy")
 
515
        if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
454
516
        {
455
517
            push @buf_potfiles_notexist, $_;
456
518
        }
483
545
            warn "\n" if ($VERBOSE or @result);
484
546
            warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
485
547
            warn @buf_potfiles_notexist, "\n";
486
 
            warn "Please remove them from POTFILES.in or POTFILES.skip. A file \e[1m'notexist'\e[0m\n".
 
548
            warn "Please remove them from POTFILES.in. A file \e[1m'notexist'\e[0m\n".
487
549
                 "containing this list of absent files has been written in the current directory.\n";
488
550
        }
489
551
    }
494
556
    }
495
557
}
496
558
 
497
 
sub print_error_invalid_option
 
559
sub Console_WriteError_InvalidOption
498
560
{
499
561
    ## Handle invalid arguments
500
562
    print STDERR "Try `${PROGRAM} --help' for more information.\n";
501
563
    exit 1;
502
564
}
503
565
 
504
 
sub generate_headers
 
566
sub isIntltoolExtractInPath
505
567
{
506
 
    my $EXTRACT = `which intltool-extract 2>/dev/null`;
507
 
    chomp $EXTRACT;
 
568
    my ($file) = @_;
 
569
    # If either a file exists, or when run it returns 0 exit status
 
570
    return 1 if ((-x $file) or (system("$file >/dev/null") == 0));
 
571
    return 0;
 
572
}
508
573
 
509
 
    $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"};
 
574
sub GenerateHeaders
 
575
{
 
576
    my $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} || "intltool-extract";
510
577
 
511
578
    ## Generate the .h header files, so we can allow glade and
512
579
    ## xml translation support
513
 
    if (! -x "$EXTRACT")
 
580
    if (! isIntltoolExtractInPath("$EXTRACT"))
514
581
    {
515
582
        print STDERR "\n *** The intltool-extract script wasn't found!"
516
583
             ."\n *** Without it, intltool-update can not generate files.\n";
518
585
    }
519
586
    else
520
587
    {
521
 
        open (FILE, "<POTFILES.in") or die "$PROGRAM: POTFILES.in not found.\n";
 
588
        open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
522
589
        
523
590
        while (<FILE>) 
524
591
        {
528
595
           ## Find xml files in POTFILES.in and generate the
529
596
           ## files with help from the extract script
530
597
 
531
 
           my $gettext_type= &determine_type ($1);
 
598
           my $gettext_type= &POFile_DetermineType ($1);
532
599
 
533
 
           if (/\.($xml_extension|$ini_extension)$/ || /^\[/)
 
600
           if (/\.($xml_support|$ini_support)$/ || /^\[/)
534
601
           {
535
602
               s/^\[[^\[].*]\s*//;
536
603
 
538
605
 
539
606
               if ($VERBOSE)
540
607
               {
541
 
                   system ($EXTRACT, "--update", 
 
608
                   system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
542
609
                           "--type=$gettext_type", $filename);
543
610
               } 
544
611
               else 
545
612
               {
546
613
                   system ($EXTRACT, "--update", "--type=$gettext_type", 
547
 
                           "--quiet", $filename);
 
614
                           "--srcdir=$SRCDIR", "--quiet", $filename);
548
615
               }
549
616
           }
550
617
       }
555
622
#
556
623
# Generate .pot file from POTFILES.in
557
624
#
558
 
sub generate_po_template
 
625
sub GeneratePOTemplate
559
626
{
560
 
    my $XGETTEXT = `which xgettext 2>/dev/null`;
 
627
    my $XGETTEXT = $ENV{"XGETTEXT"} || "@INTLTOOL_XGETTEXT@";
 
628
    my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
561
629
    chomp $XGETTEXT;
562
630
 
563
 
    $XGETTEXT = $ENV{"XGETTEXT"} if $ENV{"XGETTEXT"};
564
 
 
565
631
    if (! -x $XGETTEXT)
566
632
    {
567
633
        print STDERR " *** xgettext is not found on this system!\n".
571
637
 
572
638
    print "Building $MODULE.pot...\n" if $VERBOSE;
573
639
 
574
 
    open INFILE, "<POTFILES.in";
 
640
    open INFILE, $POTFILES_in;
575
641
    unlink "POTFILES.in.temp";
576
 
    open OUTFILE, ">POTFILES.in.temp";
 
642
    open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
577
643
 
578
644
    my $gettext_support_nonascii = 0;
579
645
 
580
646
    # checks for GNU gettext >= 0.12
581
 
    # don't use argument list, since shell interpretation is desired here
582
 
    if (system("$XGETTEXT --version --from-code=UTF-8 >&/dev/null") == 0)
 
647
    my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
 
648
    if ($? == 0)
583
649
    {
584
650
        $gettext_support_nonascii = 1;
585
651
    }
589
655
        print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
590
656
                     "         strings. That means you should install a version of gettext\n".
591
657
                     "         that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
592
 
                     "         or have to let non-ASCII strings untranslated.\n";
 
658
                     "         or have to let non-ASCII strings untranslated. (If there is any)\n";
593
659
    }
594
660
 
595
661
    my $encoding = "ASCII";
609
675
        {
610
676
            $forced_gettext_code=$1;
611
677
        }
612
 
        elsif (/\.($xml_extension|$ini_extension)$/ || /^\[/)
 
678
        elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
613
679
        {
614
680
            s/^\[.*]\s*//;
615
 
            print OUTFILE "$_.h\n";
 
681
            print OUTFILE "../$_.h\n";
616
682
            push @temp_headers, "../$_.h";
617
 
            $gettext_code = &determine_code ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
683
            $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
618
684
        } 
619
685
        else 
620
686
        {
621
 
            print OUTFILE "$_\n";
622
 
            $gettext_code = &determine_code ("../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
 
687
            print OUTFILE "$SRCDIR/../$_\n";
 
688
            $gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
623
689
        }
624
690
 
625
691
        next if (! $gettext_support_nonascii);
660
726
    unlink "$MODULE.pot";
661
727
    my @xgettext_argument=("$XGETTEXT",
662
728
                           "--add-comments",
663
 
                           "--directory\=\.\.",
664
 
                           "--keyword\=\_",
665
 
                           "--keyword\=N\_",
666
 
                           "--keyword\=U\_",
 
729
                           "--directory\=\.",
667
730
                           "--output\=$MODULE\.pot",
668
731
                           "--files-from\=\.\/POTFILES\.in\.temp");
 
732
    my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
 
733
    push @xgettext_argument, $XGETTEXT_KEYWORDS;
 
734
    my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
 
735
    push @xgettext_argument, "--msgid-bugs-address\=$MSGID_BUGS_ADDRESS" if $MSGID_BUGS_ADDRESS;
669
736
    push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
 
737
    push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
670
738
    my $xgettext_command = join ' ', @xgettext_argument;
671
739
 
672
740
    # intercept xgettext error message
 
741
    print "Running $xgettext_command\n" if $VERBOSE;
673
742
    my $xgettext_error_msg = `$xgettext_command 2>\&1`;
674
743
    my $command_failed = $?;
675
744
 
720
789
    }
721
790
}
722
791
 
723
 
sub update_po_file
 
792
sub POFile_Update
724
793
{
725
794
    -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
726
795
 
 
796
    my $MSGMERGE = $ENV{"MSGMERGE"} || "@INTLTOOL_MSGMERGE@";
727
797
    my ($lang, $outfile) = @_;
728
798
 
729
 
    print "Merging $lang.po with $MODULE.pot..." if $VERBOSE;
 
799
    print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
730
800
 
731
 
    my $infile = "$lang.po";
732
 
    $outfile = "$lang.po" if ($outfile eq "");
 
801
    my $infile = "$SRCDIR/$lang.po";
 
802
    $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
733
803
 
734
804
    # I think msgmerge won't overwrite old file if merge is not successful
735
 
    system ("msgmerge", "-o", $outfile, $infile, "$MODULE.pot");
 
805
    system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
736
806
}
737
807
 
738
 
sub print_error_not_existing
 
808
sub Console_WriteError_NotExisting
739
809
{
740
810
    my ($file) = @_;
741
811
 
745
815
    exit;
746
816
}
747
817
 
748
 
sub gather_po_files
 
818
sub GatherPOFiles
749
819
{
750
820
    my @po_files = glob ("./*.po");
751
821
 
752
 
    @languages = map (&po_file2lang, @po_files);
 
822
    @languages = map (&POFile_GetLanguage, @po_files);
753
823
 
754
824
    foreach my $lang (@languages) 
755
825
    {
757
827
    }
758
828
}
759
829
 
760
 
sub po_file2lang ($)
 
830
sub POFile_GetLanguage ($)
761
831
{
762
832
    s/^(.*\/)?(.+)\.po$/$2/;
763
833
    return $_;
764
834
}
765
835
 
766
 
sub print_status
 
836
sub Console_Write_TranslationStatus
767
837
{
768
838
    my ($lang, $output_file) = @_;
769
 
 
770
 
    $output_file = "$lang.po" if ($output_file eq "");
771
 
 
772
 
    system ("msgfmt", "-o", "/dev/null", "--statistics", $output_file);
 
839
    my $MSGFMT = $ENV{"MSGFMT"} || "@INTLTOOL_MSGFMT@";
 
840
 
 
841
    $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
 
842
 
 
843
    system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
773
844
}
774
845
 
775
 
sub print_report
 
846
sub Console_Write_CoverageReport
776
847
{
777
 
    &gather_po_files;
 
848
    my $MSGFMT = $ENV{"MSGFMT"} || "@INTLTOOL_MSGFMT@";
 
849
 
 
850
    &GatherPOFiles;
778
851
 
779
852
    foreach my $lang (@languages) 
780
853
    {
781
854
        print "$lang: ";
782
 
        &update_po_file ($lang, "");
 
855
        &POFile_Update ($lang, "");
783
856
    }
784
857
 
785
858
    print "\n\n * Current translation support in $MODULE \n\n";
787
860
    foreach my $lang (@languages)
788
861
    {
789
862
        print "$lang: ";
790
 
        system ("msgfmt", "-o", "/dev/null", "--statistics", "$lang.po");
 
863
        system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
791
864
    }
792
865
}
793
866
 
794
 
sub substitute_var
 
867
sub SubstituteVariable
795
868
{
796
869
    my ($str) = @_;
797
870
    
802
875
    # variables elsewhere.
803
876
    while (<CONF>)
804
877
    {
805
 
        if (/^(\w+)=(\S+)/)
 
878
        if (/^(\w+)=(.*)$/)
806
879
        {
807
 
            $varhash{$1} = $2;
 
880
            ($varhash{$1} = $2) =~  s/^["'](.*)["']$/$1/;
808
881
        }
809
882
    }
810
883
    
812
885
    {
813
886
        my $rest = $3;
814
887
        my $untouched = $1;
815
 
        my $sub = $varhash{$2};
816
 
        
817
 
        return substitute_var ("$untouched$sub$rest");
 
888
        my $sub = "";
 
889
        # Ignore recursive definitions of variables
 
890
        $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
 
891
 
 
892
        return SubstituteVariable ("$untouched$sub$rest");
818
893
    }
819
 
    return $str;
 
894
    
 
895
    # We're using Perl backticks ` and "echo -n" here in order to 
 
896
    # expand any shell escapes (such as backticks themselves) in every variable
 
897
    return echo_n ($str);
820
898
}
821
899
 
822
 
sub open_CONF_handle
 
900
sub CONF_Handle_Open
823
901
{
824
902
    my $base_dirname = getcwd();
825
903
    $base_dirname =~ s@.*/@@;
828
906
 
829
907
    if ($base_dirname =~ /^po(-.+)?$/) 
830
908
    {
831
 
        if (-f "../configure.ac") 
 
909
        if (-f "Makevars") 
 
910
        {
 
911
            my $makefile_source;
 
912
 
 
913
            local (*IN);
 
914
            open (IN, "<Makevars") || die "can't open Makevars: $!";
 
915
 
 
916
            while (<IN>) 
 
917
            {
 
918
                if (/^top_builddir[ \t]*=/) 
 
919
                {
 
920
                    $src_dir = $_;
 
921
                    $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
 
922
 
 
923
                    chomp $src_dir;
 
924
                    if (-f "$src_dir" . "/configure.ac") {
 
925
                        $conf_in = "$src_dir" . "/configure.ac" . "\n";
 
926
                    } else {
 
927
                        $conf_in = "$src_dir" . "/configure.in" . "\n";
 
928
                    }
 
929
                    last;
 
930
                }
 
931
            }
 
932
            close IN;
 
933
 
 
934
            $conf_in || die "Cannot find top_builddir in Makevars.";
 
935
        }
 
936
        elsif (-f "../configure.ac") 
832
937
        {
833
938
            $conf_in = "../configure.ac";
834
939
        } 
841
946
            my $makefile_source;
842
947
 
843
948
            local (*IN);
844
 
            open IN, "<Makefile" || die "can't open Makefile: $!";
 
949
            open (IN, "<Makefile") || return;
845
950
 
846
951
            while (<IN>) 
847
952
            {
861
966
            $conf_in || die "Cannot find top_srcdir in Makefile.";
862
967
        }
863
968
 
864
 
        open (CONF, "<$conf_in") || die "can't open $conf_in: $!";
 
969
        open (CONF, "<$conf_in");
865
970
    }
866
971
    else
867
972
    {
871
976
    }
872
977
}
873
978
 
874
 
sub find_package_name
 
979
sub FindPackageName
875
980
{
876
 
    &open_CONF_handle;
 
981
    my $version;
 
982
    my $domain = &FindMakevarsDomain;
 
983
    my $name = $domain || "untitled";
 
984
 
 
985
    &CONF_Handle_Open;
877
986
 
878
987
    my $conf_source; {
879
988
        local (*IN);
880
 
        open (IN, "<&CONF") || die "can't open configure.in/configure.ac: $!";
 
989
        open (IN, "<&CONF") || return $name;
881
990
        seek (IN, 0, 0);
882
991
        local $/; # slurp mode
883
992
        $conf_source = <IN>;
884
993
        close IN;
885
994
    }
886
995
 
887
 
    my $name = "untitled";
888
 
    my $version;
889
 
 
890
996
    # priority for getting package name:
891
997
    # 1. GETTEXT_PACKAGE
892
998
    # 2. first argument of AC_INIT (with >= 2 arguments)
897
1003
    if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
898
1004
    {
899
1005
        ($name, $version) = ($1, $2);
900
 
        $name =~ s/[\[\]\s]//g;
901
 
        ($varhash{"AC_PACKAGE_VERSION"} = $version) =~ s/[\[\]\s]//g;
 
1006
        $name    =~ s/[\[\]\s]//g;
 
1007
        $version =~ s/[\[\]\s]//g;
 
1008
        $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
 
1009
        $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
 
1010
        $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
 
1011
        $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
902
1012
    }
903
1013
    
904
1014
    if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m) 
905
1015
    {
906
1016
        ($name, $version) = ($1, $2);
907
 
        $name=~ s/[\[\]\s]//g;
908
 
        $varhash{"AC_PACKAGE_NAME"} = $name;
909
 
        ($varhash{"AC_PACKAGE_VERSION"} = $version) =~ s/[\[\]\s]//g;
 
1017
        $name    =~ s/[\[\]\s]//g;
 
1018
        $version =~ s/[\[\]\s]//g;
 
1019
        $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
 
1020
        $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
 
1021
        $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
 
1022
        $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
910
1023
    }
911
1024
 
912
1025
    # \s makes this not work, why?
913
1026
    $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
914
1027
    
915
 
    # prepend '$' to auto* internal variables, usually they are
916
 
    # used in configure.in/ac without the '$'
917
 
    $name =~ s/AC_/\$AC_/g;
918
 
    $name =~ s/\$\$/\$/g;
919
 
    
920
 
    $name = substitute_var ($name);
 
1028
    # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
 
1029
    # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
 
1030
    $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
 
1031
 
 
1032
    $name = $domain if $domain;
 
1033
 
 
1034
    $name = SubstituteVariable ($name);
 
1035
    $name =~ s/^["'](.*)["']$/$1/;
921
1036
 
922
1037
    return $name if $name;
923
1038
}
 
1039
 
 
1040
 
 
1041
sub FindPOTKeywords
 
1042
{
 
1043
 
 
1044
    my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_";
 
1045
    my $varname = "XGETTEXT_OPTIONS";
 
1046
    my $make_source; {
 
1047
        local (*IN);
 
1048
        open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
 
1049
        seek (IN, 0, 0);
 
1050
        local $/; # slurp mode
 
1051
        $make_source = <IN>;
 
1052
        close IN;
 
1053
    }
 
1054
 
 
1055
    $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
 
1056
    
 
1057
    return $keywords;
 
1058
}
 
1059
 
 
1060
sub FindMakevarsDomain
 
1061
{
 
1062
 
 
1063
    my $domain = "";
 
1064
    my $makevars_source; { 
 
1065
        local (*IN);
 
1066
        open (IN, "<Makevars") || return $domain;
 
1067
        seek (IN, 0, 0);
 
1068
        local $/; # slurp mode
 
1069
        $makevars_source = <IN>;
 
1070
        close IN;
 
1071
    }
 
1072
 
 
1073
    $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
 
1074
    $domain =~ s/^\s+//;
 
1075
    $domain =~ s/\s+$//;
 
1076
    
 
1077
    return $domain;
 
1078
}
 
1079
 
 
1080
sub FindMakevarsBugAddress
 
1081
{
 
1082
 
 
1083
    my $address = "";
 
1084
    my $makevars_source; { 
 
1085
        local (*IN);
 
1086
        open (IN, "<Makevars") || return undef;
 
1087
        seek (IN, 0, 0);
 
1088
        local $/; # slurp mode
 
1089
        $makevars_source = <IN>;
 
1090
        close IN;
 
1091
    }
 
1092
 
 
1093
    $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
 
1094
    $address =~ s/^\s+//;
 
1095
    $address =~ s/\s+$//;
 
1096
    
 
1097
    return $address;
 
1098
}