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.37.1";
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 $PKGNAME = FindPackageName ();
129 # --version and --help don't require a module name
130 my $MODULE = $GETTEXT_PACKAGE || $PKGNAME || "unknown";
141 elsif ($MAINTAIN_ARG)
149 &Console_Write_CoverageReport;
151 elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
155 ## Report error if the language file supplied
156 ## to the command line is non-existent
157 &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
158 if ! -s "$SRCDIR/$lang.po";
162 print "Working, please wait..." if $VERBOSE;
166 &POFile_Update ($lang, $OUTPUT_FILE);
167 &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
171 &Console_Write_IntltoolHelp;
178 sub Console_Write_IntltoolVersion
181 ${PROGRAM} (${PACKAGE}) $VERSION
182 Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
184 Copyright (C) 2000-2003 Free Software Foundation, Inc.
185 This is free software; see the source for copying conditions. There is NO
186 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
191 sub Console_Write_IntltoolHelp
194 Usage: ${PROGRAM} [OPTION]... LANGCODE
195 Updates PO template files and merge them with the translations.
197 Mode of operation (only one is allowed):
198 -p, --pot generate the PO template only
199 -s, --headers generate the header files in POTFILES.in
200 -m, --maintain search for left out files from POTFILES.in
201 -r, --report display a status report for the module
202 -d, --dist merge LANGCODE.po with existing PO template
205 -g, --gettext-package=NAME override PO template name, useful with --pot
206 -o, --output-file=FILE write merged translation to FILE
207 -x, --verbose display lots of feedback
208 --help display this help and exit
209 --version output version information and exit
212 ${PROGRAM} --pot just create a new PO template
213 ${PROGRAM} xy create new PO template and merge xy.po with it
215 Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
216 or send email to <xml-i18n-tools\@gnome.org>.
224 my $ret = `echo "$str"`;
226 $ret =~ s/\n$//; # do we need the "s" flag?
231 sub POFile_DetermineType ($)
236 my $xml_regex = "(?:" . $xml_support . ")";
237 my $ini_regex = "(?:" . $ini_support . ")";
238 my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
240 if ($type =~ /\[type: gettext\/([^\]].*)]/)
244 elsif ($type =~ /schemas(\.in)+$/)
246 $gettext_type="schemas";
248 elsif ($type =~ /glade2?(\.in)*$/)
250 $gettext_type="glade";
252 elsif ($type =~ /scm(\.in)*$/)
254 $gettext_type="scheme";
256 elsif ($type =~ /keys(\.in)+$/)
258 $gettext_type="keys";
263 elsif ($type =~ /$xml_regex$/)
267 elsif ($type =~ /$ini_regex$/)
271 elsif ($type =~ /$buildin_regex$/)
273 $gettext_type="buildin";
277 $gettext_type="unknown";
280 return "gettext\/$gettext_type";
283 sub TextFile_DetermineEncoding ($)
285 my $gettext_code="ASCII"; # All files are ASCII by default
286 my $filetype=`file $_ | cut -d ' ' -f 2`;
290 if ($filetype =~ /^(ISO|UTF)/)
292 chomp ($gettext_code = $filetype);
294 elsif ($filetype =~ /^XML/)
296 $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
300 return $gettext_code;
303 sub isNotValidMissing
307 return if $file =~ /^\{arch\}\/.*$/;
308 return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
315 @buf_i18n_xml_unmarked,
318 @buf_potfiles_ignore,
320 @buf_allfiles_sorted,
321 @buf_potfiles_sorted,
322 @buf_potfiles_ignore_sorted
325 ## Search and find all translatable files
327 push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
328 push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
329 push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
330 push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
333 push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
334 push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
335 push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
336 push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
337 }, "$SRCDIR/.." if "$SRCDIR" ne ".";
339 open POTFILES, $POTFILES_in or die "$PROGRAM: there's no POTFILES.in!\n";
340 @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
343 foreach (@buf_potfiles) {
347 print "Searching for missing translatable files...\n" if $VERBOSE;
349 ## Check if we should ignore some found files, when
350 ## comparing with POTFILES.in
351 foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
353 (-s "$SRCDIR/$ignore") or next;
355 if ("$ignore" eq "POTFILES.ignore")
357 print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
358 "content of this file to POTFILES.skip.\n";
361 print "Found $ignore: Ignoring files...\n" if $VERBOSE;
362 open FILE, "<$SRCDIR/$ignore" or die "ERROR: Failed to open $SRCDIR/$ignore!\n";
366 push @buf_potfiles_ignore, $_ unless /^(#|\s*$)/;
370 @buf_potfiles_ignore_sorted = sort (@buf_potfiles_ignore);
373 foreach my $file (@buf_i18n_plain)
381 # Handle continued multi-line comment.
384 next unless s-.*\*/--;
388 # Handle continued macro.
391 $in_macro = 0 unless /\\$/;
395 # Handle start of macro (or any preprocessor directive).
398 $in_macro = 1 if /^([^\\]|\\.)*\\$/;
402 # Handle comments and quoted text.
403 while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
414 elsif ($match eq "//")
420 if (!s-$match([^\\]|\\.)*?$match-QUOTEDTEXT-)
422 warn "mismatched quotes at line $. in $file\n";
428 if (/\w\.GetString *\(QUOTEDTEXT/)
430 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
431 ## Remove the first 3 chars and add newline
432 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
437 ## C_ N_ Q_ and _ are the macros defined in gi8n.h
438 if (/[CNQ]?_ *\(QUOTEDTEXT/)
440 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
441 ## Remove the first 3 chars and add newline
442 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
450 foreach my $file (@buf_i18n_xml)
456 # FIXME: share the pattern matching code with intltool-extract
457 if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
459 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
460 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
468 foreach my $file (@buf_i18n_ini)
475 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
476 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
484 foreach my $file (@buf_i18n_xml_unmarked)
486 if (defined isNotValidMissing (unpack("x3 A*", $file))) {
487 push @buf_allfiles, unpack("x3 A*", $file) . "\n";
492 @buf_allfiles_sorted = sort (@buf_allfiles);
493 @buf_potfiles_sorted = sort (@buf_potfiles);
496 foreach (@buf_potfiles_sorted)
503 foreach (@buf_potfiles_ignore_sorted)
512 foreach (@buf_allfiles_sorted)
515 my $srcdir = $SRCDIR;
518 $dummy =~ s#^$srcdir/../##;
519 $dummy =~ s#^$srcdir/##;
520 $dummy =~ s#_build/##;
521 if (!exists($in2{$dummy}))
527 my @buf_potfiles_notexist;
529 foreach (@buf_potfiles_sorted)
531 chomp (my $dummy = $_);
532 if ("$dummy" ne "" and !(-f "$SRCDIR/../$dummy" or -f "../$dummy"))
534 push @buf_potfiles_notexist, $_;
538 ## Save file with information about the files missing
539 ## if any, and give information about this procedure.
540 if (@result + @buf_potfiles_notexist > 0)
544 print "\n" if $VERBOSE;
546 open OUT, ">missing";
549 warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
550 "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
551 print STDERR @result, "\n";
552 warn "If some of these files are left out on purpose then please add them to\n".
553 "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
554 "of left out files has been written in the current directory.\n";
556 if (@buf_potfiles_notexist)
559 open OUT, ">notexist";
560 print OUT @buf_potfiles_notexist;
562 warn "\n" if ($VERBOSE or @result);
563 warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
564 warn @buf_potfiles_notexist, "\n";
565 warn "Please remove them from POTFILES.in. A file \e[1m'notexist'\e[0m\n".
566 "containing this list of absent files has been written in the current directory.\n";
570 ## If there is nothing to complain about, notify the user
572 print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
576 sub Console_WriteError_InvalidOption
578 ## Handle invalid arguments
579 print STDERR "Try `${PROGRAM} --help' for more information.\n";
586 # If either a file exists, or when run it returns 0 exit status
587 return 1 if ((-x $file) or (system("$file --version >$devnull") == 0));
594 # Check that we are using GNU gettext tools
595 if (isProgramInPath ($file))
597 my $version = `$file --version`;
598 return 1 if ($version =~ m/.*\(GNU .*\).*/);
605 my $EXTRACT = $ENV{"INTLTOOL_EXTRACT"} || "intltool-extract";
607 ## Generate the .h header files, so we can allow glade and
608 ## xml translation support
609 if (! isProgramInPath ("$EXTRACT"))
611 print STDERR "\n *** The intltool-extract script wasn't found!"
612 ."\n *** Without it, intltool-update can not generate files.\n";
617 open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
622 next if /^\[\s*encoding/;
624 ## Find xml files in POTFILES.in and generate the
625 ## files with help from the extract script
627 my $gettext_type= &POFile_DetermineType ($1);
629 if (/\.($xml_support|$ini_support)$/ || /^\[/)
633 my $filename = "../$_";
637 system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
638 "--type=$gettext_type", $filename);
642 system ($EXTRACT, "--update", "--type=$gettext_type",
643 "--srcdir=$SRCDIR", "--quiet", $filename);
652 # Generate .pot file from POTFILES.in
654 sub GeneratePOTemplate
656 my $XGETTEXT = $ENV{"XGETTEXT"} || "xgettext";
657 my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
660 if (! isGNUGettextTool ("$XGETTEXT"))
662 print STDERR " *** GNU xgettext is not found on this system!\n".
663 " *** Without it, intltool-update can not extract strings.\n";
667 print "Building $MODULE.pot...\n" if $VERBOSE;
669 open INFILE, $POTFILES_in;
670 unlink "POTFILES.in.temp";
671 open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
673 my $gettext_support_nonascii = 0;
675 # checks for GNU gettext >= 0.12
676 my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
679 $gettext_support_nonascii = 1;
683 # urge everybody to upgrade gettext
684 print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
685 " strings. That means you should install a version of gettext\n".
686 " that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
687 " or have to let non-ASCII strings untranslated. (If there is any)\n";
690 my $encoding = "ASCII";
691 my $forced_gettext_code;
693 my $encoding_problem_is_reported = 0;
697 next if (/^#/ or /^\s*$/);
703 if (/^\[\s*encoding:\s*(.*)\s*\]/)
705 $forced_gettext_code=$1;
707 elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
710 print OUTFILE "../$_.h\n";
711 push @temp_headers, "../$_.h";
712 $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
716 print OUTFILE "$SRCDIR/../$_\n";
717 $gettext_code = &TextFile_DetermineEncoding ("$SRCDIR/../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
720 next if (! $gettext_support_nonascii);
722 if (defined $forced_gettext_code)
724 $encoding=$forced_gettext_code;
726 elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
728 if ($encoding eq "ASCII")
730 $encoding=$gettext_code;
732 elsif ($gettext_code ne "ASCII")
734 # Only report once because the message is quite long
735 if (! $encoding_problem_is_reported)
737 print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
738 " but $PROGRAM thinks that most of the source files are in\n".
739 " $encoding encoding, while \"$_\" is (likely) in\n".
740 " $gettext_code encoding. If you are sure that all translatable strings\n".
741 " are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
742 " line to POTFILES.in:\n\n".
743 " [encoding: UTF-8]\n\n".
744 " and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
745 "(such warning message will only be reported once.)\n";
746 $encoding_problem_is_reported = 1;
755 unlink "$MODULE.pot";
756 my @xgettext_argument=("$XGETTEXT",
759 "--default-domain\=$MODULE",
760 "--flag\=g_strdup_printf:1:c-format",
761 "--flag\=g_string_printf:2:c-format",
762 "--flag\=g_string_append_printf:2:c-format",
763 "--flag\=g_error_new:3:c-format",
764 "--flag\=g_set_error:4:c-format",
765 "--flag\=g_markup_printf_escaped:1:c-format",
766 "--flag\=g_log:3:c-format",
767 "--flag\=g_print:1:c-format",
768 "--flag\=g_printerr:1:c-format",
769 "--flag\=g_printf:1:c-format",
770 "--flag\=g_fprintf:2:c-format",
771 "--flag\=g_sprintf:2:c-format",
772 "--flag\=g_snprintf:3:c-format",
773 "--flag\=g_scanner_error:2:c-format",
774 "--flag\=g_scanner_warn:2:c-format",
775 "--output\=$MODULE\.pot",
776 "--files-from\=\.\/POTFILES\.in\.temp");
777 my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
778 push @xgettext_argument, $XGETTEXT_KEYWORDS;
779 my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
780 push @xgettext_argument, "--msgid-bugs-address\=\"$MSGID_BUGS_ADDRESS\"" if $MSGID_BUGS_ADDRESS;
781 push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
782 push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
783 my $xgettext_command = join ' ', @xgettext_argument;
785 # intercept xgettext error message
786 print "Running $xgettext_command\n" if $VERBOSE;
787 my $xgettext_error_msg = `$xgettext_command 2>\&1`;
788 my $command_failed = $?;
790 unlink "POTFILES.in.temp";
792 print "Removing generated header (.h) files..." if $VERBOSE;
793 unlink foreach (@temp_headers);
794 print "done.\n" if $VERBOSE;
796 if (! $command_failed)
798 if (! -e "$MODULE.pot")
800 print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
804 print "Wrote $MODULE.pot\n" if $VERBOSE;
809 if ($xgettext_error_msg =~ /--from-code/)
811 # replace non-ASCII error message with a more useful one.
812 print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n".
813 " string marked for translation. Please make sure that all strings marked\n".
814 " for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n".
815 " following line to POTFILES.in and rerun $PROGRAM:\n\n".
816 " [encoding: UTF-8]\n\n";
820 print STDERR "$xgettext_error_msg";
821 if (-e "$MODULE.pot")
824 print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
825 " Please consult error message above if there is any.\n";
829 print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
830 " error message above if there is any.\n";
839 -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
841 my $MSGMERGE = $ENV{"MSGMERGE"} || "msgmerge";
842 my ($lang, $outfile) = @_;
844 if (! isGNUGettextTool ("$MSGMERGE"))
846 print STDERR " *** GNU msgmerge is not found on this system!\n".
847 " *** Without it, intltool-update can not extract strings.\n";
851 print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
853 my $infile = "$SRCDIR/$lang.po";
854 $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
856 # I think msgmerge won't overwrite old file if merge is not successful
857 system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
860 sub Console_WriteError_NotExisting
864 ## Report error if supplied language file is non-existing
865 print STDERR "$PROGRAM: $file does not exist!\n";
866 print STDERR "Try '$PROGRAM --help' for more information.\n";
872 my @po_files = glob ("./*.po");
874 @languages = map (&POFile_GetLanguage, @po_files);
876 foreach my $lang (@languages)
878 $po_files_by_lang{$lang} = shift (@po_files);
882 sub POFile_GetLanguage ($)
884 s/^(.*\/)?(.+)\.po$/$2/;
888 sub Console_Write_TranslationStatus
890 my ($lang, $output_file) = @_;
891 my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
893 if (! isGNUGettextTool ("$MSGFMT"))
895 print STDERR " *** GNU msgfmt is not found on this system!\n".
896 " *** Without it, intltool-update can not extract strings.\n";
900 $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
902 system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
905 sub Console_Write_CoverageReport
907 my $MSGFMT = $ENV{"MSGFMT"} || "msgfmt";
909 if (! isGNUGettextTool ("$MSGFMT"))
911 print STDERR " *** GNU msgfmt is not found on this system!\n".
912 " *** Without it, intltool-update can not extract strings.\n";
918 foreach my $lang (@languages)
920 print STDERR "$lang: ";
921 &POFile_Update ($lang, "");
924 print STDERR "\n\n * Current translation support in $MODULE \n\n";
926 foreach my $lang (@languages)
928 print STDERR "$lang: ";
929 system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
933 sub SubstituteVariable
937 # always need to rewind file whenever it has been accessed
940 # cache each variable. varhash is global to we can add
941 # variables elsewhere.
946 ($varhash{$1} = $2) =~ s/^["'](.*)["']$/$1/;
950 if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
955 # Ignore recursive definitions of variables
956 $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
958 return SubstituteVariable ("$untouched$sub$rest");
961 # We're using Perl backticks ` and "echo -n" here in order to
962 # expand any shell escapes (such as backticks themselves) in every variable
963 return echo_n ($str);
968 my $base_dirname = getcwd();
969 $base_dirname =~ s@.*/@@;
971 my ($conf_in, $src_dir);
973 if ($base_dirname =~ /^po(-.+)?$/)
980 open (IN, "<Makevars") || die "can't open Makevars: $!";
984 if (/^top_builddir[ \t]*=/)
987 $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
990 if (-f "$src_dir" . "/configure.ac") {
991 $conf_in = "$src_dir" . "/configure.ac" . "\n";
993 $conf_in = "$src_dir" . "/configure.in" . "\n";
1000 $conf_in || die "Cannot find top_builddir in Makevars.";
1002 elsif (-f "$SRCDIR/../configure.ac")
1004 $conf_in = "$SRCDIR/../configure.ac";
1006 elsif (-f "$SRCDIR/../configure.in")
1008 $conf_in = "$SRCDIR/../configure.in";
1012 my $makefile_source;
1015 open (IN, "<Makefile") || return;
1019 if (/^top_srcdir[ \t]*=/)
1022 $src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
1025 $conf_in = "$src_dir" . "/configure.in" . "\n";
1032 $conf_in || die "Cannot find top_srcdir in Makefile.";
1035 open (CONF, "<$conf_in");
1039 print STDERR "$PROGRAM: Unable to proceed.\n" .
1040 "Make sure to run this script inside the po directory.\n";
1048 my $domain = &FindMakevarsDomain;
1049 my $name = $domain || "untitled";
1055 open (IN, "<&CONF") || return $name;
1057 local $/; # slurp mode
1058 $conf_source = <IN>;
1062 # priority for getting package name:
1063 # 1. GETTEXT_PACKAGE
1064 # 2. first argument of AC_INIT (with >= 2 arguments)
1065 # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
1067 # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m
1068 # the \s makes this not work, why?
1069 if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
1071 ($name, $version) = ($1, $2);
1072 $name =~ s/[\[\]\s]//g;
1073 $version =~ s/[\[\]\s]//g;
1074 $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1075 $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1076 $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1077 $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1080 if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m)
1082 ($name, $version) = ($1, $2);
1083 $name =~ s/[\[\]\s]//g;
1084 $version =~ s/[\[\]\s]//g;
1085 $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
1086 $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
1087 $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
1088 $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
1091 # \s makes this not work, why?
1092 $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
1094 # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
1095 # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
1096 $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
1098 $name = $domain if $domain;
1100 $name = SubstituteVariable ($name);
1101 $name =~ s/^["'](.*)["']$/$1/;
1103 return $name if $name;
1110 my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_";
1111 my $varname = "XGETTEXT_OPTIONS";
1114 open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
1116 local $/; # slurp mode
1117 $make_source = <IN>;
1121 # unwrap lines split with a trailing \
1122 $make_source =~ s/\\ $ \n/ /mxg;
1123 $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
1128 sub FindMakevarsDomain
1132 my $makevars_source; {
1134 open (IN, "<Makevars") || return $domain;
1136 local $/; # slurp mode
1137 $makevars_source = <IN>;
1141 $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
1142 $domain =~ s/^\s+//;
1143 $domain =~ s/\s+$//;
1148 sub FindMakevarsBugAddress
1152 my $makevars_source; {
1154 open (IN, "<Makevars") || return undef;
1156 local $/; # slurp mode
1157 $makevars_source = <IN>;
1161 $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
1162 $address =~ s/^\s+//;
1163 $address =~ s/\s+$//;