1 #!@XML_I18N_TOOLS_PERL@ -w
3 # The GNOME Translation Update Tool
5 # Copyright (C) 2000 Free Software Foundation.
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This script 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 library; if not, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Author(s): Kenneth Christiansen
23 ## Release information
24 my $PROGRAM = "xml-i18n-update";
26 my $_PACKAGE = "xml-i18n-tools";
35 ## Scalars used by the option stuff
38 my $VERSION_ARG = "0";
41 my $HEADERS_ARG = "0";
42 my $MAINTAIN_ARG = "0";
47 my %po_files_by_lang = ();
50 "xml(\.in)*|". # .in is not required
52 "glade(\.in)*|". # .in is not required
63 my $PACKAGE = &find_package_name;
65 ## Always print as the first thing
68 ## Give error if script is run without an argument
70 print "${PROGRAM}: missing file arguments\n";
71 print "Try `${PROGRAM} --help' for more information.\n";
77 "help|h|?" => \$HELP_ARG,
78 "version|v" => \$VERSION_ARG,
79 "dist|d" => \$DIST_ARG,
81 "headers|s" => \$HEADERS_ARG,
82 "maintain|m" => \$MAINTAIN_ARG,
83 "report|r" => \$REPORT_ARG,
84 "verbose|x" => \$VERBOSE
88 ## Use the supplied arguments
90 ## This section will check for the different options.
92 sub split_on_argument {
100 } elsif ($DIST_ARG) {
108 } elsif ($HEADERS_ARG) {
112 } elsif ($MAINTAIN_ARG) {
115 } elsif ($REPORT_ARG) {
119 if ($LANG =~ /^-/){ ## not an option
135 print "Working, please wait..." unless $VERBOSE;
142 ## Report error if the language file supplied
143 ## to the command line is non-existent
149 sub determine_type($) {
154 if ($type =~ /\[type: (gettext\/[^\]].*)]/) {
157 elsif ($type =~ /(?:xml(\.in)*|ui|oaf(?:\.in)+|sheet(?:\.in)+|pong(?:\.in)+|etspec)$/) {
158 $gettext_type="gettext\/xml";
160 elsif ($type =~ /glade(\.in)*$/) {
161 $gettext_type="gettext\/glade";
163 elsif ($type =~ /(?:desktop(?:\.in)+|directory(?:\.in)+|soundlist(?:\.in)+)$/) {
164 $gettext_type="gettext\/ini";
166 elsif ($type =~ /keys(\.in)+$/) {
167 $gettext_type="gettext\/keys";
169 else { $gettext_type=""; }
171 return $gettext_type;
176 ## Print version information
177 print "${PROGRAM} (${_PACKAGE}) $VERSION\n";
178 print "Written by Kenneth Christiansen <kenneth\@gnome.org>, 2000.\n\n";
179 print "Copyright (C) 2000 Free Software Foundation, Inc.\n";
180 print "This is free software; see the source for copying conditions. There is NO\n";
181 print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
187 ## Print usage information
188 print "Usage: ./${PROGRAM} [OPTIONS] ...LANGCODE\n";
189 print "Updates pot files and merge them with the translations.\n\n";
190 print " -H, --help shows this help page\n";
191 print " -P, --pot generate the pot file only\n";
192 print " -S, --headers generate the XML headerfiles in POTFILES.in\n";
193 print " -M, --maintain search for missing files in POTFILES.in\n";
194 print " -R, --report creates a status report for the module.\n";
195 print " -X, --verbose show lots of feedback\n";
196 print " -V, --version shows the version\n";
197 print "\nExamples of use:\n";
198 print "${PROGRAM} --pot just creates a new pot file from the source\n";
199 print "${PROGRAM} da created new pot file and updated the da.po file\n\n";
200 print "Report bugs to <kenneth\@gnome.org>.\n";
209 @buf_potfiles_ignore,
211 @buf_allfiles_sorted,
215 ## Search and find all translatable files
216 find sub { push @buf_i18n_plain, "$File::Find::name" if /\.(c|y|cc|c\+\+|h|gob)$/ }, "..";
217 find sub { push @buf_i18n_xml, "$File::Find::name" if /\.($xml_extension)$/ }, "..";
219 open(POTFILES, "POTFILES.in") || die "$PROGRAM: there's no POTFILES.in!!!\n";
220 @buf_potfiles = <POTFILES>;
222 print "Searching for missing translatable files...\n";
224 ## Check if we should ignore some found files, when
225 ## comparing with POTFILES.in
226 if (-s "POTFILES.skip"){
227 open FILE, "POTFILES.skip";
230 push @buf_potfiles_ignore, $_;
233 print "Found POTFILES.skip: Ignoring files...\n";
234 @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
237 foreach my $file (@buf_i18n_plain){
241 ## Remove the first 3 chars and add newline
242 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
248 foreach my $file (@buf_i18n_xml){
252 ## Remove the first 3 chars and add newline
253 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
259 @buf_allfiles_sorted = sort (@buf_allfiles);
260 @buf_potfiles_sorted = sort (@buf_potfiles);
263 foreach (@buf_potfiles_sorted) {
269 foreach (@buf_allfiles_sorted){
270 if (!exists($in2{$_})){
275 ## Save file with information about the files missing
276 ## if any, and give information about this proceedier
278 open OUT, ">missing";
280 print "\nHere is the result:\n\n", @result, "\n";
281 print "The file \"missing\" has been placed in the current directory.\n";
282 print "Files supposed to be ignored should be placed in \"POTFILES.skip\"\n";
285 ## If there is nothing to complain about, notice the user
287 print "\nWell, it's all perfect! Congratulation!\n";
293 ## Handle invalid arguments
294 print "${PROGRAM}: invalid option -- $LANG\n";
295 print "Try `${PROGRAM} --help' for more information.\n";
301 my $XML_I18N_EXTRACT = `which xml-i18n-extract 2>/dev/null`;
302 chomp $XML_I18N_EXTRACT;
304 $XML_I18N_EXTRACT = $ENV{"XML_I18N_EXTRACT"} if $ENV{"XML_I18N_EXTRACT"};
306 ## Generate the .h header files, so we can allow glade and
307 ## xml translation support
308 if (! -s $XML_I18N_EXTRACT)
310 print "\n *** The xml-i18n-extract script wasn't found!"
311 ."\n *** Without this xml-i18n-update can not generate files.\n";
316 open FILE, "<POTFILES.in";
320 ## Find xml files in POTFILES.in and generate the
321 ## files with help from the xml-i18n-extract script
323 my $gettext_type=&determine_type($1);
325 if (/\.($xml_extension)$/ || /^\[/){
326 $_ =~ s/^\[[^\[].*]\s*//;
327 my $filename = "../$_";
330 system($XML_I18N_EXTRACT, "--update", "--type=$gettext_type", $filename);
332 system($XML_I18N_EXTRACT, "--update", "--type=$gettext_type", "--quiet", $filename);
342 ## Generate the potfiles from the POTFILES.in file
344 print "Building the $PACKAGE.pot...\n" if $VERBOSE;
346 move("POTFILES.in", "POTFILES.in.old");
348 open INFILE, "<POTFILES.in.old";
349 open OUTFILE, ">POTFILES.in";
351 s/\.($xml_extension)$/$&.h/;
352 s/^\[.*]\s*(.*)/$1.h/;
358 my $gettext_test ="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot "
359 ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)";
361 system("xgettext", "--default-domain\=$PACKAGE", "--directory\=\.\.",
362 "--add-comments", "--keyword\=\_", "--keyword\=N\_",
363 "--files-from\=\.\/POTFILES\.in");
365 system($gettext_test);
367 print "Wrote $PACKAGE.pot\n" if $VERBOSE;
369 move("POTFILES.in.old", "POTFILES.in");
371 print "Removing generated header (.h) files..." if $VERBOSE;
373 open FILE, "<POTFILES.in";
377 unlink "../$_.h" if /\.($xml_extension)$/;
380 print "done\n" if $VERBOSE;
391 if ($ARGV[0] ne "--dist" && $ARGV[0] ne "-D") {
392 print "Merging $LANG.po with $PACKAGE.pot..." if $VERBOSE;
395 &perform_merge($LANG);
396 ## Remove the "messages" trash file generated by gettext
404 copy("$LANG.po", "$LANG.po.old") || die "copy failed: $!";
407 system("msgmerge", "$LANG.po.old", "$PACKAGE.pot", "-o", "$LANG.po");
409 ## Remove the backup file
410 unlink "$LANG.po.old";
415 ## Report error if supplied language file is non-existing
416 print "$PROGRAM: sorry, $LANG.po does not exist!\n";
417 print "Try `$PROGRAM --help' for more information.\n";
423 my @po_files = glob("./*.po");
425 @languages = map (&po_file2lang, @po_files);
427 foreach my $lang (@languages) {
428 $po_files_by_lang{$lang} = shift (@po_files);
435 $tmp =~ s/^.*\/(.*)\.po$/$1/;
442 system("msgfmt", "--statistics", "$LANG.po");
452 foreach my $lang (@languages){
454 &perform_merge($lang);
457 print "\n\n * Current translation support in $PACKAGE \n\n";
459 foreach my $lang (@languages){
462 system("msgfmt", "--statistics", "$lang.po");
466 sub find_package_name
468 my $base_dirname = getcwd();
469 $base_dirname =~ s@.*/@@;
471 my ($conf_in, $src_dir);
473 if ($base_dirname eq "po") {
474 if (-f "../configure.in") {
475 $conf_in = "../configure.in";
479 open (IN, "<Makefile") || die "can't open Makefile: $!";
482 if (/^top_srcdir[ \t]*=/) {
484 # print "${src_dir}\n";
486 $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
487 # print "${src_dir}\n";
489 $conf_in = "$src_dir" . "/configure.in" . "\n";
493 $conf_in || die "Cannot find top_srcdir in Makefile."
498 local $/; # slurp mode
499 open (IN, "<$conf_in") || die "can't open $conf_in: $!";
503 if ($conf_source =~ /AM_INIT_AUTOMAKE\(([^,]*),(.*)/) {
504 my $package_name = $1;
505 if ($package_name =~ /^[\$](.*)/){
506 if ($conf_source =~ /$1=(.*)/) {
510 return $package_name;
514 print "$PROGRAM: Unable to determine package name.\n" .
515 "Make sure to run this script inside the po directory.\n";