aboutsummaryrefslogtreecommitdiffstats
path: root/intltool-update.in
diff options
context:
space:
mode:
authorAlessio Treglia <alessio@debian.org>2014-07-21 13:58:29 +0100
committerAlessio Treglia <alessio@debian.org>2014-07-21 13:58:29 +0100
commite25104d1480e03993980d944d21d788a95ecd09d (patch)
tree96b84cc4baac713ad7ab3e887395f9febb91a462 /intltool-update.in
parent6ef14034edff72de856c29dd2e4f2b180444d890 (diff)
Imported Upstream version 0.18upstream/0.18
Diffstat (limited to 'intltool-update.in')
-rw-r--r--intltool-update.in986
1 files changed, 653 insertions, 333 deletions
diff --git a/intltool-update.in b/intltool-update.in
index 180c40b..661d8fe 100644
--- a/intltool-update.in
+++ b/intltool-update.in
@@ -1,9 +1,10 @@
#!@INTLTOOL_PERL@ -w
+# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# The Intltool Message Updater
#
-# Copyright (C) 2000-2002 Free Software Foundation.
+# Copyright (C) 2000-2003 Free Software Foundation.
#
# Intltool is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -29,7 +30,7 @@
## Release information
my $PROGRAM = "intltool-update";
-my $VERSION = "0.26";
+my $VERSION = "0.35.0";
my $PACKAGE = "intltool";
## Loaded modules
@@ -52,36 +53,51 @@ my $GETTEXT_PACKAGE = "";
my $OUTPUT_FILE = "";
my @languages;
-my $conf_file; # remove later
my %varhash = ();
my %po_files_by_lang = ();
# Regular expressions to categorize file types.
# FIXME: Please check if the following is correct
-my $xml_extension =
-"xml(\.in)*|". # .in is not required
-"ui|".
-"glade2?(\.in)*|". # .in is not required
-"scm(\.in)*|". # .in is not required
-"oaf(\.in)+|".
-"etspec|".
-"sheet(\.in)+|".
-"schemas(\.in)+|".
-"pong(\.in)+";
-
-my $ini_extension =
-"desktop(\.in)+|".
-"caves(\.in)+|".
-"directory(\.in)+|".
-"soundlist(\.in)+|".
-"keys(\.in)+|".
-"theme(\.in)+|".
-"server(\.in)+";
-
-## Always print as the first thing
+my $xml_support =
+"xml(?:\\.in)*|". # http://www.w3.org/XML/ (Note: .in is not required)
+"ui|". # Bonobo specific - User Interface desc. files
+"lang|". # ?
+"glade2?(?:\\.in)*|". # Glade specific - User Interface desc. files (Note: .in is not required)
+"scm(?:\\.in)*|". # ? (Note: .in is not required)
+"oaf(?:\\.in)+|". # DEPRECATED: Replaces by Bonobo .server files
+"etspec|". # ?
+"server(?:\\.in)+|". # Bonobo specific
+"sheet(?:\\.in)+|". # ?
+"schemas(?:\\.in)+|". # GConf specific
+"pong(?:\\.in)+|". # DEPRECATED: PONG is not used [by GNOME] any longer.
+"kbd(?:\\.in)+"; # GOK specific.
+
+my $ini_support =
+"icon(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
+"desktop(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
+"caves(?:\\.in)+|". # GNOME Games specific
+"directory(?:\\.in)+|". # http://www.freedesktop.org/Standards/menu-spec
+"soundlist(?:\\.in)+|". # GNOME specific
+"keys(?:\\.in)+|". # GNOME Mime database specific
+"theme(?:\\.in)+|". # http://www.freedesktop.org/Standards/icon-theme-spec
+"service(?:\\.in)+"; # DBus specific
+
+my $buildin_gettext_support =
+"c|y|cs|cc|cpp|c\\+\\+|h|hh|gob|py";
+
+## Always flush buffer when printing
$| = 1;
+## Sometimes the source tree will be rooted somewhere else.
+my $SRCDIR = ".";
+my $POTFILES_in;
+
+$SRCDIR = $ENV{"srcdir"} if $ENV{"srcdir"};
+$POTFILES_in = "<$SRCDIR/POTFILES.in";
+
+my $devnull = ($^O eq 'MSWin32' ? 'NUL:' : '/dev/null');
+
## Handle options
GetOptions
(
@@ -95,10 +111,10 @@ GetOptions
"verbose|x" => \$VERBOSE,
"gettext-package|g=s" => \$GETTEXT_PACKAGE,
"output-file|o=s" => \$OUTPUT_FILE,
- ) or &print_error_invalid_option;
+ ) or &Console_WriteError_InvalidOption;
-&print_help if $HELP_ARG;
-&print_version if $VERSION_ARG;
+&Console_Write_IntltoolHelp if $HELP_ARG;
+&Console_Write_IntltoolVersion if $VERSION_ARG;
my $arg_count = ($DIST_ARG > 0)
+ ($POT_ARG > 0)
@@ -106,134 +122,131 @@ my $arg_count = ($DIST_ARG > 0)
+ ($MAINTAIN_ARG > 0)
+ ($REPORT_ARG > 0);
-&print_help if $arg_count > 1;
+&Console_Write_IntltoolHelp if $arg_count > 1;
# --version and --help don't require a module name
-my $MODULE = $GETTEXT_PACKAGE || &find_package_name;
+my $MODULE = $GETTEXT_PACKAGE || &FindPackageName || "unknown";
-if ($DIST_ARG)
+if ($POT_ARG)
{
- if ($ARGV[0] =~ /^[a-z]/)
- {
- &update_po_file ($ARGV[0], $OUTPUT_FILE);
- &print_status ($ARGV[0], $OUTPUT_FILE);
- }
- else
- {
- &print_help;
- }
-}
-elsif ($POT_ARG)
+ &GenerateHeaders;
+ &GeneratePOTemplate;
+}
+elsif ($HEADERS_ARG)
{
- &generate_headers;
- &generate_po_template;
-}
-elsif ($HEADERS_ARG)
+ &GenerateHeaders;
+}
+elsif ($MAINTAIN_ARG)
{
- &generate_headers;
-}
-elsif ($MAINTAIN_ARG)
+ &FindLeftoutFiles;
+}
+elsif ($REPORT_ARG)
{
- &find_leftout_files;
-}
-elsif ($REPORT_ARG)
+ &GenerateHeaders;
+ &GeneratePOTemplate;
+ &Console_Write_CoverageReport;
+}
+elsif ((defined $ARGV[0]) && $ARGV[0] =~ /^[a-z]/)
{
- &print_report;
+ my $lang = $ARGV[0];
+
+ ## Report error if the language file supplied
+ ## to the command line is non-existent
+ &Console_WriteError_NotExisting("$SRCDIR/$lang.po")
+ if ! -s "$SRCDIR/$lang.po";
+
+ if (!$DIST_ARG)
+ {
+ print "Working, please wait..." if $VERBOSE;
+ &GenerateHeaders;
+ &GeneratePOTemplate;
+ }
+ &POFile_Update ($lang, $OUTPUT_FILE);
+ &Console_Write_TranslationStatus ($lang, $OUTPUT_FILE);
}
else
{
- if ($ARGV[0] =~ /^[a-z]/)
- {
- &main ($ARGV[0], $OUTPUT_FILE);
- }
- else
- {
- &print_help;
- }
+ &Console_Write_IntltoolHelp;
}
exit;
#########
-sub print_version
+sub Console_Write_IntltoolVersion
{
- ## Print version information
- print "${PROGRAM} (${PACKAGE}) $VERSION\n";
- print "Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.\n\n";
- print "Copyright (C) 2000-2002 Free Software Foundation, Inc.\n";
- print "This is free software; see the source for copying conditions. There is NO\n";
- print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
+ print <<_EOF_;
+${PROGRAM} (${PACKAGE}) $VERSION
+Written by Kenneth Christiansen, Maciej Stachowiak, and Darin Adler.
+
+Copyright (C) 2000-2003 Free Software Foundation, Inc.
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+_EOF_
exit;
}
-sub print_help
+sub Console_Write_IntltoolHelp
{
- ## Print usage information
- print "Usage: ${PROGRAM} [OPTIONS] ...LANGCODE\n";
- print "Updates PO template files and merge them with the translations.\n\n";
- print " -p, --pot generate the PO template only\n";
- print " -s, --headers generate the header files in POTFILES.in\n";
- print " -m, --maintain search for left out files from POTFILES.in\n";
- print " -r, --report display a status report for the module.\n";
- print " -x, --verbose display lots of feedback\n";
- print " --help display this help and exit\n";
- print " --version output version information and exit\n";
- print "\nExamples of use:\n";
- print "${PROGRAM} --pot just creates a new PO template from the source\n";
- print "${PROGRAM} da created new PO template and updated the da.po file\n\n";
- print "Report bugs to bugzilla.gnome.org, module 'intltool'.\n";
+ print <<_EOF_;
+Usage: ${PROGRAM} [OPTION]... LANGCODE
+Updates PO template files and merge them with the translations.
+
+Mode of operation (only one is allowed):
+ -p, --pot generate the PO template only
+ -s, --headers generate the header files in POTFILES.in
+ -m, --maintain search for left out files from POTFILES.in
+ -r, --report display a status report for the module
+ -d, --dist merge LANGCODE.po with existing PO template
+
+Extra options:
+ -g, --gettext-package=NAME override PO template name, useful with --pot
+ -o, --output-file=FILE write merged translation to FILE
+ -x, --verbose display lots of feedback
+ --help display this help and exit
+ --version output version information and exit
+
+Examples of use:
+${PROGRAM} --pot just create a new PO template
+${PROGRAM} xy create new PO template and merge xy.po with it
+
+Report bugs to http://bugzilla.gnome.org/ (product name "$PACKAGE")
+or send email to <xml-i18n-tools\@gnome.org>.
+_EOF_
exit;
}
-sub main
+sub echo_n
{
- my ($lang, $output_file) = @_;
-
- ## Report error if the language file supplied
- ## to the command line is non-existent
- &print_error_not_existing("$lang.po") if ! -s "$lang.po";
+ my $str = shift;
+ my $ret = `echo "$str"`;
+
+ $ret =~ s/\n$//; # do we need the "s" flag?
- print "Working, please wait..." if $VERBOSE;
- &generate_headers;
- &generate_po_template;
- &update_po_file ($lang, $output_file);
- &print_status ($lang, $output_file);
+ return $ret;
}
-sub determine_type ($)
+sub POFile_DetermineType ($)
{
my $type = $_;
my $gettext_type;
- # FIXME: Use $xml_extentions, and maybe do all this even nicer
- my $xml_regex =
- "(?:xml(\.in)*|ui|oaf(?:\.in)+|server(?:\.in)+|sheet(?:\.in)+|".
- "pong(?:\.in)+|etspec|schemas(?:\.in)+)";
- my $ini_regex =
- "(?:desktop(?:\.in)+|theme(?:\.in)+|caves(?:\.in)+|directory(?:\.in)+|".
- "soundlist(?:\.in)+)";
+ my $xml_regex = "(?:" . $xml_support . ")";
+ my $ini_regex = "(?:" . $ini_support . ")";
+ my $buildin_regex = "(?:" . $buildin_gettext_support . ")";
if ($type =~ /\[type: gettext\/([^\]].*)]/)
{
- $gettext_type=$1;
+ $gettext_type=$1;
}
elsif ($type =~ /schemas(\.in)+$/)
{
- $gettext_type="schemas";
- }
- elsif ($type =~ /$xml_regex$/)
- {
- $gettext_type="xml";
+ $gettext_type="schemas";
}
elsif ($type =~ /glade2?(\.in)*$/)
{
$gettext_type="glade";
}
- elsif ($type =~ /$ini_regex$/)
- {
- $gettext_type="ini";
- }
elsif ($type =~ /scm(\.in)*$/)
{
$gettext_type="scheme";
@@ -242,15 +255,58 @@ sub determine_type ($)
{
$gettext_type="keys";
}
- else
+
+ # bucket types
+
+ elsif ($type =~ /$xml_regex$/)
+ {
+ $gettext_type="xml";
+ }
+ elsif ($type =~ /$ini_regex$/)
{
- $gettext_type="";
+ $gettext_type="ini";
+ }
+ elsif ($type =~ /$buildin_regex$/)
+ {
+ $gettext_type="buildin";
+ }
+ else
+ {
+ $gettext_type="unknown";
}
return "gettext\/$gettext_type";
}
-sub find_leftout_files
+sub TextFile_DetermineEncoding ($)
+{
+ my $gettext_code="ASCII"; # All files are ASCII by default
+ my $filetype=`file $_ | cut -d ' ' -f 2`;
+
+ if ($? eq "0")
+ {
+ if ($filetype =~ /^(ISO|UTF)/)
+ {
+ chomp ($gettext_code = $filetype);
+ }
+ elsif ($filetype =~ /^XML/)
+ {
+ $gettext_code="UTF-8"; # We asume that .glade and other .xml files are UTF-8
+ }
+ }
+
+ return $gettext_code;
+}
+
+sub isNotValidMissing
+{
+ my ($file) = @_;
+
+ return if $file =~ /^\{arch\}\/.*$/;
+ return if $file =~ /^$varhash{"PACKAGE"}-$varhash{"VERSION"}\/.*$/;
+}
+
+sub FindLeftoutFiles
{
my (@buf_i18n_plain,
@buf_i18n_xml,
@@ -265,55 +321,54 @@ sub find_leftout_files
## Search and find all translatable files
find sub {
- push @buf_i18n_plain, "$File::Find::name" if /\.(c|y|cc|cpp|c\+\+|h|gob)$/
+ push @buf_i18n_plain, "$File::Find::name" if /\.($buildin_gettext_support)$/;
+ push @buf_i18n_xml, "$File::Find::name" if /\.($xml_support)$/;
+ push @buf_i18n_ini, "$File::Find::name" if /\.($ini_support)$/;
+ push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/;
}, "..";
- find sub {
- push @buf_i18n_xml, "$File::Find::name" if /\.($xml_extension)$/
- }, "..";
- find sub {
- push @buf_i18n_ini, "$File::Find::name" if /\.($ini_extension)$/
- }, "..";
- find sub {
- push @buf_i18n_xml_unmarked, "$File::Find::name" if /\.(schemas(\.in)+)$/
- }, "..";
- open POTFILES, "POTFILES.in" or die "$PROGRAM: there's no POTFILES.in!\n";
+ open POTFILES, $POTFILES_in or die "$PROGRAM: there's no POTFILES.in!\n";
+ @buf_potfiles = grep !/^(#|\s*$)/, <POTFILES>;
+ close POTFILES;
- @buf_potfiles = grep /^[^#]/, <POTFILES>;
foreach (@buf_potfiles) {
- s/^\[.*]\s*//;
+ s/^\[.*]\s*//;
}
-
+
print "Searching for missing translatable files...\n" if $VERBOSE;
## Check if we should ignore some found files, when
## comparing with POTFILES.in
- foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
+ foreach my $ignore ("POTFILES.skip", "POTFILES.ignore")
{
- if (-s $ignore)
- {
- open FILE, $ignore;
-
- while (<FILE>)
- {
- if (/^[^#]/)
- {
- push @buf_potfiles_ignore, $_;
- }
- }
- print "Found $ignore: Ignoring files...\n" if $VERBOSE;
- @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
- }
+ (-s $ignore) or next;
+
+ if ("$ignore" eq "POTFILES.ignore")
+ {
+ print "The usage of POTFILES.ignore is deprecated. Please consider moving the\n".
+ "content of this file to POTFILES.skip.\n";
+ }
+
+ print "Found $ignore: Ignoring files...\n" if $VERBOSE;
+ open FILE, "<$ignore" or die "ERROR: Failed to open $ignore!\n";
+
+ while (<FILE>)
+ {
+ push @buf_potfiles_ignore, $_ unless /^(#|\s*$)/;
+ }
+ close FILE;
+
+ @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles);
}
foreach my $file (@buf_i18n_plain)
{
- my $in_comment = 0;
+ my $in_comment = 0;
my $in_macro = 0;
- open FILE, "<$file";
- while (<FILE>)
+ open FILE, "<$file";
+ while (<FILE>)
{
# Handle continued multi-line comment.
if ($in_comment)
@@ -321,21 +376,21 @@ sub find_leftout_files
next unless s-.*\*/--;
$in_comment = 0;
}
-
+
# Handle continued macro.
if ($in_macro)
{
$in_macro = 0 unless /\\$/;
next;
}
-
+
# Handle start of macro (or any preprocessor directive).
if (/^\s*\#/)
{
$in_macro = 1 if /^([^\\]|\\.)*\\$/;
next;
}
-
+
# Handle comments and quoted text.
while (m-(/\*|//|\'|\")-) # \' and \" keep emacs perl mode happy
{
@@ -361,47 +416,67 @@ sub find_leftout_files
}
}
}
-
+
+ if (/\.GetString ?\(QUOTEDTEXT/)
+ {
+ if (defined isNotValidMissing (unpack("x3 A*", $file))) {
+ ## Remove the first 3 chars and add newline
+ push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ }
+ last;
+ }
+
if (/_\(QUOTEDTEXT/)
{
- ## Remove the first 3 chars and add newline
- push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ if (defined isNotValidMissing (unpack("x3 A*", $file))) {
+ ## Remove the first 3 chars and add newline
+ push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ }
last;
}
}
close FILE;
}
-
+
foreach my $file (@buf_i18n_xml)
{
- open FILE, "<$file";
-
+ open FILE, "<$file";
+
while (<FILE>)
{
- if (/\s_(.*)=\"/ || /translatable=\"yes\"/)
+ # FIXME: share the pattern matching code with intltool-extract
+ if (/\s_[-A-Za-z0-9._:]+\s*=\s*\"([^"]+)\"/ || /<_[^>]+>/ || /translatable=\"yes\"/)
{
- push @buf_allfiles, unpack("x3 A*", $file) . "\n";
- last;
- }
- }
+ if (defined isNotValidMissing (unpack("x3 A*", $file))) {
+ push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ }
+ last;
+ }
+ }
+ close FILE;
}
foreach my $file (@buf_i18n_ini)
{
- open FILE, "<$file";
- while (<FILE>)
+ open FILE, "<$file";
+ while (<FILE>)
{
- if (/_(.*)=/)
+ if (/_(.*)=/)
{
- push @buf_allfiles, unpack("x3 A*", $file) . "\n";
- last;
- }
- }
+ if (defined isNotValidMissing (unpack("x3 A*", $file))) {
+ push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ }
+ last;
+ }
+ }
+ close FILE;
}
foreach my $file (@buf_i18n_xml_unmarked)
{
- push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ if (defined isNotValidMissing (unpack("x3 A*", $file))) {
+ push @buf_allfiles, unpack("x3 A*", $file) . "\n";
+ }
}
@@ -411,57 +486,85 @@ sub find_leftout_files
my %in2;
foreach (@buf_potfiles_sorted)
{
- $in2{$_} = 1;
+ $in2{$_} = 1;
}
my @result;
foreach (@buf_allfiles_sorted)
{
- if (!exists($in2{$_}))
+ if (!exists($in2{$_}))
{
- push @result, $_
- }
+ push @result, $_
+ }
+ }
+
+ my @buf_potfiles_notexist;
+
+ foreach (@buf_potfiles_sorted)
+ {
+ chomp (my $dummy = $_);
+ if ("$dummy" ne "" and ! -f "../$dummy")
+ {
+ push @buf_potfiles_notexist, $_;
+ }
}
## Save file with information about the files missing
## if any, and give information about this procedure.
- if (@result)
+ if (@result + @buf_potfiles_notexist > 0)
{
- print "\n" if $VERBOSE;
- open OUT, ">missing";
- print OUT @result;
- print STDERR "The following files contain translations and are currently not in use. Please\n";
- print STDERR "consider adding these to the POTFILES.in file, located in the po/ directory.\n\n";
- print STDERR @result, "\n";
- print STDERR "If some of these files are left out on purpose then please add them to\n";
- print STDERR "POTFILES.skip instead of POTFILES.in. A file 'missing' containing this list\n";
- print STDERR "of left out files has been written in the current directory.\n";
+ if (@result)
+ {
+ print "\n" if $VERBOSE;
+ unlink "missing";
+ open OUT, ">missing";
+ print OUT @result;
+ close OUT;
+ warn "\e[1mThe following files contain translations and are currently not in use. Please\e[0m\n".
+ "\e[1mconsider adding these to the POTFILES.in file, located in the po/ directory.\e[0m\n\n";
+ print STDERR @result, "\n";
+ warn "If some of these files are left out on purpose then please add them to\n".
+ "POTFILES.skip instead of POTFILES.in. A file \e[1m'missing'\e[0m containing this list\n".
+ "of left out files has been written in the current directory.\n";
+ }
+ if (@buf_potfiles_notexist)
+ {
+ unlink "notexist";
+ open OUT, ">notexist";
+ print OUT @buf_potfiles_notexist;
+ close OUT;
+ warn "\n" if ($VERBOSE or @result);
+ warn "\e[1mThe following files do not exist anymore:\e[0m\n\n";
+ warn @buf_potfiles_notexist, "\n";
+ warn "Please remove them from POTFILES.in or POTFILES.skip. A file \e[1m'notexist'\e[0m\n".
+ "containing this list of absent files has been written in the current directory.\n";
+ }
}
## If there is nothing to complain about, notify the user
else {
- print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
+ print "\nAll files containing translations are present in POTFILES.in.\n" if $VERBOSE;
}
}
-sub print_error_invalid_option
+sub Console_WriteError_InvalidOption
{
## Handle invalid arguments
print STDERR "Try `${PROGRAM} --help' for more information.\n";
exit 1;
}
-sub generate_headers
+sub GenerateHeaders
{
- my $EXTRACT = `which intltool-extract 2>/dev/null`;
+ my $EXTRACT = "@INTLTOOL_EXTRACT@";
chomp $EXTRACT;
$EXTRACT = $ENV{"INTLTOOL_EXTRACT"} if $ENV{"INTLTOOL_EXTRACT"};
## Generate the .h header files, so we can allow glade and
## xml translation support
- if (! -s $EXTRACT)
+ if (! -x "$EXTRACT")
{
print STDERR "\n *** The intltool-extract script wasn't found!"
."\n *** Without it, intltool-update can not generate files.\n";
@@ -469,135 +572,231 @@ sub generate_headers
}
else
{
- open FILE, "<POTFILES.in";
-
+ open (FILE, $POTFILES_in) or die "$PROGRAM: POTFILES.in not found.\n";
+
while (<FILE>)
{
- chomp;
+ chomp;
+ next if /^\[\s*encoding/;
- ## Find xml files in POTFILES.in and generate the
- ## files with help from the extract script
+ ## Find xml files in POTFILES.in and generate the
+ ## files with help from the extract script
- my $gettext_type= &determine_type ($1);
+ my $gettext_type= &POFile_DetermineType ($1);
- if (/\.($xml_extension|$ini_extension)$/ || /^\[/)
+ if (/\.($xml_support|$ini_support)$/ || /^\[/)
{
- $_ =~ s/^\[[^\[].*]\s*//;
+ s/^\[[^\[].*]\s*//;
my $filename = "../$_";
if ($VERBOSE)
{
- system ($EXTRACT, "--update",
+ system ($EXTRACT, "--update", "--srcdir=$SRCDIR",
"--type=$gettext_type", $filename);
- }
+ }
else
{
system ($EXTRACT, "--update", "--type=$gettext_type",
- "--quiet", $filename);
- }
- }
+ "--srcdir=$SRCDIR", "--quiet", $filename);
+ }
+ }
}
close FILE;
}
}
-sub generate_po_template
+#
+# Generate .pot file from POTFILES.in
+#
+sub GeneratePOTemplate
{
- ## Generate the potfiles from the POTFILES.in file
+ my $XGETTEXT = $ENV{"XGETTEXT"} || "@INTLTOOL_XGETTEXT@";
+ my $XGETTEXT_ARGS = $ENV{"XGETTEXT_ARGS"} || '';
+ chomp $XGETTEXT;
+
+ if (! -x $XGETTEXT)
+ {
+ print STDERR " *** xgettext is not found on this system!\n".
+ " *** Without it, intltool-update can not extract strings.\n";
+ exit;
+ }
- print "Building the $MODULE.pot...\n" if $VERBOSE;
+ print "Building $MODULE.pot...\n" if $VERBOSE;
- move ("POTFILES.in", "POTFILES.in.old");
+ open INFILE, $POTFILES_in;
+ unlink "POTFILES.in.temp";
+ open OUTFILE, ">POTFILES.in.temp" or die("Cannot open POTFILES.in.temp for writing");
- open INFILE, "<POTFILES.in.old";
- open OUTFILE, ">POTFILES.in";
+ my $gettext_support_nonascii = 0;
- while (<INFILE>)
+ # checks for GNU gettext >= 0.12
+ my $dummy = `$XGETTEXT --version --from-code=UTF-8 >$devnull 2>$devnull`;
+ if ($? == 0)
{
- chomp;
- if (/\.($xml_extension|$ini_extension)$/ || /^\[/)
- {
- s/^\[.*]\s*//;
- print OUTFILE "$_.h\n";
- }
- else
- {
- print OUTFILE "$_\n";
- }
+ $gettext_support_nonascii = 1;
+ }
+ else
+ {
+ # urge everybody to upgrade gettext
+ print STDERR "WARNING: This version of gettext does not support extracting non-ASCII\n".
+ " strings. That means you should install a version of gettext\n".
+ " that supports non-ASCII strings (such as GNU gettext >= 0.12),\n".
+ " or have to let non-ASCII strings untranslated. (If there is any)\n";
}
-
- close OUTFILE;
- close INFILE;
- system ("xgettext", "--default-domain\=$MODULE",
- "--directory\=\.\.",
- "--add-comments",
- "--keyword\=\_",
- "--keyword\=N\_",
- "--keyword\=U\_",
- "--files-from\=\.\/POTFILES\.in");
+ my $encoding = "ASCII";
+ my $forced_gettext_code;
+ my @temp_headers;
+ my $encoding_problem_is_reported = 0;
- move ("POTFILES.in.old", "POTFILES.in");
+ while (<INFILE>)
+ {
+ next if (/^#/ or /^\s*$/);
- print "Removing generated header (.h) files..." if $VERBOSE;
+ chomp;
- open FILE, "<POTFILES.in";
+ my $gettext_code;
- while (<FILE>)
- {
- chomp;
- unlink "../$_.h" if /\.($xml_extension|$ini_extension)$/;
- }
+ if (/^\[\s*encoding:\s*(.*)\s*\]/)
+ {
+ $forced_gettext_code=$1;
+ }
+ elsif (/\.($xml_support|$ini_support)$/ || /^\[/)
+ {
+ s/^\[.*]\s*//;
+ print OUTFILE "../$_.h\n";
+ push @temp_headers, "../$_.h";
+ $gettext_code = &TextFile_DetermineEncoding ("../$_.h") if ($gettext_support_nonascii and not defined $forced_gettext_code);
+ }
+ else
+ {
+ if ($SRCDIR eq ".") {
+ print OUTFILE "../$_\n";
+ } else {
+ print OUTFILE "$SRCDIR/../$_\n";
+ }
+ $gettext_code = &TextFile_DetermineEncoding ("../$_") if ($gettext_support_nonascii and not defined $forced_gettext_code);
+ }
- close FILE;
- print "done\n" if $VERBOSE;
+ next if (! $gettext_support_nonascii);
- if (!-e "$MODULE.po")
- {
- print STDERR "WARNING: It seems that none of the files in POTFILES.in ".
- "contain marked strings\n";
- exit (1);
+ if (defined $forced_gettext_code)
+ {
+ $encoding=$forced_gettext_code;
+ }
+ elsif (defined $gettext_code and "$encoding" ne "$gettext_code")
+ {
+ if ($encoding eq "ASCII")
+ {
+ $encoding=$gettext_code;
+ }
+ elsif ($gettext_code ne "ASCII")
+ {
+ # Only report once because the message is quite long
+ if (! $encoding_problem_is_reported)
+ {
+ print STDERR "WARNING: You should use the same file encoding for all your project files,\n".
+ " but $PROGRAM thinks that most of the source files are in\n".
+ " $encoding encoding, while \"$_\" is (likely) in\n".
+ " $gettext_code encoding. If you are sure that all translatable strings\n".
+ " are in same encoding (say UTF-8), please \e[1m*prepend*\e[0m the following\n".
+ " line to POTFILES.in:\n\n".
+ " [encoding: UTF-8]\n\n".
+ " and make sure that configure.in/ac checks for $PACKAGE >= 0.27 .\n".
+ "(such warning message will only be reported once.)\n";
+ $encoding_problem_is_reported = 1;
+ }
+ }
+ }
}
- system ("rm", "-f", "$MODULE.pot");
- move ("$MODULE.po", "$MODULE.pot") or
- die "$PROGRAM: couldn't move $MODULE.po to $MODULE.pot.\n";
-
- print "Wrote $MODULE.pot\n" if $VERBOSE;
-}
+ close OUTFILE;
+ close INFILE;
-sub update_po_file
-{
- my ($lang, $output_file) = @_;
- my ($infile, $outfile);
+ unlink "$MODULE.pot";
+ my @xgettext_argument=("$XGETTEXT",
+ "--add-comments",
+ "--directory\=\.",
+ "--output\=$MODULE\.pot",
+ "--files-from\=\.\/POTFILES\.in\.temp");
+ my $XGETTEXT_KEYWORDS = &FindPOTKeywords;
+ push @xgettext_argument, $XGETTEXT_KEYWORDS;
+ my $MSGID_BUGS_ADDRESS = &FindMakevarsBugAddress;
+ push @xgettext_argument, "--msgid-bugs-address\=$MSGID_BUGS_ADDRESS" if $MSGID_BUGS_ADDRESS;
+ push @xgettext_argument, "--from-code\=$encoding" if ($gettext_support_nonascii);
+ push @xgettext_argument, $XGETTEXT_ARGS if $XGETTEXT_ARGS;
+ my $xgettext_command = join ' ', @xgettext_argument;
+
+ # intercept xgettext error message
+ print "Running $xgettext_command\n" if $VERBOSE;
+ my $xgettext_error_msg = `$xgettext_command 2>\&1`;
+ my $command_failed = $?;
+
+ unlink "POTFILES.in.temp";
- print "Merging $lang.po with $MODULE.pot..." if $VERBOSE;
+ print "Removing generated header (.h) files..." if $VERBOSE;
+ unlink foreach (@temp_headers);
+ print "done.\n" if $VERBOSE;
- if ($output_file ne "")
+ if (! $command_failed)
{
- $infile = "$lang.po";
- $outfile = $output_file;
+ if (! -e "$MODULE.pot")
+ {
+ print "None of the files in POTFILES.in contain strings marked for translation.\n" if $VERBOSE;
+ }
+ else
+ {
+ print "Wrote $MODULE.pot\n" if $VERBOSE;
+ }
}
else
{
- copy ("$lang.po", "$lang.po.old") || die "copy failed: $!";
- $infile = "$lang.po.old";
- $outfile = "$lang.po";
+ if ($xgettext_error_msg =~ /--from-code/)
+ {
+ # replace non-ASCII error message with a more useful one.
+ print STDERR "ERROR: xgettext failed to generate PO template file because there is non-ASCII\n".
+ " string marked for translation. Please make sure that all strings marked\n".
+ " for translation are in uniform encoding (say UTF-8), then \e[1m*prepend*\e[0m the\n".
+ " following line to POTFILES.in and rerun $PROGRAM:\n\n".
+ " [encoding: UTF-8]\n\n";
+ }
+ else
+ {
+ print STDERR "$xgettext_error_msg";
+ if (-e "$MODULE.pot")
+ {
+ # is this possible?
+ print STDERR "ERROR: xgettext failed but still managed to generate PO template file.\n".
+ " Please consult error message above if there is any.\n";
+ }
+ else
+ {
+ print STDERR "ERROR: xgettext failed to generate PO template file. Please consult\n".
+ " error message above if there is any.\n";
+ }
+ }
+ exit (1);
}
+}
+
+sub POFile_Update
+{
+ -f "$MODULE.pot" or die "$PROGRAM: $MODULE.pot does not exist.\n";
- # Perform merge, remove backup file and the "messages" trash file
- # generated by gettext
- system ("msgmerge", "-o", $outfile, $infile, "$MODULE.pot");
+ my $MSGMERGE = $ENV{"MSGMERGE"} || "@INTLTOOL_MSGMERGE@";
+ my ($lang, $outfile) = @_;
- if ($output_file eq "")
- {
- unlink $infile;
- }
- unlink "messages";
+ print "Merging $SRCDIR/$lang.po with $MODULE.pot..." if $VERBOSE;
+
+ my $infile = "$SRCDIR/$lang.po";
+ $outfile = "$SRCDIR/$lang.po" if ($outfile eq "");
+
+ # I think msgmerge won't overwrite old file if merge is not successful
+ system ("$MSGMERGE", "-o", $outfile, $infile, "$MODULE.pot");
}
-sub print_error_not_existing
+sub Console_WriteError_NotExisting
{
my ($file) = @_;
@@ -607,11 +806,11 @@ sub print_error_not_existing
exit;
}
-sub gather_po_files
+sub GatherPOFiles
{
my @po_files = glob ("./*.po");
- @languages = map (&po_file2lang, @po_files);
+ @languages = map (&POFile_GetLanguage, @po_files);
foreach my $lang (@languages)
{
@@ -619,73 +818,77 @@ sub gather_po_files
}
}
-sub po_file2lang ($)
+sub POFile_GetLanguage ($)
{
- my $tmp = $_;
- $tmp =~ s/^.*\/(.*)\.po$/$1/;
- return $tmp;
+ s/^(.*\/)?(.+)\.po$/$2/;
+ return $_;
}
-sub print_status
+sub Console_Write_TranslationStatus
{
my ($lang, $output_file) = @_;
+ my $MSGFMT = $ENV{"MSGFMT"} || "@INTLTOOL_MSGFMT@";
- if ($output_file eq "")
- {
- $output_file = "$lang.po";
- }
+ $output_file = "$SRCDIR/$lang.po" if ($output_file eq "");
- system ("msgfmt", "--statistics", $output_file);
- print "\n";
+ system ("$MSGFMT", "-o", "$devnull", "--verbose", $output_file);
}
-sub print_report
+sub Console_Write_CoverageReport
{
- &generate_headers;
- &generate_po_template;
- &gather_po_files;
+ my $MSGFMT = $ENV{"MSGFMT"} || "@INTLTOOL_MSGFMT@";
+
+ &GatherPOFiles;
foreach my $lang (@languages)
{
print "$lang: ";
- &update_po_file ($lang, "");
+ &POFile_Update ($lang, "");
}
print "\n\n * Current translation support in $MODULE \n\n";
foreach my $lang (@languages)
{
- print "$lang: ";
- system ("msgfmt", "--statistics", "$lang.po");
+ print "$lang: ";
+ system ("$MSGFMT", "-o", "$devnull", "--verbose", "$SRCDIR/$lang.po");
}
}
-sub substitute_var
+sub SubstituteVariable
{
my ($str) = @_;
+ # always need to rewind file whenever it has been accessed
+ seek (CONF, 0, 0);
+
# cache each variable. varhash is global to we can add
# variables elsewhere.
while (<CONF>)
{
- if (/^(\w+)=(\S+)/)
+ if (/^(\w+)=(.*)$/)
{
- $varhash{$1} = $2;
+ ($varhash{$1} = $2) =~ s/^["'](.*)["']$/$1/;
}
}
- if ($str =~ /^(.*)\${?([A-Z]+)}?(.*)$/)
+ if ($str =~ /^(.*)\${?([A-Z_]+)}?(.*)$/)
{
my $rest = $3;
my $untouched = $1;
- my $sub = $varhash{$2};
-
- return substitute_var ("$untouched$sub$rest");
+ my $sub = "";
+ # Ignore recursive definitions of variables
+ $sub = $varhash{$2} if defined $varhash{$2} and $varhash{$2} !~ /\${?$2}?/;
+
+ return SubstituteVariable ("$untouched$sub$rest");
}
- return $str;
+
+ # We're using Perl backticks ` and "echo -n" here in order to
+ # expand any shell escapes (such as backticks themselves) in every variable
+ return echo_n ($str);
}
-sub open_CONF_handle
+sub CONF_Handle_Open
{
my $base_dirname = getcwd();
$base_dirname =~ s@.*/@@;
@@ -694,76 +897,193 @@ sub open_CONF_handle
if ($base_dirname =~ /^po(-.+)?$/)
{
- if (-f "../configure.in")
- {
- $conf_in = "../configure.in";
- }
- elsif (-f "../configure.ac")
- {
+ if (-f "Makevars")
+ {
+ my $makefile_source;
+
+ local (*IN);
+ open (IN, "<Makevars") || die "can't open Makevars: $!";
+
+ while (<IN>)
+ {
+ if (/^top_builddir[ \t]*=/)
+ {
+ $src_dir = $_;
+ $src_dir =~ s/^top_builddir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
+
+ chomp $src_dir;
+ if (-f "$src_dir" . "/configure.ac") {
+ $conf_in = "$src_dir" . "/configure.ac" . "\n";
+ } else {
+ $conf_in = "$src_dir" . "/configure.in" . "\n";
+ }
+ last;
+ }
+ }
+ close IN;
+
+ $conf_in || die "Cannot find top_builddir in Makevars.";
+ }
+ elsif (-f "../configure.ac")
+ {
$conf_in = "../configure.ac";
- }
- else
- {
+ }
+ elsif (-f "../configure.in")
+ {
+ $conf_in = "../configure.in";
+ }
+ else
+ {
my $makefile_source;
-
+
local (*IN);
- open IN, "<Makefile" || die "can't open Makefile: $!";
-
+ open (IN, "<Makefile") || return;
+
while (<IN>)
- {
+ {
if (/^top_srcdir[ \t]*=/)
- {
+ {
$src_dir = $_;
$src_dir =~ s/^top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/;
-
+
chomp $src_dir;
$conf_in = "$src_dir" . "/configure.in" . "\n";
-
+
last;
}
}
-
- $conf_file || die "Cannot find top_srcdir in Makefile.";
+ close IN;
+
+ $conf_in || die "Cannot find top_srcdir in Makefile.";
}
-
- $conf_file = $conf_in;
- open (CONF, "<$conf_in") || die "can't open $conf_in: $!";
+
+ open (CONF, "<$conf_in");
}
else
{
print STDERR "$PROGRAM: Unable to proceed.\n" .
- "Make sure to run this script inside the po directory.\n";
+ "Make sure to run this script inside the po directory.\n";
exit;
}
}
-sub find_package_name
+sub FindPackageName
{
- &open_CONF_handle;
-
+ my $version;
+ my $domain = &FindMakevarsDomain;
+ my $name = $domain || "untitled";
+
+ &CONF_Handle_Open;
+
my $conf_source; {
local (*IN);
- open (IN, "<$conf_file") || die "can't open $conf_file: $!";
+ open (IN, "<&CONF") || return $name;
seek (IN, 0, 0);
local $/; # slurp mode
$conf_source = <IN>;
+ close IN;
}
-
- my $name = "";
- $name = $1 if $conf_source =~ /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m;
+ # priority for getting package name:
+ # 1. GETTEXT_PACKAGE
+ # 2. first argument of AC_INIT (with >= 2 arguments)
+ # 3. first argument of AM_INIT_AUTOMAKE (with >= 2 argument)
+
+ # /^AM_INIT_AUTOMAKE\([\s\[]*([^,\)\s\]]+)/m
+ # the \s makes this not work, why?
+ if ($conf_source =~ /^AM_INIT_AUTOMAKE\(([^,\)]+),([^,\)]+)/m)
+ {
+ ($name, $version) = ($1, $2);
+ $name =~ s/[\[\]\s]//g;
+ $version =~ s/[\[\]\s]//g;
+ $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
+ $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
+ $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
+ $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
+ }
- if ($conf_source =~ /^AC_INIT\([\s\[]*([^,\)\s\]]+)\]?\s*,/m)
+ if ($conf_source =~ /^AC_INIT\(([^,\)]+),([^,\)]+)/m)
{
- $name = $1;
- $varhash{"AC_PACKAGE_NAME"} = $1;
+ ($name, $version) = ($1, $2);
+ $name =~ s/[\[\]\s]//g;
+ $version =~ s/[\[\]\s]//g;
+ $varhash{"PACKAGE_NAME"} = $name if (not $name =~ /\${?AC_PACKAGE_NAME}?/);
+ $varhash{"PACKAGE"} = $name if (not $name =~ /\${?PACKAGE}?/);
+ $varhash{"PACKAGE_VERSION"} = $version if (not $name =~ /\${?AC_PACKAGE_VERSION}?/);
+ $varhash{"VERSION"} = $version if (not $name =~ /\${?VERSION}?/);
}
+
+ # \s makes this not work, why?
+ $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\n\]]+)/m;
- $name = $1 if $conf_source =~ /^GETTEXT_PACKAGE=\[?([^\s\]]+)/m;
+ # m4 macros AC_PACKAGE_NAME, AC_PACKAGE_VERSION etc. have same value
+ # as corresponding $PACKAGE_NAME, $PACKAGE_VERSION etc. shell variables.
+ $name =~ s/\bAC_PACKAGE_/\$PACKAGE_/g;
+
+ $name = $domain if $domain;
+
+ $name = SubstituteVariable ($name);
+ $name =~ s/^["'](.*)["']$/$1/;
+
+ return $name if $name;
+}
+
+
+sub FindPOTKeywords
+{
+
+ my $keywords = "--keyword\=\_ --keyword\=N\_ --keyword\=U\_ --keyword\=Q\_";
+ my $varname = "XGETTEXT_OPTIONS";
+ my $make_source; {
+ local (*IN);
+ open (IN, "<Makevars") || (open(IN, "<Makefile.in.in") && ($varname = "XGETTEXT_KEYWORDS")) || return $keywords;
+ seek (IN, 0, 0);
+ local $/; # slurp mode
+ $make_source = <IN>;
+ close IN;
+ }
+
+ $keywords = $1 if $make_source =~ /^$varname[ ]*=\[?([^\n\]]+)/m;
- $name = "\$AC_PACKAGE_NAME" if "$name" eq "AC_PACKAGE_NAME";
+ return $keywords;
+}
+
+sub FindMakevarsDomain
+{
+
+ my $domain = "";
+ my $makevars_source; {
+ local (*IN);
+ open (IN, "<Makevars") || return $domain;
+ seek (IN, 0, 0);
+ local $/; # slurp mode
+ $makevars_source = <IN>;
+ close IN;
+ }
+
+ $domain = $1 if $makevars_source =~ /^DOMAIN[ ]*=\[?([^\n\]\$]+)/m;
+ $domain =~ s/^\s+//;
+ $domain =~ s/\s+$//;
- $name = substitute_var ($name);
+ return $domain;
+}
- return $name if $name;
+sub FindMakevarsBugAddress
+{
+
+ my $address = "";
+ my $makevars_source; {
+ local (*IN);
+ open (IN, "<Makevars") || return undef;
+ seek (IN, 0, 0);
+ local $/; # slurp mode
+ $makevars_source = <IN>;
+ close IN;
+ }
+
+ $address = $1 if $makevars_source =~ /^MSGID_BUGS_ADDRESS[ ]*=\[?([^\n\]\$]+)/m;
+ $address =~ s/^\s+//;
+ $address =~ s/\s+$//;
+
+ return $address;
}

Privacy Policy