2
# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5
# The Intltool Message Updater
7
# Copyright (C) 2000-2003 Free Software Foundation.
9
# Intltool is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU General Public License
11
# version 2 published by the Free Software Foundation.
13
# Intltool is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
# As a special exception to the GNU General Public License, if you
23
# distribute this file as part of a program that contains a
24
# configuration script generated by Autoconf, you may include it under
25
# the same distribution terms that you use for the rest of that program.
27
# Authors: Kenneth Christiansen <kenneth@gnu.org>
29
# Darin Adler <darin@bentspoon.com>
31
## Release information
32
my $PROGRAM = "intltool-update";
33
my $VERSION = "0.40.5";
34
my $PACKAGE = "intltool";
43
## Scalars used by the option stuff
52
my $GETTEXT_PACKAGE = "";
57
my %po_files_by_lang = ();
59
# Regular expressions to categorize file types.
60
# FIXME: Please check if the following is correct
63
"xml(?:\\.in)*|". # http://www.w3.org/XML/ (Note: .in is not required)
64
"ui|". # Bonobo specific - User Interface desc. files
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
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
"policy(?:\\.in)+"; # PolicyKit files
78
"icon(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
79
"desktop(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
80
"caves(?:\\.in)+|". # GNOME Games specific
81
"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
82
"soundlist(?:\\.in)+|". # GNOME specific
83
"keys(?:\\.in)+|". # GNOME Mime database specific
84
"theme(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
85
"service(?:\\.in)+"; # DBus specific
87
my $buildin_gettext_support =
88
"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
90
## Always flush buffer when printing
93
## Sometimes the source tree will be rooted somewhere else.
94
my $SRCDIR = $ENV{"srcdir"} || ".";
97
$POTFILES_in = "<$SRCDIR/POTFILES.in";
99
my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
104
"help" => \$HELP_ARG,
105
"version" => \$VERSION_ARG,
106
"dist|d" => \$DIST_ARG,
107
"pot|p" => \$POT_ARG,
108
"headers|s" => \$HEADERS_ARG,
109
"maintain|m" => \$MAINTAIN_ARG,
110
"report|r" => \$REPORT_ARG,
111
"verbose|x" => \$VERBOSE,
112
"gettext-package|g=s" => \$GETTEXT_PACKAGE,
113
"output-file|o=s" => \$OUTPUT_FILE,
114
) or &Console_WriteError_InvalidOption;
116
&Console_Write_IntltoolHelp if $HELP_ARG;
117
&Console_Write_IntltoolVersion if $VERSION_ARG;
119
my $arg_count = ($DIST_ARG > 0)
122
+ ($MAINTAIN_ARG > 0)
125
&Console_Write_IntltoolHelp if $arg_count > 1;
127
my $MODULE = $GETTEXT_PACKAGE || FindPackageName() || "unknown";
138
elsif ($MAINTAIN_ARG)
146
&Console_Write_CoverageReport;
148
elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
152
## Report error if the language file supplied
153
## to the command line is non-existent
154
&Console_WriteError_NotExisting("$SRCDIR/$lang.po")
155
if ! -s "$SRCDIR/$lang.po";
159
print "Working, please wait..." if $VERBOSE;
163
&POFile_Update ($lang, $OUTPUT_FILE);
164
&Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
168
&Console_Write_IntltoolHelp;
175
sub Console_Write_IntltoolVersion
178
${PROGRAM} (${PACKAGE}) $VERSION
179
Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
181
Copyright (C) 2000-2003 Free Software Foundation, Inc.
182
This is free software; see the source for copying conditions. There is NO
183
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
188
sub Console_Write_IntltoolHelp
191
Usage: ${PROGRAM} [OPTION]... LANGCODE
192
Updates PO template files and merge them with the translations.
194
Mode of operation (only one is allowed):
195
-p, --pot generate the PO template only
196
-s, --headers generate the header files in POTFILES.in
197
-m, --maintain search for left out files from POTFILES.in
198
-r, --report display a status report for the module
199
-d, --dist merge LANGCODE.po with existing PO template
202
-g, --gettext-package=NAME override PO template name, useful with --pot
203
-o, --output-file=FILE write merged translation to FILE
204
-x, --verbose display lots of feedback
205
--help display this help and exit
206
--version output version information and exit
209
${PROGRAM} --pot just create a new PO template
210
${PROGRAM} xy create new PO template and merge xy.po with it
212
Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
213
or send email to <xml-i18n-tools\@gnome.org>.
221
my $ret = `echo "$str"`;
223
$ret =~ s/\n$//; # do we need the "s" flag?
228
sub POFile_DetermineType ($)
233
my $xml_regex = "(?:" . $xml_support . ")";
234
my $ini_regex = "(?:" . $ini_support . ")";
235
my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
237
if ($type =~ /\[type: gettext\/([^\]].*)]/)
241
elsif ($type =~ /schemas(\.in)+$/)
243
$gettext_type="schemas";
245
elsif ($type =~ /glade2?(\.in)*$/)
247
$gettext_type="glade";
249
elsif ($type =~ /scm(\.in)*$/)
251
$gettext_type="scheme";
253
elsif ($type =~ /keys(\.in)+$/)
255
$gettext_type="keys";
260
elsif ($type =~ /$xml_regex$/)
264
elsif ($type =~ /$ini_regex$/)
268
elsif ($type =~ /$buildin_regex$/)
270
$gettext_type="buildin";
274
$gettext_type="unknown";
277
return "gettext\/$gettext_type";
280
sub TextFile_DetermineEncoding ($)
282
my $gettext_code="UTF-8"; # All files are UTF-8 by default
283
my $filetype=`file $_ | cut -d ' ' -f 2`;
287
if ($filetype =~ /^(ISO|UTF)/)
289
chomp ($gettext_code = $filetype);
291
elsif ($filetype =~ /^XML/)
293
$gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
297
return $gettext_code;
300
sub isNotValidMissing
304
return if $file =~ /^\{arch\}\/.*$/;
305
return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
312
@buf_i18n_xml_unmarked,
315
@buf_potfiles_ignore,
317
@buf_allfiles_sorted,
318
@buf_potfiles_sorted,
319
@buf_potfiles_ignore_sorted
322
## Search and find all translatable files
324
push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
325
push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
326
push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
327
push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
330
push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
331
push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
332
push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
333
push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
334
}, "$SRCDIR/.." if "$SRCDIR" ne ".";
336
open POTFILES, $POTFILES_in or die "$PROGRAM: there's no POTFILES.in!\n";
337
@buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
340
foreach (@buf_potfiles) {
344
print "Searching for missing translatable files...\n" if $VERBOSE;
346
## Check if we should ignore some found files, when
347
## comparing with POTFILES.in
348
foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
350
(-s "$SRCDIR/$ignore") or next;
352
if ("$ignore" eq "POTFILES.ignore")
354
print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
355
"content of this file to POTFILES.skip.\n";
358
print "Found $ignore: Ignoring files...\n" if $VERBOSE;
359
open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
364
next if (/^(#|\s*$)/);
366
my $skipdir = "../$_";
367
$skipdir = "$SRCDIR/../$_" if "$SRCDIR" ne ".";
375
push @dirignored, "$File::Find::name" if /\.($buildin_gettext_support)$/;
376
push @dirignored, "$File::Find::name" if /\.($xml_support)$/;
377
push @dirignored, "$File::Find::name" if /\.($ini_support)$/;
378
push @dirignored, "$File::Find::name" if /\.(schemas(\.in)+)$/;
380
foreach my $ignored (@dirignored)
382
$ignored =~ s/^$SRCDIR\///g;
383
$ignored =~ s/^..\///g;
384
$ignored =~ s/$/\n/g;
385
push @buf_potfiles_ignore, $ignored;
389
push @buf_potfiles_ignore, $_;
393
@buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
396
foreach my $file (@buf_i18n_plain)
404
# Handle continued multi-line comment.
407
next unless s-.*\*/--;
411
# Handle continued macro.
414
$in_macro = 0 unless /\\$/;
418
# Handle start of macro (or any preprocessor directive).
421
$in_macro = 1 if /^([^\\]|\\.)*\\$/;
425
# Handle comments and quoted text.
426
while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
437
elsif ($match eq "//")
443
if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
445
warn "mismatched quotes at line $. in $file\n";
451
if (/\w\.GetString *\(QUOTEDTEXT/)
453
if (defined isNotValidMissing (unpack("x3 A*", $file))) {
454
## Remove the first 3 chars and add newline
455
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
460
## C_ N_ NC_ Q_ and _ are the macros defined in gi8n.h
461
if (/(NC|[CNQ]?)_ *\(QUOTEDTEXT/)
463
if (defined isNotValidMissing (unpack("x3 A*", $file))) {
464
## Remove the first 3 chars and add newline
465
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
473
foreach my $file (@buf_i18n_xml)
479
# FIXME: share the pattern matching code with intltool-extract
480
if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
482
if (defined isNotValidMissing (unpack("x3 A*", $file))) {
483
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
491
foreach my $file (@buf_i18n_ini)
498
if (defined isNotValidMissing (unpack("x3 A*", $file))) {
499
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
507
foreach my $file (@buf_i18n_xml_unmarked)
509
if (defined isNotValidMissing (unpack("x3 A*", $file))) {
510
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
515
@buf_allfiles_sorted = sort (@buf_allfiles);
516
@buf_potfiles_sorted = sort (@buf_potfiles);
519
foreach (@buf_potfiles_sorted)
526
foreach (@buf_potfiles_ignore_sorted)
535
foreach (@buf_allfiles_sorted)
538
my $srcdir = $SRCDIR;
541
$dummy =~ s#^$srcdir/../##;
542
$dummy =~ s#^$srcdir/##;
543
$dummy =~ s#_build/##;
544
if (!exists($in2{$dummy}))
550
my @buf_potfiles_notexist;
552
foreach (@buf_potfiles_sorted)
554
chomp (my $dummy = $_);
555
if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
557
push @buf_potfiles_notexist, $_;
561
## Save file with information about the files missing
562
## if any, and give information about this procedure.
563
if (@result + @buf_potfiles_notexist > 0)
567
print "\n" if $VERBOSE;
569
open OUT, ">missing";
572
warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
573
"\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
574
print STDERR @result, "\n";
575
warn "If some of these files are left out on purpose then please add them to\n".
576
"POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
577
"of left out files has been written in the current directory.\n";
579
if (@buf_potfiles_notexist)
582
open OUT, ">notexist";
583
print OUT @buf_potfiles_notexist;
585
warn "\n" if ($VERBOSE or @result);
586
warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
587
warn @buf_potfiles_notexist, "\n";
588
warn "Please remove them from POTFILES.in. A file \e[1m'notexist'\e[0m\n".
589
"containing this list of absent files has been written in the current directory.\n";
593
## If there is nothing to complain about, notify the user
595
print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
599
sub Console_WriteError_InvalidOption
601
## Handle invalid arguments
602
print STDERR "Try `${PROGRAM} --help' for more information.\n";
609
# If either a file exists, or when run it returns 0 exit status
610
return 1 if ((-x $file) or (system("$file --version >$devnull") == 0));
617
# Check that we are using GNU gettext tools
618
if (isProgramInPath ($file))
620
my $version = `$file --version`;
621
return 1 if ($version =~ m/.*\(GNU .*\).*/);
628
my $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} || "intltool-extract";
630
$EXTRACT = "$^X $EXTRACT" if ($^O eq 'MSWin32' && !($EXTRACT =~ /perl/));
632
## Generate the .h header files, so we can allow glade and
633
## xml translation support
634
if (! isProgramInPath ("$EXTRACT"))
636
print STDERR "\n *** The intltool-extract script wasn't found!"
637
."\n *** Without it, intltool-update can not generate files.\n";
642
open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
647
next if /^\[\s*encoding/;
649
## Find xml files in POTFILES.in and generate the
650
## files with help from the extract script
652
my $gettext_type= &POFile_DetermineType ($1);
654
if (/\.($xml_support|$ini_support)$/ || /^\[/)
658
my $filename = "../$_";
662
system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
663
"--type=$gettext_type", $filename);
667
system ($EXTRACT, "--update", "--type=$gettext_type",
668
"--srcdir=$SRCDIR", "--quiet", $filename);
677
# Generate .pot file from POTFILES.in
679
sub GeneratePOTemplate
681
my $XGETTEXT = $ENV{"XGETTEXT"} || "xgettext";
682
my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
685
if (! isGNUGettextTool ("$XGETTEXT"))
687
print STDERR " *** GNU xgettext is not found on this system!\n".
688
" *** Without it, intltool-update can not extract strings.\n";
692
print "Building $MODULE.pot...\n" if $VERBOSE;
694
open INFILE, $POTFILES_in;
695
unlink "POTFILES.in.temp";
696
open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
698
my $gettext_support_nonascii = 0;
700
# checks for GNU gettext >= 0.12
701
my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
704
$gettext_support_nonascii = 1;
708
# require gnu gettext >= 0.12
709
die "$PROGRAM: GNU gettext >= 0.12 is required for intltool\n";
712
my $encoding = "UTF-8";
713
my $forced_gettext_code;
715
my $encoding_problem_is_reported = 0;
719
next if (/^#/ or /^\s*$/);
725
if (/^\[\s*encoding:\s*(.*)\s*\]/)
727
$forced_gettext_code=$1;
729
elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
732
print OUTFILE "../$_.h\n";
733
push @temp_headers, "../$_.h";
734
$gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
738
print OUTFILE "$SRCDIR/../$_\n";
739
$gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
742
next if (! $gettext_support_nonascii);
744
if (defined $forced_gettext_code)
746
$encoding=$forced_gettext_code;
748
elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
750
if ($encoding eq "ASCII")
752
$encoding=$gettext_code;
754
elsif ($gettext_code ne "ASCII")
756
# Only report once because the message is quite long
757
if (! $encoding_problem_is_reported)
759
print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
760
" but $PROGRAM thinks that most of the source files are in\n".
761
" $encoding encoding, while \"$_\" is (likely) in\n".
762
" $gettext_code encoding. If you are sure that all translatable strings\n".
763
" are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
764
" line to POTFILES.in:\n\n".
765
" [encoding: UTF-8]\n\n".
766
" and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
767
"(such warning message will only be reported once.)\n";
768
$encoding_problem_is_reported = 1;
777
unlink "$MODULE.pot";
778
my @xgettext_argument=("$XGETTEXT",
781
"--default-domain\=$MODULE",
782
"--flag\=g_strdup_printf:1:c-format",
783
"--flag\=g_string_printf:2:c-format",
784
"--flag\=g_string_append_printf:2:c-format",
785
"--flag\=g_error_new:3:c-format",
786
"--flag\=g_set_error:4:c-format",
787
"--flag\=g_markup_printf_escaped:1:c-format",
788
"--flag\=g_log:3:c-format",
789
"--flag\=g_print:1:c-format",
790
"--flag\=g_printerr:1:c-format",
791
"--flag\=g_printf:1:c-format",
792
"--flag\=g_fprintf:2:c-format",
793
"--flag\=g_sprintf:2:c-format",
794
"--flag\=g_snprintf:3:c-format",
795
"--flag\=g_scanner_error:2:c-format",
796
"--flag\=g_scanner_warn:2:c-format",
797
"--output\=$MODULE\.pot",
798
"--files-from\=\.\/POTFILES\.in\.temp");
799
my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
800
push @xgettext_argument, $XGETTEXT_KEYWORDS;
801
my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
802
push @xgettext_argument, "--msgid-bugs-address\=\"$MSGID_BUGS_ADDRESS\"" if $MSGID_BUGS_ADDRESS;
803
push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
804
push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
805
my $xgettext_command = join ' ', @xgettext_argument;
807
# intercept xgettext error message
808
print "Running $xgettext_command\n" if $VERBOSE;
809
my $xgettext_error_msg = `$xgettext_command 2>\&1`;
810
my $command_failed = $?;
812
unlink "POTFILES.in.temp";
814
print "Removing generated header (.h) files..." if $VERBOSE;
815
unlink foreach (@temp_headers);
816
print "done.\n" if $VERBOSE;
818
if (! $command_failed)
820
if (! -e "$MODULE.pot")
822
print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
826
print "Wrote $MODULE.pot\n" if $VERBOSE;
831
if ($xgettext_error_msg =~ /--from-code/)
833
my $errlocation = "unknown";
835
if ($xgettext_error_msg =~ /Non-ASCII string at (.*)\..*/)
839
print STDERR "ERROR: xgettext failed to generate PO tempalte file because the following \n".
840
" file contains strings marked for translation, not encoded in UTF-8. \n".
841
" Please ensure all strings marked for translation are UTF-8 encoded. \n\n".
846
print STDERR "$xgettext_error_msg";
847
if (-e "$MODULE.pot")
850
print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
851
" Please consult error message above if there is any.\n";
855
print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
856
" error message above if there is any.\n";
865
-f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
867
my $MSGMERGE = $ENV{"MSGMERGE"} || "msgmerge";
868
my ($lang, $outfile) = @_;
870
if (! isGNUGettextTool ("$MSGMERGE"))
872
print STDERR " *** GNU msgmerge is not found on this system!\n".
873
" *** Without it, intltool-update can not extract strings.\n";
877
print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
879
my $infile = "$SRCDIR/$lang.po";
880
$outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
882
# I think msgmerge won't overwrite old file if merge is not successful
883
system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
886
sub Console_WriteError_NotExisting
890
## Report error if supplied language file is non-existing
891
print STDERR "$PROGRAM: $file does not exist!\n";
892
print STDERR "Try '$PROGRAM --help' for more information.\n";
898
my @po_files = glob ("./*.po");
900
@languages = map (&POFile_GetLanguage, @po_files);
902
foreach my $lang (@languages)
904
$po_files_by_lang{$lang} = shift (@po_files);
908
sub POFile_GetLanguage ($)
910
s/^(.*\/)?(.+)\.po$/$2/;
914
sub Console_Write_TranslationStatus
916
my ($lang, $output_file) = @_;
917
my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
919
if (! isGNUGettextTool ("$MSGFMT"))
921
print STDERR " *** GNU msgfmt is not found on this system!\n".
922
" *** Without it, intltool-update can not extract strings.\n";
926
$output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
928
system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
931
sub Console_Write_CoverageReport
933
my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
935
if (! isGNUGettextTool ("$MSGFMT"))
937
print STDERR " *** GNU msgfmt is not found on this system!\n".
938
" *** Without it, intltool-update can not extract strings.\n";
944
foreach my $lang (@languages)
946
print STDERR "$lang: ";
947
&POFile_Update ($lang, "");
950
print STDERR "\n\n * Current translation support in $MODULE \n\n";
952
foreach my $lang (@languages)
954
print STDERR "$lang: ";
955
system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
959
sub SubstituteVariable
963
# always need to rewind file whenever it has been accessed
966
# cache each variable. varhash is global to we can add
967
# variables elsewhere.
972
($varhash{$1} = $2) =~ s/^["'](.*)["']$/$1/;
976
if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
981
# Ignore recursive definitions of variables
982
$sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
984
return SubstituteVariable ("$untouched$sub$rest");
987
# We're using Perl backticks ` and "echo -n" here in order to
988
# expand any shell escapes (such as backticks themselves) in every variable
989
return echo_n ($str);
994
my $base_dirname = getcwd();
995
$base_dirname =~ s@.*/@@;
997
my ($conf_in, $src_dir);
999
if ($base_dirname =~ /^po(-.+)?$/)
1003
my $makefile_source;
1006
open (IN, "<Makevars") || die "can't open Makevars: $!";
1010
if (/^top_builddir[ \t]*=/)
1013
$src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
1016
if (-f "$src_dir" . "/configure.ac") {
1017
$conf_in = "$src_dir" . "/configure.ac" . "\n";
1019
$conf_in = "$src_dir" . "/configure.in" . "\n";
1026
$conf_in || die "Cannot find top_builddir in Makevars.";
1028
elsif (-f "$SRCDIR/../configure.ac")
1030
$conf_in = "$SRCDIR/../configure.ac";
1032
elsif (-f "$SRCDIR/../configure.in")
1034
$conf_in = "$SRCDIR/../configure.in";
1038
my $makefile_source;
1041
open (IN, "<Makefile") || return;
1045
if (/^top_srcdir[ \t]*=/)
1048
$src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
1051
$conf_in = "$src_dir" . "/configure.in" . "\n";
1058
$conf_in || die "Cannot find top_srcdir in Makefile.";
1061
open (CONF, "<$conf_in");
1065
print STDERR "$PROGRAM: Unable to proceed.\n" .
1066
"Make sure to run this script inside the po directory.\n";
1074
my $domain = &FindMakevarsDomain;
1075
my $name = $domain || "untitled";
1081
open (IN, "<&CONF") || return $name;
1083
local $/; # slurp mode
1084
$conf_source = <IN>;
1088
# priority for getting package name:
1089
# 1. GETTEXT_PACKAGE
1090
# 2. first argument of AC_INIT (with >= 2 arguments)
1091
# 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
1093
# /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m
1094
# the \s makes this not work, why?
1095
if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
1097
($name, $version) = ($1, $2);
1098
$name =~ s/[\[\]\s]//g;
1099
$version =~ s/[\[\]\s]//g;
1101
$version =~ s/\(+$//g;
1103
$varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1104
$varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1105
$varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1106
$varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1109
if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m)
1111
($name, $version) = ($1, $2);
1112
$name =~ s/[\[\]\s]//g;
1113
$version =~ s/[\[\]\s]//g;
1115
$version =~ s/\(+$//g;
1117
$varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1118
$varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1119
$varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1120
$varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1123
# \s makes this not work, why?
1124
$name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
1126
# m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
1127
# as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
1128
$name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
1130
$name = $domain if $domain;
1132
$name = SubstituteVariable ($name);
1133
$name =~ s/^["'](.*)["']$/$1/;
1135
return $name if $name;
1142
my $keywords = "--keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 --keyword=Q_";
1143
my $varname = "XGETTEXT_OPTIONS";
1146
open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
1148
local $/; # slurp mode
1149
$make_source = <IN>;
1153
# unwrap lines split with a trailing \
1154
$make_source =~ s/\\ $ \n/ /mxg;
1155
$keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
1160
sub FindMakevarsDomain
1164
my $makevars_source; {
1166
open (IN, "<Makevars") || return $domain;
1168
local $/; # slurp mode
1169
$makevars_source = <IN>;
1173
$domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
1174
$domain =~ s/^\s+//;
1175
$domain =~ s/\s+$//;
1180
sub FindMakevarsBugAddress
1184
my $makevars_source; {
1186
open (IN, "<Makevars") || return undef;
1188
local $/; # slurp mode
1189
$makevars_source = <IN>;
1193
$address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
1194
$address =~ s/^\s+//;
1195
$address =~ s/\s+$//;