4
# The Intltool Message Updater
6
# Copyright (C) 2000-2002 Free Software Foundation.
8
# Intltool is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU General Public License
10
# version 2 published by the Free Software Foundation.
12
# Intltool is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
# As a special exception to the GNU General Public License, if you
22
# distribute this file as part of a program that contains a
23
# configuration script generated by Autoconf, you may include it under
24
# the same distribution terms that you use for the rest of that program.
26
# Authors: Kenneth Christiansen <kenneth@gnu.org>
28
# Darin Adler <darin@bentspoon.com>
30
## Release information
31
my $PROGRAM = "intltool-update";
33
my $PACKAGE = "intltool";
42
## Scalars used by the option stuff
51
my $GETTEXT_PACKAGE = "";
54
my %po_files_by_lang = ();
56
# Regular expressions to categorize file types.
57
# FIXME: Please check if the following is correct
60
"xml(\.in)*|". # .in is not required
62
"glade2?(\.in)*|". # .in is not required
63
"scm(\.in)*|". # .in is not required
79
## Always print as the first thing
86
"version" => \$VERSION_ARG,
87
"dist|d" => \$DIST_ARG,
89
"headers|s" => \$HEADERS_ARG,
90
"maintain|m" => \$MAINTAIN_ARG,
91
"report|r" => \$REPORT_ARG,
92
"verbose|x" => \$VERBOSE,
93
"gettext-package|g=s" => \$GETTEXT_PACKAGE,
94
) or &print_error_invalid_option;
96
&print_help if $HELP_ARG;
97
&print_version if $VERSION_ARG;
99
my $arg_count = ($DIST_ARG > 0)
102
+ ($MAINTAIN_ARG > 0)
104
&print_help if $arg_count > 1;
106
# --version and --help don't require a module name
107
my $MODULE = $GETTEXT_PACKAGE || &find_package_name;
110
if ($ARGV[0] =~ /^[a-z]/){
111
&update_po_file ($ARGV[0]);
112
&print_status ($ARGV[0]);
118
&generate_po_template;
119
} elsif ($HEADERS_ARG) {
121
} elsif ($MAINTAIN_ARG) {
123
} elsif ($REPORT_ARG) {
126
if ($ARGV[0] =~ /^[a-z]/) {
139
## Print version information
140
print "${PROGRAM} (${PACKAGE}) $VERSION\n";
141
print "Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.\n\n";
142
print "Copyright (C) 2000-2002 Free Software Foundation, Inc.\n";
143
print "This is free software; see the source for copying conditions. There is NO\n";
144
print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
150
## Print usage information
151
print "Usage: ${PROGRAM} [OPTIONS] ...LANGCODE\n";
152
print "Updates PO template files and merge them with the translations.\n\n";
153
print " -p, --pot generate the PO template only\n";
154
print " -s, --headers generate the header files in POTFILES.in\n";
155
print " -m, --maintain search for left out files from POTFILES.in\n";
156
print " -r, --report display a status report for the module.\n";
157
print " -x, --verbose display lots of feedback\n";
158
print " --help display this help and exit\n";
159
print " --version output version information and exit\n";
160
print "\nExamples of use:\n";
161
print "${PROGRAM} --pot just creates a new PO template from the source\n";
162
print "${PROGRAM} da created new PO template and updated the da.po file\n\n";
163
print "Report bugs to bugzilla.gnome.org, module 'intltool'.\n";
171
## Report error if the language file supplied
172
## to the command line is non-existent
173
&print_error_not_existing("$lang.po") if ! -s "$lang.po";
175
print "Working, please wait..." unless $VERBOSE;
177
&generate_po_template;
178
&update_po_file ($lang);
179
&print_status ($lang);
182
sub determine_type ($)
187
# FIXME: Use $xml_extentions, and maybe do all this even nicer
189
"(?:xml(\.in)*|ui|oaf(?:\.in)+|server(?:\.in)+|sheet(?:\.in)+|".
190
"pong(?:\.in)+|etspec|schemas(?:\.in)+)";
192
"(?:desktop(?:\.in)+|theme(?:\.in)+|caves(?:\.in)+|directory(?:\.in)+|".
193
"soundlist(?:\.in)+)";
195
if ($type =~ /\[type: gettext\/([^\]].*)]/) {
198
elsif ($type =~ /schemas(\.in)+$/) {
199
$gettext_type="schemas";
201
elsif ($type =~ /$xml_regex$/) {
204
elsif ($type =~ /glade2?(\.in)*$/) {
205
$gettext_type="glade";
207
elsif ($type =~ /$ini_regex$/) {
210
elsif ($type =~ /scm(\.in)*$/) {
211
$gettext_type="scheme";
213
elsif ($type =~ /keys(\.in)+$/) {
214
$gettext_type="keys";
216
else { $gettext_type=""; }
218
return "gettext\/$gettext_type";
221
sub find_leftout_files
225
@buf_i18n_xml_unmarked,
228
@buf_potfiles_ignore,
230
@buf_allfiles_sorted,
234
## Search and find all translatable files
236
push @buf_i18n_plain, "$File::Find::name" if /\.(c|y|cc|cpp|c\+\+|h|gob)$/
239
push @buf_i18n_xml, "$File::Find::name" if /\.($xml_extension)$/
242
push @buf_i18n_ini, "$File::Find::name" if /\.($ini_extension)$/
245
push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/
249
open POTFILES, "POTFILES.in" or die "$PROGRAM: there's no POTFILES.in!\n";
251
@buf_potfiles = grep /^[^#]/, <POTFILES>;
252
foreach (@buf_potfiles) {
256
print "Searching for missing translatable files...\n" if $VERBOSE;
258
## Check if we should ignore some found files, when
259
## comparing with POTFILES.in
260
foreach my $ignore ("POTFILES.skip", "POTFILES.ignore") {
265
push @buf_potfiles_ignore, $_;
268
print "Found $ignore: Ignoring files...\n" if $VERBOSE;
269
@buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
273
foreach my $file (@buf_i18n_plain)
281
# Handle continued multi-line comment.
284
next unless s-.*\*/--;
288
# Handle continued macro.
291
$in_macro = 0 unless /\\$/;
295
# Handle start of macro (or any preprocessor directive).
298
$in_macro = 1 if /^([^\\]|\\.)*\\$/;
302
# Handle comments and quoted text.
303
while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
314
elsif ($match eq "//")
320
if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
322
warn "mismatched quotes at line $. in $file\n";
331
## Remove the first 3 chars and add newline
332
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
339
foreach my $file (@buf_i18n_xml) {
342
if (/\s_(.*)=\"/ || /translatable=\"yes\"/){
343
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
349
foreach my $file (@buf_i18n_ini){
353
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
359
foreach my $file (@buf_i18n_xml_unmarked){
360
push @buf_allfiles, unpack("x3 A*", $file) . "\n";
364
@buf_allfiles_sorted = sort (@buf_allfiles);
365
@buf_potfiles_sorted = sort (@buf_potfiles);
368
foreach (@buf_potfiles_sorted) {
374
foreach (@buf_allfiles_sorted){
375
if (!exists($in2{$_})){
380
## Save file with information about the files missing
381
## if any, and give information about this procedure.
383
print "\n" if $VERBOSE;
384
open OUT, ">missing";
386
print "The following files contain translations and are currently not in use. Please\n";
387
print "consider adding these to the POTFILES.in file, located in the po/ directory.\n\n";
389
print "If some of these files are left out on purpose then please add them to\n";
390
print "POTFILES.skip instead of POTFILES.in. A file 'missing' containing this list\n";
391
print "of left out files has been written in the current directory.\n";
394
## If there is nothing to complain about, notify the user
396
print "\nAll files containing translations are present in POTFILES.in.\n";
400
sub print_error_invalid_option
402
## Handle invalid arguments
403
print "Try `${PROGRAM} --help' for more information.\n";
409
my $EXTRACT = `which intltool-extract 2>/dev/null`;
412
$EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"};
414
## Generate the .h header files, so we can allow glade and
415
## xml translation support
418
print "\n *** The intltool-extract script wasn't found!"
419
."\n *** Without it, intltool-update can not generate files.\n";
424
open FILE, "<POTFILES.in";
428
## Find xml files in POTFILES.in and generate the
429
## files with help from the extract script
431
my $gettext_type= &determine_type ($1);
433
if (/\.($xml_extension|$ini_extension)$/ || /^\[/){
434
$_ =~ s/^\[[^\[].*]\s*//;
435
my $filename = "../$_";
438
system($EXTRACT, "--update", "--type=$gettext_type", $filename);
440
system($EXTRACT, "--update", "--type=$gettext_type", "--quiet", $filename);
448
sub generate_po_template
450
## Generate the potfiles from the POTFILES.in file
452
print "Building the $MODULE.pot...\n" if $VERBOSE;
454
move ("POTFILES.in", "POTFILES.in.old");
456
open INFILE, "<POTFILES.in.old";
457
open OUTFILE, ">POTFILES.in";
460
if (/\.($xml_extension|$ini_extension)$/ || /^\[/) {
462
print OUTFILE "$_.h\n";
464
print OUTFILE "$_\n";
470
system ("xgettext", "--default-domain\=$MODULE",
476
"--files-from\=\.\/POTFILES\.in");
478
move ("POTFILES.in.old", "POTFILES.in");
480
print "Removing generated header (.h) files..." if $VERBOSE;
482
open FILE, "<POTFILES.in";
487
unlink "../$_.h" if /\.($xml_extension|$ini_extension)$/;
491
print "done\n" if $VERBOSE;
493
if (!-e "$MODULE.po") {
494
print "WARNING: It seems that none of the files in POTFILES.in ".
495
"contain marked strings\n";
499
system ("rm", "-f", "$MODULE.pot");
500
move ("$MODULE.po", "$MODULE.pot") or die "$PROGRAM: couldn't move $MODULE.po to $MODULE.pot.\n";
502
print "Wrote $MODULE.pot\n" if $VERBOSE;
509
print "Merging $lang.po with $MODULE.pot..." if $VERBOSE;
511
copy ("$lang.po", "$lang.po.old") || die "copy failed: $!";
513
# Perform merge, remove backup file and the "messages" trash file
514
# generated by gettext
515
system ("msgmerge", "-o", "$lang.po", "$lang.po.old", "$MODULE.pot");
516
unlink "$lang.po.old";
520
sub print_error_not_existing
524
## Report error if supplied language file is non-existing
525
print "$PROGRAM: $file does not exist!\n";
526
print "Try '$PROGRAM --help' for more information.\n";
532
my @po_files = glob ("./*.po");
534
@languages = map (&po_file2lang, @po_files);
536
foreach my $lang (@languages) {
537
$po_files_by_lang{$lang} = shift (@po_files);
544
$tmp =~ s/^.*\/(.*)\.po$/$1/;
552
system ("msgfmt", "--statistics", "$lang.po");
559
&generate_po_template;
562
foreach my $lang (@languages) {
564
&update_po_file ($lang);
567
print "\n\n * Current translation support in $MODULE \n\n";
569
foreach my $lang (@languages){
571
system ("msgfmt", "--statistics", "$lang.po");
575
sub find_package_name
577
my $base_dirname = getcwd();
578
$base_dirname =~ s@.*/@@;
580
my ($conf_in, $src_dir);
582
if ($base_dirname =~ /^po(-.+)?$/) {
583
if (-f "../configure.in") {
584
$conf_in = "../configure.in";
585
} elsif (-f "../configure.ac") {
586
$conf_in = "../configure.ac";
590
open IN, "<Makefile" || die "can't open Makefile: $!";
593
if (/^top_srcdir[ \t]*=/) {
595
# print "${src_dir}\n";
597
$src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
598
# print "${src_dir}\n";
600
$conf_in = "$src_dir" . "/configure.in" . "\n";
604
$conf_in || die "Cannot find top_srcdir in Makefile."
610
open (IN, "<$conf_in") || die "can't open $conf_in: $!";
612
if (/^(\w+)=(\S+)/) { $varhash{$1} = $2 };
615
local $/; # slurp mode
620
$name = $1 if $conf_source =~ /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m;
621
if ($conf_source =~ /^AC_INIT\([\s\[]*([^,\)\s\]]+)\]?\s*,/m) {
623
$varhash{"AC_PACKAGE_NAME"} = $1;
625
$name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\s\]]+)/m;
627
$name = "\$AC_PACKAGE_NAME" if "$name" eq "AC_PACKAGE_NAME";
630
while (($name =~ /[\$](\S+)/) && ("$oldname" ne "$name")) {
632
if (exists $varhash{$1}) {
633
$name =~ s/[\$](\S+)/$varhash{$1}/;
636
return $name if $name;
639
print "$PROGRAM: Unable to determine package name.\n" .
640
"Make sure to run this script inside the po directory.\n";