diff options
-rw-r--r-- | ChangeLog | 33 | ||||
-rw-r--r-- | Makefile.am | 72 | ||||
-rw-r--r-- | README | 6 | ||||
-rw-r--r-- | configure.in | 13 | ||||
-rw-r--r-- | intltool-extract.in.in | 2 | ||||
-rw-r--r-- | intltool-merge.in.in | 2 | ||||
-rwxr-xr-x | intltool-prepare.in | 283 | ||||
-rwxr-xr-x | intltool-unicodify.in | 2 | ||||
-rw-r--r-- | intltool-update.in.in | 2 | ||||
-rw-r--r-- | intltool.m4 | 63 | ||||
-rw-r--r-- | intltoolize.in | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 9 | ||||
-rw-r--r-- | tests/cases/.cvsignore | 1 | ||||
-rw-r--r-- | tests/cases/Makefile.am | 10 | ||||
-rw-r--r-- | tests/results/Makefile.am | 8 | ||||
-rwxr-xr-x | tests/selftest.pl | 108 | ||||
-rwxr-xr-x | tests/selftest.pl.in | 2 | ||||
-rw-r--r-- | xml-i18n-extract.in | 303 | ||||
-rw-r--r-- | xml-i18n-extract.in.in | 2 | ||||
-rw-r--r-- | xml-i18n-merge.in | 401 | ||||
-rw-r--r-- | xml-i18n-merge.in.in | 2 | ||||
-rwxr-xr-x | xml-i18n-prepare.in | 283 | ||||
-rwxr-xr-x | xml-i18n-prepare.in.in | 283 | ||||
-rw-r--r-- | xml-i18n-toolize.in | 2 | ||||
-rw-r--r-- | xml-i18n-tools.Makefile.patch | 9 | ||||
-rw-r--r-- | xml-i18n-tools.m4 | 63 | ||||
-rwxr-xr-x | xml-i18n-unicodify | 65 | ||||
-rwxr-xr-x | xml-i18n-unicodify.in | 2 | ||||
-rw-r--r-- | xml-i18n-update.in | 495 | ||||
-rw-r--r-- | xml-i18n-update.in.in | 2 |
30 files changed, 198 insertions, 2332 deletions
@@ -1,3 +1,36 @@ +2001-02-05 Maciej Stachowiak <mjs@eazel.com> + + reviewed by: George Lebl <jirka@eazel.com> + Robin * Slomkowski <rslomkow@eazel.com> + + Fixed bug 6199 (perl location is configured at xml-i18n-tools + configure time -- not the configure time for a package that uses + the tools) and 6250 (perl path hard-coded in selftest.pl). Also + made 'make distcheck' work. + + * tests/Makefile.am: Screw around a bit so the self test script + ends up executable after configure substitution. + * tests/cases/.cvsignore: Ignore a new file + * tests/cases/Makefile.am, tests/results/Makefile.am: Add missing + files to EXTRA_DIST. + * tests/selftest.pl.in: renamed from tests/selftest.pl, set perl + path at configure time. + * xml-i18n-unicodify.in: renamed from xml-i18n-unicodify, set perl + path at configure time. + * xml-i18n-extract.in.in, xml-i18n-merge.in.in, + xml-i18n-prepare.in.in, xml-i18n-update.in.in: Renamed to .in.in + from .in; substitute all variables except perl path at + xml-i18n-tools configure time, so .in versions can be copied into + modules when xml-i18n-toolizing. + * xml-i18n-toolize.in: copy .in versions of tools into module. + * xml-i18n-tools.Makefile.patch: don't change DISTFILES, this + broke with the new changes. + * xml-i18n-tools.m4: substitute xml-i18n-tools ; expect xml-i18n-* + to be in builddir. + * README: Updated instructions on how to use. + * Makefile.am: Adjust what gets installed where. + * configure.in: Adjust set of files being output. + 2001-02-01 Kenneth Christiansen <kenneth@gnu.org> * tests/selftest.pl: diff --git a/Makefile.am b/Makefile.am index 7f19f24..468e9cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,34 +6,60 @@ NULL = aclocal_macros = xml-i18n-tools.m4 -CLEANFILES = \ - xml-i18n-toolize xml-i18n-extract \ - xml-i18n-merge xml-i18n-update \ - xml-i18n-prepare *.gz +CLEANFILES = \ + xml-i18n-toolize \ + xml-i18n-extract.in \ + xml-i18n-merge.in \ + xml-i18n-update.in \ + xml-i18n-extract \ + xml-i18n-merge \ + xml-i18n-prepare \ + xml-i18n-update \ + xml-i18n-unicodify \ + *.gz \ + $(NULL) # These are required by xml-i18n-toolize. -pkgdata_SCRIPTS = \ - xml-i18n-extract xml-i18n-merge \ - xml-i18n-update xml-i18n-prepare +pkgdata_DATA = \ + xml-i18n-extract.in \ + xml-i18n-merge.in \ + xml-i18n-update.in \ + xml-i18n-tools.Makefile.patch \ + $(NULL) -pkgdata_DATA = xml-i18n-tools.Makefile.patch # This macro file should be visible to Automake's aclocal. aclocal_DATA = $(aclocal_macros) -# The xml-i18n-tools distributor. -bin_SCRIPTS = \ - xml-i18n-toolize xml-i18n-update \ - xml-i18n-extract xml-i18n-prepare - -EXTRA_DIST = \ - $(aclocal_macros) \ - xml-i18n-toolize.in \ - xml-i18n-extract.in \ - xml-i18n-merge.in \ - xml-i18n-update.in \ - xml-i18n-prepare.in \ - xml-i18n-unicodify \ - xml-i18n-tools.spec \ - $(pkgdata_DATA) \ +# The xml-i18n-tools distributor and installed versions of scripts + +bin_SCRIPTS = \ + xml-i18n-toolize \ + xml-i18n-update \ + xml-i18n-merge \ + xml-i18n-extract \ + xml-i18n-prepare \ + xml-i18n-unicodify \ + $(NULL) + +EXTRA_DIST = \ + $(aclocal_macros) \ + xml-i18n-toolize.in \ + xml-i18n-extract.in.in \ + xml-i18n-merge.in.in \ + xml-i18n-update.in.in \ + xml-i18n-prepare.in \ + xml-i18n-unicodify.in \ + xml-i18n-tools.spec \ + $(pkgdata_DATA) \ $(NULL) + + +xml-i18n-extract: xml-i18n-extract.in + sed -e "s:@XML_I18N_TOOLS_PERL@:$(PERL):;" < $< > $@ + +xml-i18n-merge: xml-i18n-merge.in + sed -e "s:@XML_I18N_TOOLS_PERL@:$(PERL):;" < $< > $@ + +xml-i18n-update: xml-i18n-update.in + sed -e "s:@XML_I18N_TOOLS_PERL@:$(PERL):;" < $< > $@ @@ -22,9 +22,9 @@ To use xml-i18n-tools in your module, do the following: AM_PROG_XML_I18N_TOOLS - o Add xml-i18n-extract, xml-i18n-merge and xml-i18n-update to - EXTRA_DIST in your top-level Makefile.am and also to the top-level - .cvsignore. + o Add xml-i18n-extract.in, xml-i18n-merge.in and xml-i18n-update.in + to EXTRA_DIST in your top-level Makefile.am and also to the + top-level .cvsignore. Also add the non-.in versions to .cvsignore o Add the .xml and .glade files you want translated to POTFILES.in diff --git a/configure.in b/configure.in index d89eb4c..576e278 100644 --- a/configure.in +++ b/configure.in @@ -11,24 +11,25 @@ AC_SUBST(pkgdatadir) dnl automake does not need this, but libtoolize does aclocaldir='${datadir}'/aclocal AC_SUBST(aclocaldir) - AC_PATH_PROG(PERL, perl) if test -z "$PERL"; then AC_MSG_ERROR([perl not found]) fi if test -z "`$PERL -v | fgrep '5.' 2> /dev/null`"; then - AC_MSG_ERROR([perl 5.x required]) + AC_MSG_ERROR([perl 5.x required for xml-i18n-tools]) fi AC_OUTPUT([ Makefile tests/Makefile +tests/selftest.pl tests/cases/Makefile tests/results/Makefile -xml-i18n-extract -xml-i18n-merge -xml-i18n-toolize -xml-i18n-update +xml-i18n-extract.in +xml-i18n-merge.in xml-i18n-prepare +xml-i18n-update.in xml-i18n-tools.spec +xml-i18n-toolize +xml-i18n-unicodify ]) diff --git a/intltool-extract.in.in b/intltool-extract.in.in index 7debbe0..24dc283 100644 --- a/intltool-extract.in.in +++ b/intltool-extract.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- # diff --git a/intltool-merge.in.in b/intltool-merge.in.in index 46e4299..3e1e1ac 100644 --- a/intltool-merge.in.in +++ b/intltool-merge.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # # The XML Translation Merge Tool diff --git a/intltool-prepare.in b/intltool-prepare.in deleted file mode 100755 index 8de2e64..0000000 --- a/intltool-prepare.in +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/perl -w - -# XML I18N Desktop File Prepare Tool -# -# Copyright (C) 2001 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): Gediminas Paulauskas <menesis@delfi.lt> -# Kenneth Christiansen <kenneth@gnu.org> - -## Release information -my $PROGRAM = "xml-i18n-extract"; -my $PACKAGE = "@PACKAGE@"; -my $VERSION = "@VERSION@"; -my $MAINTAINER = "<menesis\@delfi.lt>"; - -## Loaded modules -use strict; -use Getopt::Long; -use File::Find; - -## Scalars used by the option stuff -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $VERBOSE = "0"; - -my @languages; -my @desktop_files; -my $new; -my $file; - -my $desktop_extension = "(desktop|soundlist|keys|directory)+"; -my $desktop_find_regex = ".*desktop\\|soundlist\\|keys\\|directory"; - -my $keywords = "Name|Comment|description"; - -## Always print as the first thing -$| = 1; - -## Handle options -GetOptions ( - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "verbose|x" => \$VERBOSE - ) or &invalid_option; - - -## Use the supplied arguments -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - - } else { - &main; - } -} - -&split_on_argument; - -sub main -{ - print "Working, please wait...\n" if (! $VERBOSE); - &find_desktop_files; - &append_keywords; - &add_to_potfiles; - &perform_rescue; - &add_to_cvsignore; - &generate_empty; -} - -sub version{ - - ## Print version information - print "${PROGRAM} ${PACKAGE} $VERSION\n"; - print "Written by Gediminas Paulauskas <menesis\@delfi.lt>, 2000.\n\n"; - print "Copyright (C) 2000 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"; - exit; -} - -sub help -{ - ## Print usage information - print "Usage: $PROGRAM [OPTION] KEYWORD ...\n"; - print "Updates pot files and merge them with the translations.\n"; - print "KEYWORD is additional key besides Name, Comment and description\n\n"; - print " -H, --help shows this help page\n"; - print " -X, --verbose show lots of feedback\n"; - print " -V, --version shows the version\n"; - print "Report bugs to $MAINTAINER.\n"; - exit; -} - -sub invalid_option -{ - ## Handle invalid arguments - ## my $opt = $ARGV[0]; - ## print "$PROGRAM: invalid option -- $opt\n"; - print "Try `$PROGRAM --help' for more information.\n"; - exit 1; -} - -sub append_keywords -{ - my $arg; - foreach $arg (@ARGV) { - $keywords .= "|$arg"; - } -} - -sub add_to_potfiles -{ - open FILE, ">>po/POTFILES.in"; - my $intro = 0; - foreach my $desktop (@desktop_files) { - next if contains("po/POTFILES.in", "$desktop.in"); - # Print explanation comment only once - unless ($intro) { - print FILE "# files added by xml-i18n-prepare\n"; - $intro = 1; - } - print FILE "$desktop.in\n"; - } - close FILE; -} - -sub perform_rescue -{ - foreach $file (@desktop_files) { - &rescue_file($file); - } -} - -sub rescue_file -{ - my ($filename) = @_; - my ($msgid, $line, $lang); - - print "Rescuing translations from $filename ...\n" if $VERBOSE; - - open ORIG, "<$filename"; - $line = 1; - while (<ORIG>) { - chomp; - $line++; - my $entry = $_; - if (($entry =~ /^($keywords)=(.*)$/) || - ($entry =~ /^(\s*description)=(.*)$/)) { - $msgid = $2; - $msgid =~ s/\"/\\"/; - } elsif (($entry =~ /^($keywords)\[(.*?)\]=(.*)$/) || - ($entry =~ /^(\s*\[)(.*?)\]description=(.*)$/)) { - $lang = $2; - next if (!-s "po/$lang.po"); - - my $msgstr = $3; - $msgstr =~ s/"/\\"/g; - - $line--; - next if contains("po/$lang.po", "msgid \"$msgid\""); - - open POFILE, ">>po/$lang.po"; - - print POFILE "\n#: $filename.in:$line\n"; - print POFILE "msgid \"$msgid\"\n"; - print POFILE "msgstr \"$msgstr\"\n"; - - close POFILE; - } - } -} - -sub generate_empty -{ - my $all = ' '; - foreach my $full (@desktop_files) { - $new = "$full.in"; - $all .= "$new "; - print "Generating empty $new ...\n" if $VERBOSE; - open FULL, "<$full"; - open NEW, ">$new"; - - while (<FULL>) { - unless ( - (/^($keywords)\[.*?\]=.*$/) || - (/^\s*\[(.*?)\]description=.*$/) - ) { - if (/^($keywords)=.*$/) { - print NEW "_$_"; - } elsif (/^(\s*)(description=.*)$/) { - print NEW "$1_$2\n"; - } else { - print NEW; - } - } - } - - close NEW; - } - print "*** Please add these files to CVS by following command: ***\n" - . "cvs add$all\n"; -} - -sub add_to_cvsignore -{ - my $all = ' '; - my $ign; - foreach $file (@desktop_files) { - $file =~ /^(.*\/)*(.*?\.$desktop_extension$)$/; - if ($1) { - $ign = "$1.cvsignore"; - } else { - $ign = ".cvsignore"; - } - my $basename = $2; - - next if contains($ign, $basename); - - print "Appending $basename to $ign\n" if $VERBOSE; - open FILE, ">>$ign"; - print FILE "$basename\n"; - $all .= "$file "; - } - close FILE; - unless ($all eq ' ') { - print "*** Please remove files from CVS by following command: ***\n" - . "cvs remove -f$all\n"; - } -} - -sub contains -{ - my ($name, $expr) = @_; - open CONT, "<$name"; - while (<CONT>) { - return 1 if /^$expr$/; - } - return 0; -} - -sub find_desktop_files -{ - if ($VERBOSE) { - print "Found these interesting files:\n"; - } else { - print "Finding interesting files..."; - } - find (\&wanted, '.'); - print "done\n" unless $VERBOSE; -} - -sub wanted -{ - if (/$desktop_extension$/) { - my $file = $File::Find::name; - $file =~ s/\.\///; - push @desktop_files, $file; - print "$file\n" if $VERBOSE; - } -} - -# vim: ts=4 sw=4 expandtab diff --git a/intltool-unicodify.in b/intltool-unicodify.in index 041ac73..44fea6c 100755 --- a/intltool-unicodify.in +++ b/intltool-unicodify.in @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!@PERL@ -w # # The i18n Unicode Encoding Utility diff --git a/intltool-update.in.in b/intltool-update.in.in index abdae55..e4d8d1b 100644 --- a/intltool-update.in.in +++ b/intltool-update.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # The GNOME Translation Update Tool # diff --git a/intltool.m4 b/intltool.m4 index 5504544..4e42949 100644 --- a/intltool.m4 +++ b/intltool.m4 @@ -24,47 +24,62 @@ # serial 1 AC_PROG_XML_I18N_TOOLS AC_DEFUN(AC_PROG_XML_I18N_TOOLS, [ -# Always use our own xml-i18n-tools. - -XML_I18N_EXTRACT='$(top_srcdir)/xml-i18n-extract' -AC_SUBST(XML_I18N_EXTRACT)dnl - -XML_I18N_MERGE='$(top_srcdir)/xml-i18n-merge' -AC_SUBST(XML_I18N_MERGE)dnl - -XML_I18N_UPDATE='$(top_srcdir)/xml-i18n-update' -AC_SUBST(XML_I18N_UPDATE)dnl dnl This is a hack - we use the expansion of AC_SUBST instead of dnl AC_SUBST itself to avoid automake putting dnl XML_I18N_MERGE_OAF_RULE = @XML_I18N_MERGE_OAF_RULE@ dnl in all the Makefile.in's -XML_I18N_MERGE_OAF_RULE='\%.oaf : \%.oaf.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -o $(top_srcdir)/po $< [$]*.oaf' +XML_I18N_MERGE_OAF_RULE='\%.oaf : \%.oaf.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -o $(top_srcdir)/po $< [$]*.oaf' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_OAF_RULE@%[$]XML_I18N_MERGE_OAF_RULE%g AC_DIVERT_POP()dnl -dnl This is a hack - we use the expansion of AC_SUBST instead of -dnl AC_SUBST itself to avoid automake putting -dnl XML_I18N_MERGE_KEYS_RULE = @XML_I18N_MERGE_KEYS_RULE@ -dnl in all the Makefile.in's -XML_I18N_MERGE_KEYS_RULE='\%.keys : \%.keys.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -k $(top_srcdir)/po $< [$]*.keys' +dnl same deal +XML_I18N_MERGE_KEYS_RULE='\%.keys : \%.keys.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -k $(top_srcdir)/po $< [$]*.keys' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_KEYS_RULE@%[$]XML_I18N_MERGE_KEYS_RULE%g AC_DIVERT_POP()dnl -dnl This is a hack - we use the expansion of AC_SUBST instead of -dnl AC_SUBST itself to avoid automake putting -dnl XML_I18N_MERGE_DESKTOP_RULE = @XML_I18N_MERGE_DESKTOP_RULE@ -dnl in all the Makefile.in's -XML_I18N_MERGE_DESKTOP_RULE='\%.desktop : \%.desktop.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -d $(top_srcdir)/po $< [$]*.desktop' +dnl same deal +XML_I18N_MERGE_DESKTOP_RULE='\%.desktop : \%.desktop.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -d $(top_srcdir)/po $< [$]*.desktop' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_DESKTOP_RULE@%[$]XML_I18N_MERGE_DESKTOP_RULE%g AC_DIVERT_POP()dnl +# Always use our own xml-i18n-tools. +XML_I18N_EXTRACT='$(top_builddir)/xml-i18n-extract' +AC_SUBST(XML_I18N_EXTRACT)dnl + +XML_I18N_MERGE='$(top_builddir)/xml-i18n-merge' +AC_SUBST(XML_I18N_MERGE)dnl + +XML_I18N_UPDATE='$(top_builddir)/xml-i18n-update' +AC_SUBST(XML_I18N_UPDATE)dnl + +AC_PATH_PROG(XML_I18N_TOOLS_PERL, perl) +if test -z "$XML_I18N_TOOLS_PERL"; then + AC_MSG_ERROR([perl not found; required for xml-i18n-tools]) +fi +if test -z "`$XML_I18N_TOOLS_PERL -v | fgrep '5.' 2> /dev/null`"; then + AC_MSG_ERROR([perl 5.x required for xml-i18n-tools]) +fi + +dnl manually sed perl in so people don't have to put the xml-i18n-tools scripts in their +dnl AC_OUTPUT +AC_OUTPUT_COMMANDS([ +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-extract.in > xml-i18n-extract; +chmod ugo+x xml-i18n-extract; + +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-merge.in > xml-i18n-merge; +chmod ugo+x xml-i18n-merge; + +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-update.in > xml-i18n-update; +chmod ugo+x xml-i18n-update; +], XML_I18N_TOOLS_PERL=${XML_I18N_TOOLS_PERL}) + # Redirect the config.log output again, so that the ltconfig log is not # clobbered by the next message. exec 5>>./config.log diff --git a/intltoolize.in b/intltoolize.in index c25b9ef..46f44d3 100644 --- a/intltoolize.in +++ b/intltoolize.in @@ -134,7 +134,7 @@ if test -z "$files"; then echo "$progname: cannot list files in \`$pkgdatadir'" 1>&2 exit 1 fi -files='xml-i18n-extract xml-i18n-merge xml-i18n-update' +files='xml-i18n-extract.in xml-i18n-merge.in xml-i18n-update.in' auxdir=. auxdirline=`egrep '^AC_CONFIG_AUX_DIR' configure.in 2>/dev/null` diff --git a/tests/Makefile.am b/tests/Makefile.am index 65b3a45..bd4fe56 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,10 @@ SUBDIRS = cases results -EXTRA_DIST = selftest.pl +EXTRA_DIST = selftest.pl.in + +TESTS=selftest + +selftest: selftest.pl + cp $< $@ + chmod +x $@ -TESTS=selftest.pl diff --git a/tests/cases/.cvsignore b/tests/cases/.cvsignore index cdbfa7b..2fee4e6 100644 --- a/tests/cases/.cvsignore +++ b/tests/cases/.cvsignore @@ -2,4 +2,5 @@ Makefile Makefile.in extract1.desktop.h extract2.keyprop.h +extract3.xml.in.h merge1.xml diff --git a/tests/cases/Makefile.am b/tests/cases/Makefile.am index c96e6d3..211800e 100644 --- a/tests/cases/Makefile.am +++ b/tests/cases/Makefile.am @@ -1,6 +1,6 @@ -EXTRA_DIST = \ - extract1.desktop \ - extract2.keyprop \ - merge1.xml.in \ - extract3.xml.in +EXTRA_DIST = \ + extract1.desktop \ + extract2.keyprop \ + merge1.xml.in \ + extract3.xml.in \ test.po diff --git a/tests/results/Makefile.am b/tests/results/Makefile.am index 08f52c4..cc3f733 100644 --- a/tests/results/Makefile.am +++ b/tests/results/Makefile.am @@ -1,5 +1,5 @@ -EXTRA_DIST = \ - extract1.desktop.h \ - extract2.keyprop.h \ - extract3.xml.in.h +EXTRA_DIST = \ + extract1.desktop.h \ + extract2.keyprop.h \ + extract3.xml.in.h \ merge1.xml diff --git a/tests/selftest.pl b/tests/selftest.pl deleted file mode 100755 index bdcfd6a..0000000 --- a/tests/selftest.pl +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/perl -w - -# Selftest for The XML Translation Tools -# -# Copyright (C) 2000 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): Kenneth Christiansen - -## Release information -my $PROGRAM = "selftest"; -my $VERSION = "0.1"; -my $result; -my $case; - -## Loaded modules -use strict; - -## Always print as the first thing -$| = 1; - -my $failed = 0; - -my $srcdir = $ENV{"srcdir"} or "."; - -sub check_result($) -{ - my $testcase = $_[0]; - my $result =`diff -Nup $srcdir/results/$testcase.h $srcdir/cases/$testcase.h`; - - if ($? == 0 && $result eq "") { - print "[OK]\n"; ## diff was empty, ie. files were equal - } else { - print "[FAILED]\n"; - $failed = 1; - } -} - -sub check_result_output($) -{ - my $testcase = $_[0]; - $testcase =~ s/\.in//; - my $result =`diff -Nup $srcdir/results/$testcase $srcdir/cases/$testcase`; - - if ($? == 0 && $result eq "") { - print "[OK]\n"; ## diff was empty, ie. files were equal - } else { - print "[FAILED]\n"; - open OUT, ">>errors"; - print OUT $result; - close OUT; - $failed = 1; - } -} - - -## SELFTESTS - -## Welcome notice - -print "Running selftest of the xml-i18n-tools module...\n\n"; -unlink "errors"; - -## 1. Extract/Simple desktop file - -print "1. Checking output from simple desktop file: "; - -$case = "extract1.desktop"; -system("/usr/bin/perl ../xml-i18n-extract --type=gettext/ini --quiet --update $srcdir/cases/$case") == 0 or $failed = 1; -check_result($case); - -## 2. Extract/Simple desktop-like file - -print "2. Checking output from simple desktop-like file: "; - -$case = "extract2.keyprop"; -system("/usr/bin/perl ../xml-i18n-extract --type=gettext/ini --quiet --update $srcdir/cases/$case") == 0 or $failed = 1; -check_result($case); - -## 3. Extract/Simple desktop-like file - -print "3. Checking output from simple xml-file: "; - -$case = "merge1.xml"; -system("/usr/bin/perl ../xml-i18n-merge -o --quiet $srcdir/cases $srcdir/cases/$case.in $srcdir/cases/$case") == 0 or $failed = 1; -check_result_output($case); - -print "4. Checking output from simple xml-file: "; - -$case = "extract3.xml.in"; -system("/usr/bin/perl ../xml-i18n-extract --type=gettext/xml --quiet --update $srcdir/cases/$case") == 0 or $failed = 1; -check_result($case); - -exit $failed; - diff --git a/tests/selftest.pl.in b/tests/selftest.pl.in index bdcfd6a..aa1ade3 100755 --- a/tests/selftest.pl.in +++ b/tests/selftest.pl.in @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!@PERL@ -w # Selftest for The XML Translation Tools # diff --git a/xml-i18n-extract.in b/xml-i18n-extract.in deleted file mode 100644 index 7debbe0..0000000 --- a/xml-i18n-extract.in +++ /dev/null @@ -1,303 +0,0 @@ -#!@PERL@ -w -# -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- - -# -# The XML Translation Extractor -# -# Copyright (C) 2000 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Authors: Kenneth Christiansen <kenneth@gnu.org> -# Darin Adler <darin@eazel.com> -# - -## Release information -my $PROGRAM = "xml-i18n-extract"; -my $PACKAGE = "@PACKAGE@"; -my $VERSION = "@VERSION@"; - -## Script options - Enable by setting value to 1 -my $ENABLE_INI = "1"; ## desktop and alike files -my $ENABLE_KEYS = "1"; ## mimetype descriptions -my $ENABLE_GLADE = "1"; ## glade files -my $ENABLE_XML = "1"; ## generic xml files - -## Loaded modules -use strict; -use File::Basename; -use Getopt::Long; - -## Scalars used by the option stuff -my $TYPE_ARG = "0"; -my $LOCAL_ARG = "0"; -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $UPDATE_ARG = "0"; -my $QUIET_ARG = "0"; - -my $FILE; -my $OUTFILE; - -my $gettext_type = ""; -my $input; -my %messages = (); - -## Always print first -$| = 1; - -## Handle options -GetOptions ( - "type=s" => \$TYPE_ARG, - "local|l" => \$LOCAL_ARG, - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "update" => \$UPDATE_ARG, - "quiet|q" => \$QUIET_ARG, - ) or &error; - -&split_on_argument; - - -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - - } elsif ($LOCAL_ARG) { - &place_local; - &extract; - - } elsif ($UPDATE_ARG) { - &place_normal; - &extract; - - } elsif (@ARGV > 0) { - &place_normal; - &message; - &extract; - - } else { - &help; - - } -} - -sub place_normal { - $FILE = $ARGV[0]; - $OUTFILE = "$FILE.h"; -} - -sub place_local { - $OUTFILE = fileparse($FILE, ()); - if (!-e "tmp/") { - system("mkdir tmp/"); - } - $OUTFILE = "./tmp/$OUTFILE.h" -} - -sub determine_type { - if ($TYPE_ARG =~ /^gettext\/(.*)/) { - $gettext_type=$1 - } -} - -## Sub for printing release information -sub version{ - print "${PROGRAM} (${PACKAGE}) $VERSION\n"; - print "Copyright (C) 2000 Free Software Foundation, Inc.\n"; - print "Written by Kenneth Christiansen, 2000.\n\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"; - exit; -} - -## Sub for printing usage information -sub help{ - print "Usage: ${PROGRAM} [FILENAME] [OPTIONS] ...\n"; - print "Generates a header file from an xml source file.\n\nGrabs all strings "; - print "between <_translatable_node> and it's end tag,\nwhere tag are all allowed "; - print "xml tags. Read the docs for more info.\n\n"; - print " -v, --version shows the version\n"; - print " -h, --help shows this help page\n"; - print " -q, --quiet quiet mode\n"; - print "\nReport bugs to <kenneth\@gnu.org>.\n"; - exit; -} - -## Sub for printing error messages -sub error{ -# print "xml-i18n-extract: invalid option @ARGV\n"; - print "Try `${PROGRAM} --help' for more information.\n"; - exit; -} - -sub message { - print "Generating C format header file for translation.\n"; -} - -sub extract { - &determine_type; - - &convert ($FILE); - - open OUT, ">$OUTFILE"; - &msg_write; - close OUT; - - print "Wrote $OUTFILE\n" unless $QUIET_ARG; -} - -sub convert($) { - - ## Reading the file - { - local (*IN); - local $/; #slurp mode - open (IN, "<$FILE") || die "can't open $FILE: $!"; - $input = <IN>; - } - - &type_ini; - &type_keys; - &type_xml; - &type_glade; -} - -sub type_ini { - - if ($ENABLE_INI) { - - ### For generic translatable desktop files ### - - if ($gettext_type eq "ini"){ - - while ($input =~ /^_.*=(.*)$/mg) { - $messages{$1} = []; - } - } - } -} - -sub type_keys { - - if ($ENABLE_KEYS) { - - ### For generic translatable mime/keys files ### - - if ($gettext_type eq "keys"){ - while ($input =~ /^\s*_\w+=(.*)$/mg) { - $messages{$1} = []; - } - } - } -} - -sub type_xml { - - if ($ENABLE_XML) { - - ### For generic translatable XML files ### - - if ($gettext_type eq "xml"){ - - while ($input =~ /[\t\n\s]_\w+=\"([^\"]+)\"/sg) { - $messages{$1} = []; - } - - while ($input =~ /<_\w+>([^_]+)<\/_\w+>/sg) { - $messages{$1} = []; - } - - } - } -} - -sub type_glade { - - if ($ENABLE_GLADE) { - - ### For translatable Glade XML files ### - - if ($gettext_type eq "glade"){ - - my $translate = "label|title|text|format|copyright|comments| - preview_text|tooltip"; - - while ($input =~ /<($translate)>([^<]+)<\/($translate)>/sg) { - - # Glade has some bugs, especially it uses translations tags to contain little - # non-translatable content. We work around this, by not including these - # strings that only includes something like: label4, and window1 - if ($2 !~ /^(window|label)[0-9]$/) { - $messages{$2} = []; - } - } - - while ($input =~ /<items>(..[^<]*)<\/items>/sg) { - my @items = split (/\n/, $1); - for (my $n = 0; $n < @items; $n++) { - $messages{$items[$n]} = []; - } - } - - } - } - -} - -sub msg_write { - - foreach my $message (sort keys %messages) { - - my ($tag) = @{ $messages{$message} }; - - # Replace XML entities for some special characters with - # the appropriate gettext syntax for those characters. - $message =~ s/"/\\"/mg; # " - $message =~ s/</</mg; - $message =~ s/>/>/mg; - $message =~ s/&/&/mg; - - print OUT "/* xgettext:no-c-format */\n" if $message =~ /%/; - print OUT "/* $tag */\n" if $tag; - - my @lines = split (/\n/, $message); - - for (my $n = 0; $n < @lines; $n++) { - - if ($n == 0) { - print OUT "char *s = N_(\""; - } else { - print OUT " \""; - } - - print OUT $lines[$n]; - - if ($n < @lines - 1) { - print OUT "\\n\"\n"; - } else { - print OUT "\");\n"; - } - } - } -} - diff --git a/xml-i18n-extract.in.in b/xml-i18n-extract.in.in index 7debbe0..24dc283 100644 --- a/xml-i18n-extract.in.in +++ b/xml-i18n-extract.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # -*- Mode: perl; indent-tabs-mode: nil; c-basic-offset: 4 -*- # diff --git a/xml-i18n-merge.in b/xml-i18n-merge.in deleted file mode 100644 index 46e4299..0000000 --- a/xml-i18n-merge.in +++ /dev/null @@ -1,401 +0,0 @@ -#!@PERL@ -w - -# -# The XML Translation Merge Tool -# -# Copyright (C) 2000 Free Software Foundation. -# Copyright (C) 2000, 2001 Eazel, Inc -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Authors: Maciej Stachowiak <mjs@eazel.com> -# Kenneth Christiansen <kenneth@gnu.org> -# Darin Adler <darin@eazel.com> -# - - -## Release information -my $PROGRAM = "xml-i18n-merge"; -my $PACKAGE = "@PACKAGE@"; -my $VERSION = "@VERSION@"; - -## Script options - Enable by setting value to 1 -my $ENABLE_XML = "1"; - -## Loaded modules -use strict; -use File::Basename; -use Getopt::Long; - -## Scalars used by the option stuff -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $XML_STYLE_ARG = "0"; -my $KEYS_STYLE_ARG = "0"; -my $DESKTOP_STYLE_ARG = "0"; -my $QUIET_ARG = "0"; - - -## Handle options -GetOptions ( - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "quiet|q" => \$QUIET_ARG, - "xml-style|o" => \$XML_STYLE_ARG, - "keys-style|k" => \$KEYS_STYLE_ARG, - "desktop-style|d" => \$DESKTOP_STYLE_ARG - ) or &error; - - -my $PO_DIR; -my $FILE; -my $OUTFILE; - -my @languages; -my %po_files_by_lang = (); -my %translations = (); - -&split_on_argument; - - -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - } elsif ($XML_STYLE_ARG && @ARGV > 2) { - &place_normal; - &message; - &preparation; - &xml_merge_translations; - } elsif ($KEYS_STYLE_ARG && @ARGV > 2) { - &place_normal; - &message; - &preparation; - &keys_merge_translations; - } elsif ($DESKTOP_STYLE_ARG && @ARGV > 2) { - &place_normal; - &message; - &preparation; - &desktop_merge_translations; - } else { - &help; - } -} - - -sub place_normal { - $PO_DIR = $ARGV[0]; - $FILE = $ARGV[1]; - $OUTFILE = $ARGV[2]; -} - - -## Sub for printing release information -sub version{ - print "${PROGRAM} (${PACKAGE}) ${VERSION}\n"; - print "Written by Maciej Stachowiak and Kenneth Christiansen, 2000.\n\n"; - print "Copyright (C) 2000 Free Software Foundation, Inc.\n"; - print "Copyright (C) 2000, 2001 Eazel, 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"; - exit; -} - -## Sub for printing usage information -sub help{ - print "Usage: ${PROGRAM} [OPTIONS] PO_DIRECTORY FILENAME OUTPUT_FILE\n"; - print "Generates an xml file that includes translated versions of some attributes,\n"; - print "from an untranslated source and a po directory that includes translations.\n"; - print " -v, --version shows the version\n"; - print " -h, --help shows this help page\n"; - print " -q, --quiet quiet mode\n"; - print " -o, --xml-style includes translations in the xml style\n"; - print " -k, --keys-style includes translations in the keys style\n"; - print " -d, --desktop-style includes translations in the desktop style\n"; - print "\nReport bugs to <mjs\@eazel.com>.\n"; - exit; -} - - -## Sub for printing error messages -sub error{ -# print "xml-i18n-merge: invalid option @ARGV\n"; - print "Try `${PROGRAM} --help' for more information.\n"; - exit; -} - - -sub message { - print "Merging translations into $OUTFILE.\n" unless $QUIET_ARG; -} - - - -sub preparation { - &gather_po_files; - &create_translation_database; -} - - - -# General-purpose code for looking up translations in .po files - -sub gather_po_files -{ - my @po_files = glob("${PO_DIR}/*.po"); - - @languages = map (&po_file2lang, @po_files); - - foreach my $lang (@languages) { - $po_files_by_lang{$lang} = shift (@po_files); - } -} - -sub po_file2lang -{ - my $tmp = $_; - $tmp =~ s/^.*\/(.*)\.po$/$1/; - return $tmp; -} - - -sub create_translation_database -{ - foreach my $lang (@languages) { - - my $po_file = $po_files_by_lang{$lang}; - - open PO_FILE, "<$po_file"; - - while (<PO_FILE>) { - if (/^#,.*fuzzy/) { - $_ = <PO_FILE>; next; - } - if (/^msgid "(.*)"/ ) { - my $msgid = $1; - $_ = <PO_FILE>; - - if (/^msgstr "(.+)"/) { - my $msgstr = $1; - $translations{$lang . "|" . $msgid} = $msgstr; - # print "[$lang]$msgstr\n"; - } - } - } - } -} - -sub lookup_translations -{ - my ($value) = @_; - - my %transmap = (); - - foreach my $lang (@languages) { - my $translation = lookup_translation ($value, $lang); - - if ($translation) { - $transmap{$lang} = $translation; - } - } - - return %transmap; -} - - -sub lookup_translation -{ - my ($string, $lang) = @_; - $string =~ s/\+/\\+/g; - - my $salt = "$lang|$string"; - - if ($translations{$salt}) { - return $translations{$salt}; - } - - return ""; -} - - -sub entity_encode_translations -{ - my %transmap = @_; - - foreach my $key (keys %transmap) { - $transmap{$key} = entity_encode ($transmap{$key}); - } - - return %transmap; -} - - -sub entity_encode -{ - my ($pre_encoded) = @_; - - my @list_of_chars = unpack ('C*', $pre_encoded); - - return join ('', map (&entity_encode_int, @list_of_chars)); -} - -sub entity_encode_int -{ - # FIXME: should probably entity encode more stuff. - if ($_ > 127) { - return "&#" . $_ . ";"; - } else { - return chr $_; - } -} - - - - - -## OAF/XML-specific merge code - -sub xml_merge_translations -{ - my $xml_source; { - local (*INPUT); - local $/; # slurp mode - open INPUT, "<$FILE" or die "can't open $FILE: $!"; - $xml_source = <INPUT>; - close INPUT; - } - - open OUTPUT, ">$OUTFILE"; - - while ($xml_source =~ /[ \t]*<[^<]*\s_\w+="[^"]*"[^<]*>/m) { - print OUTPUT $`; - my $orig_node = $&; - $xml_source = $'; - - my $non_translated_line = $orig_node; - $non_translated_line =~ s/_(\w+)="/$1="/; - - my $new_node = $non_translated_line; - - my $value_str = $orig_node; - $value_str =~ s/.*_\w+="([^"]*)".*/$1/s; - - if ($value_str) { - my %value_translation_map = entity_encode_translations - (lookup_translations ($value_str)); - - foreach my $key (keys %value_translation_map) { - my $translation = $value_translation_map{$key}; - - my $translated_line = $orig_node; - $translated_line =~ s/name="([^"]*)"/name="$1-$key"/; - $translated_line =~ s/(\s*)_(\w+)="[^"]*"/$1$2="$translation"/; - - $new_node .= "\n$translated_line"; - } - } - - $xml_source = $new_node . $xml_source; - } - - print OUTPUT $xml_source; - - close OUTPUT; -} - -sub keys_merge_translations -{ - open INPUT, "<${FILE}"; - - open OUTPUT, ">${OUTFILE}"; - - while (<INPUT>) { - chomp; - if (/^\s*_\w+=.*/) { - my $orig_line = $_; - - my $non_translated_line = $orig_line; - $non_translated_line =~ s/_([^="]*)=/$1=/; - - print OUTPUT "${non_translated_line}\n"; - - my $value_str = $orig_line; - $value_str =~ s/.*_\w+=(.*)/$1/; - - if ($value_str) { - my %value_translation_map = lookup_translations ($value_str); - - foreach my $key (keys %value_translation_map) { - my $translation = $value_translation_map{$key}; - - my $translated_line = $orig_line; - $translated_line =~ s/_([^="]*)=([^\n]*)/\[$key]$1=$translation/; - print OUTPUT "$translated_line\n"; - } - } - } else { - print OUTPUT "$_\n"; - } - } - - close OUTPUT; - close INPUT; -} - -sub desktop_merge_translations -{ - open INPUT, "<${FILE}"; - - open OUTPUT, ">${OUTFILE}"; - - while (<INPUT>) { - chomp; - if (/^\s*_\w+=.*/) { - my $orig_line = $_; - - my $non_translated_line = $orig_line; - $non_translated_line =~ s/_([^="]*)=/$1=/; - - print OUTPUT "${non_translated_line}\n"; - - my $value_str = $orig_line; - $value_str =~ s/.*_\w+=(.*)/$1/; - - if ($value_str) { - my %value_translation_map = lookup_translations ($value_str); - - foreach my $key (keys %value_translation_map) { - my $translation = $value_translation_map{$key}; - - my $translated_line = $orig_line; - $translated_line =~ s/^_([^="]*)=([^\n]*)/$1\[$key]=$translation/; - print OUTPUT "$translated_line\n"; - } - } - } else { - print OUTPUT "$_\n"; - } - } - - close OUTPUT; - close INPUT; - -} diff --git a/xml-i18n-merge.in.in b/xml-i18n-merge.in.in index 46e4299..3e1e1ac 100644 --- a/xml-i18n-merge.in.in +++ b/xml-i18n-merge.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # # The XML Translation Merge Tool diff --git a/xml-i18n-prepare.in b/xml-i18n-prepare.in deleted file mode 100755 index 8de2e64..0000000 --- a/xml-i18n-prepare.in +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/perl -w - -# XML I18N Desktop File Prepare Tool -# -# Copyright (C) 2001 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): Gediminas Paulauskas <menesis@delfi.lt> -# Kenneth Christiansen <kenneth@gnu.org> - -## Release information -my $PROGRAM = "xml-i18n-extract"; -my $PACKAGE = "@PACKAGE@"; -my $VERSION = "@VERSION@"; -my $MAINTAINER = "<menesis\@delfi.lt>"; - -## Loaded modules -use strict; -use Getopt::Long; -use File::Find; - -## Scalars used by the option stuff -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $VERBOSE = "0"; - -my @languages; -my @desktop_files; -my $new; -my $file; - -my $desktop_extension = "(desktop|soundlist|keys|directory)+"; -my $desktop_find_regex = ".*desktop\\|soundlist\\|keys\\|directory"; - -my $keywords = "Name|Comment|description"; - -## Always print as the first thing -$| = 1; - -## Handle options -GetOptions ( - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "verbose|x" => \$VERBOSE - ) or &invalid_option; - - -## Use the supplied arguments -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - - } else { - &main; - } -} - -&split_on_argument; - -sub main -{ - print "Working, please wait...\n" if (! $VERBOSE); - &find_desktop_files; - &append_keywords; - &add_to_potfiles; - &perform_rescue; - &add_to_cvsignore; - &generate_empty; -} - -sub version{ - - ## Print version information - print "${PROGRAM} ${PACKAGE} $VERSION\n"; - print "Written by Gediminas Paulauskas <menesis\@delfi.lt>, 2000.\n\n"; - print "Copyright (C) 2000 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"; - exit; -} - -sub help -{ - ## Print usage information - print "Usage: $PROGRAM [OPTION] KEYWORD ...\n"; - print "Updates pot files and merge them with the translations.\n"; - print "KEYWORD is additional key besides Name, Comment and description\n\n"; - print " -H, --help shows this help page\n"; - print " -X, --verbose show lots of feedback\n"; - print " -V, --version shows the version\n"; - print "Report bugs to $MAINTAINER.\n"; - exit; -} - -sub invalid_option -{ - ## Handle invalid arguments - ## my $opt = $ARGV[0]; - ## print "$PROGRAM: invalid option -- $opt\n"; - print "Try `$PROGRAM --help' for more information.\n"; - exit 1; -} - -sub append_keywords -{ - my $arg; - foreach $arg (@ARGV) { - $keywords .= "|$arg"; - } -} - -sub add_to_potfiles -{ - open FILE, ">>po/POTFILES.in"; - my $intro = 0; - foreach my $desktop (@desktop_files) { - next if contains("po/POTFILES.in", "$desktop.in"); - # Print explanation comment only once - unless ($intro) { - print FILE "# files added by xml-i18n-prepare\n"; - $intro = 1; - } - print FILE "$desktop.in\n"; - } - close FILE; -} - -sub perform_rescue -{ - foreach $file (@desktop_files) { - &rescue_file($file); - } -} - -sub rescue_file -{ - my ($filename) = @_; - my ($msgid, $line, $lang); - - print "Rescuing translations from $filename ...\n" if $VERBOSE; - - open ORIG, "<$filename"; - $line = 1; - while (<ORIG>) { - chomp; - $line++; - my $entry = $_; - if (($entry =~ /^($keywords)=(.*)$/) || - ($entry =~ /^(\s*description)=(.*)$/)) { - $msgid = $2; - $msgid =~ s/\"/\\"/; - } elsif (($entry =~ /^($keywords)\[(.*?)\]=(.*)$/) || - ($entry =~ /^(\s*\[)(.*?)\]description=(.*)$/)) { - $lang = $2; - next if (!-s "po/$lang.po"); - - my $msgstr = $3; - $msgstr =~ s/"/\\"/g; - - $line--; - next if contains("po/$lang.po", "msgid \"$msgid\""); - - open POFILE, ">>po/$lang.po"; - - print POFILE "\n#: $filename.in:$line\n"; - print POFILE "msgid \"$msgid\"\n"; - print POFILE "msgstr \"$msgstr\"\n"; - - close POFILE; - } - } -} - -sub generate_empty -{ - my $all = ' '; - foreach my $full (@desktop_files) { - $new = "$full.in"; - $all .= "$new "; - print "Generating empty $new ...\n" if $VERBOSE; - open FULL, "<$full"; - open NEW, ">$new"; - - while (<FULL>) { - unless ( - (/^($keywords)\[.*?\]=.*$/) || - (/^\s*\[(.*?)\]description=.*$/) - ) { - if (/^($keywords)=.*$/) { - print NEW "_$_"; - } elsif (/^(\s*)(description=.*)$/) { - print NEW "$1_$2\n"; - } else { - print NEW; - } - } - } - - close NEW; - } - print "*** Please add these files to CVS by following command: ***\n" - . "cvs add$all\n"; -} - -sub add_to_cvsignore -{ - my $all = ' '; - my $ign; - foreach $file (@desktop_files) { - $file =~ /^(.*\/)*(.*?\.$desktop_extension$)$/; - if ($1) { - $ign = "$1.cvsignore"; - } else { - $ign = ".cvsignore"; - } - my $basename = $2; - - next if contains($ign, $basename); - - print "Appending $basename to $ign\n" if $VERBOSE; - open FILE, ">>$ign"; - print FILE "$basename\n"; - $all .= "$file "; - } - close FILE; - unless ($all eq ' ') { - print "*** Please remove files from CVS by following command: ***\n" - . "cvs remove -f$all\n"; - } -} - -sub contains -{ - my ($name, $expr) = @_; - open CONT, "<$name"; - while (<CONT>) { - return 1 if /^$expr$/; - } - return 0; -} - -sub find_desktop_files -{ - if ($VERBOSE) { - print "Found these interesting files:\n"; - } else { - print "Finding interesting files..."; - } - find (\&wanted, '.'); - print "done\n" unless $VERBOSE; -} - -sub wanted -{ - if (/$desktop_extension$/) { - my $file = $File::Find::name; - $file =~ s/\.\///; - push @desktop_files, $file; - print "$file\n" if $VERBOSE; - } -} - -# vim: ts=4 sw=4 expandtab diff --git a/xml-i18n-prepare.in.in b/xml-i18n-prepare.in.in deleted file mode 100755 index 8de2e64..0000000 --- a/xml-i18n-prepare.in.in +++ /dev/null @@ -1,283 +0,0 @@ -#!/usr/bin/perl -w - -# XML I18N Desktop File Prepare Tool -# -# Copyright (C) 2001 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): Gediminas Paulauskas <menesis@delfi.lt> -# Kenneth Christiansen <kenneth@gnu.org> - -## Release information -my $PROGRAM = "xml-i18n-extract"; -my $PACKAGE = "@PACKAGE@"; -my $VERSION = "@VERSION@"; -my $MAINTAINER = "<menesis\@delfi.lt>"; - -## Loaded modules -use strict; -use Getopt::Long; -use File::Find; - -## Scalars used by the option stuff -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $VERBOSE = "0"; - -my @languages; -my @desktop_files; -my $new; -my $file; - -my $desktop_extension = "(desktop|soundlist|keys|directory)+"; -my $desktop_find_regex = ".*desktop\\|soundlist\\|keys\\|directory"; - -my $keywords = "Name|Comment|description"; - -## Always print as the first thing -$| = 1; - -## Handle options -GetOptions ( - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "verbose|x" => \$VERBOSE - ) or &invalid_option; - - -## Use the supplied arguments -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - - } else { - &main; - } -} - -&split_on_argument; - -sub main -{ - print "Working, please wait...\n" if (! $VERBOSE); - &find_desktop_files; - &append_keywords; - &add_to_potfiles; - &perform_rescue; - &add_to_cvsignore; - &generate_empty; -} - -sub version{ - - ## Print version information - print "${PROGRAM} ${PACKAGE} $VERSION\n"; - print "Written by Gediminas Paulauskas <menesis\@delfi.lt>, 2000.\n\n"; - print "Copyright (C) 2000 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"; - exit; -} - -sub help -{ - ## Print usage information - print "Usage: $PROGRAM [OPTION] KEYWORD ...\n"; - print "Updates pot files and merge them with the translations.\n"; - print "KEYWORD is additional key besides Name, Comment and description\n\n"; - print " -H, --help shows this help page\n"; - print " -X, --verbose show lots of feedback\n"; - print " -V, --version shows the version\n"; - print "Report bugs to $MAINTAINER.\n"; - exit; -} - -sub invalid_option -{ - ## Handle invalid arguments - ## my $opt = $ARGV[0]; - ## print "$PROGRAM: invalid option -- $opt\n"; - print "Try `$PROGRAM --help' for more information.\n"; - exit 1; -} - -sub append_keywords -{ - my $arg; - foreach $arg (@ARGV) { - $keywords .= "|$arg"; - } -} - -sub add_to_potfiles -{ - open FILE, ">>po/POTFILES.in"; - my $intro = 0; - foreach my $desktop (@desktop_files) { - next if contains("po/POTFILES.in", "$desktop.in"); - # Print explanation comment only once - unless ($intro) { - print FILE "# files added by xml-i18n-prepare\n"; - $intro = 1; - } - print FILE "$desktop.in\n"; - } - close FILE; -} - -sub perform_rescue -{ - foreach $file (@desktop_files) { - &rescue_file($file); - } -} - -sub rescue_file -{ - my ($filename) = @_; - my ($msgid, $line, $lang); - - print "Rescuing translations from $filename ...\n" if $VERBOSE; - - open ORIG, "<$filename"; - $line = 1; - while (<ORIG>) { - chomp; - $line++; - my $entry = $_; - if (($entry =~ /^($keywords)=(.*)$/) || - ($entry =~ /^(\s*description)=(.*)$/)) { - $msgid = $2; - $msgid =~ s/\"/\\"/; - } elsif (($entry =~ /^($keywords)\[(.*?)\]=(.*)$/) || - ($entry =~ /^(\s*\[)(.*?)\]description=(.*)$/)) { - $lang = $2; - next if (!-s "po/$lang.po"); - - my $msgstr = $3; - $msgstr =~ s/"/\\"/g; - - $line--; - next if contains("po/$lang.po", "msgid \"$msgid\""); - - open POFILE, ">>po/$lang.po"; - - print POFILE "\n#: $filename.in:$line\n"; - print POFILE "msgid \"$msgid\"\n"; - print POFILE "msgstr \"$msgstr\"\n"; - - close POFILE; - } - } -} - -sub generate_empty -{ - my $all = ' '; - foreach my $full (@desktop_files) { - $new = "$full.in"; - $all .= "$new "; - print "Generating empty $new ...\n" if $VERBOSE; - open FULL, "<$full"; - open NEW, ">$new"; - - while (<FULL>) { - unless ( - (/^($keywords)\[.*?\]=.*$/) || - (/^\s*\[(.*?)\]description=.*$/) - ) { - if (/^($keywords)=.*$/) { - print NEW "_$_"; - } elsif (/^(\s*)(description=.*)$/) { - print NEW "$1_$2\n"; - } else { - print NEW; - } - } - } - - close NEW; - } - print "*** Please add these files to CVS by following command: ***\n" - . "cvs add$all\n"; -} - -sub add_to_cvsignore -{ - my $all = ' '; - my $ign; - foreach $file (@desktop_files) { - $file =~ /^(.*\/)*(.*?\.$desktop_extension$)$/; - if ($1) { - $ign = "$1.cvsignore"; - } else { - $ign = ".cvsignore"; - } - my $basename = $2; - - next if contains($ign, $basename); - - print "Appending $basename to $ign\n" if $VERBOSE; - open FILE, ">>$ign"; - print FILE "$basename\n"; - $all .= "$file "; - } - close FILE; - unless ($all eq ' ') { - print "*** Please remove files from CVS by following command: ***\n" - . "cvs remove -f$all\n"; - } -} - -sub contains -{ - my ($name, $expr) = @_; - open CONT, "<$name"; - while (<CONT>) { - return 1 if /^$expr$/; - } - return 0; -} - -sub find_desktop_files -{ - if ($VERBOSE) { - print "Found these interesting files:\n"; - } else { - print "Finding interesting files..."; - } - find (\&wanted, '.'); - print "done\n" unless $VERBOSE; -} - -sub wanted -{ - if (/$desktop_extension$/) { - my $file = $File::Find::name; - $file =~ s/\.\///; - push @desktop_files, $file; - print "$file\n" if $VERBOSE; - } -} - -# vim: ts=4 sw=4 expandtab diff --git a/xml-i18n-toolize.in b/xml-i18n-toolize.in index c25b9ef..46f44d3 100644 --- a/xml-i18n-toolize.in +++ b/xml-i18n-toolize.in @@ -134,7 +134,7 @@ if test -z "$files"; then echo "$progname: cannot list files in \`$pkgdatadir'" 1>&2 exit 1 fi -files='xml-i18n-extract xml-i18n-merge xml-i18n-update' +files='xml-i18n-extract.in xml-i18n-merge.in xml-i18n-update.in' auxdir=. auxdirline=`egrep '^AC_CONFIG_AUX_DIR' configure.in 2>/dev/null` diff --git a/xml-i18n-tools.Makefile.patch b/xml-i18n-tools.Makefile.patch index 913f4d0..c1d8ecc 100644 --- a/xml-i18n-tools.Makefile.patch +++ b/xml-i18n-tools.Makefile.patch @@ -22,15 +22,6 @@ DEFS = @DEFS@ CFLAGS = @CFLAGS@ -@@ -49,7 +55,7 @@ - POFILES = @POFILES@ - GMOFILES = @GMOFILES@ - DISTFILES = ChangeLog Makefile.in.in POTFILES.in $(PACKAGE).pot \ --stamp-cat-id $(POFILES) $(GMOFILES) $(SOURCES) -+stamp-cat-id $(POFILES) $(GMOFILES) $(SOURCES) $(XML_I18N_UPDATE) $(XML_I18N_EXTRACT) - - POTFILES = \ - @@ -85,12 +91,7 @@ all-no: diff --git a/xml-i18n-tools.m4 b/xml-i18n-tools.m4 index 5504544..4e42949 100644 --- a/xml-i18n-tools.m4 +++ b/xml-i18n-tools.m4 @@ -24,47 +24,62 @@ # serial 1 AC_PROG_XML_I18N_TOOLS AC_DEFUN(AC_PROG_XML_I18N_TOOLS, [ -# Always use our own xml-i18n-tools. - -XML_I18N_EXTRACT='$(top_srcdir)/xml-i18n-extract' -AC_SUBST(XML_I18N_EXTRACT)dnl - -XML_I18N_MERGE='$(top_srcdir)/xml-i18n-merge' -AC_SUBST(XML_I18N_MERGE)dnl - -XML_I18N_UPDATE='$(top_srcdir)/xml-i18n-update' -AC_SUBST(XML_I18N_UPDATE)dnl dnl This is a hack - we use the expansion of AC_SUBST instead of dnl AC_SUBST itself to avoid automake putting dnl XML_I18N_MERGE_OAF_RULE = @XML_I18N_MERGE_OAF_RULE@ dnl in all the Makefile.in's -XML_I18N_MERGE_OAF_RULE='\%.oaf : \%.oaf.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -o $(top_srcdir)/po $< [$]*.oaf' +XML_I18N_MERGE_OAF_RULE='\%.oaf : \%.oaf.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -o $(top_srcdir)/po $< [$]*.oaf' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_OAF_RULE@%[$]XML_I18N_MERGE_OAF_RULE%g AC_DIVERT_POP()dnl -dnl This is a hack - we use the expansion of AC_SUBST instead of -dnl AC_SUBST itself to avoid automake putting -dnl XML_I18N_MERGE_KEYS_RULE = @XML_I18N_MERGE_KEYS_RULE@ -dnl in all the Makefile.in's -XML_I18N_MERGE_KEYS_RULE='\%.keys : \%.keys.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -k $(top_srcdir)/po $< [$]*.keys' +dnl same deal +XML_I18N_MERGE_KEYS_RULE='\%.keys : \%.keys.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -k $(top_srcdir)/po $< [$]*.keys' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_KEYS_RULE@%[$]XML_I18N_MERGE_KEYS_RULE%g AC_DIVERT_POP()dnl -dnl This is a hack - we use the expansion of AC_SUBST instead of -dnl AC_SUBST itself to avoid automake putting -dnl XML_I18N_MERGE_DESKTOP_RULE = @XML_I18N_MERGE_DESKTOP_RULE@ -dnl in all the Makefile.in's -XML_I18N_MERGE_DESKTOP_RULE='\%.desktop : \%.desktop.in $(top_srcdir)/xml-i18n-merge $(top_srcdir)/po/*.po\ - $(top_srcdir)/xml-i18n-merge -d $(top_srcdir)/po $< [$]*.desktop' +dnl same deal +XML_I18N_MERGE_DESKTOP_RULE='\%.desktop : \%.desktop.in $(top_builddir)/xml-i18n-merge $(top_srcdir)/po/*.po\ + $(top_builddir)/xml-i18n-merge -d $(top_srcdir)/po $< [$]*.desktop' AC_DIVERT_PUSH(AC_DIVERSION_SED)dnl s%@XML_I18N_MERGE_DESKTOP_RULE@%[$]XML_I18N_MERGE_DESKTOP_RULE%g AC_DIVERT_POP()dnl +# Always use our own xml-i18n-tools. +XML_I18N_EXTRACT='$(top_builddir)/xml-i18n-extract' +AC_SUBST(XML_I18N_EXTRACT)dnl + +XML_I18N_MERGE='$(top_builddir)/xml-i18n-merge' +AC_SUBST(XML_I18N_MERGE)dnl + +XML_I18N_UPDATE='$(top_builddir)/xml-i18n-update' +AC_SUBST(XML_I18N_UPDATE)dnl + +AC_PATH_PROG(XML_I18N_TOOLS_PERL, perl) +if test -z "$XML_I18N_TOOLS_PERL"; then + AC_MSG_ERROR([perl not found; required for xml-i18n-tools]) +fi +if test -z "`$XML_I18N_TOOLS_PERL -v | fgrep '5.' 2> /dev/null`"; then + AC_MSG_ERROR([perl 5.x required for xml-i18n-tools]) +fi + +dnl manually sed perl in so people don't have to put the xml-i18n-tools scripts in their +dnl AC_OUTPUT +AC_OUTPUT_COMMANDS([ +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-extract.in > xml-i18n-extract; +chmod ugo+x xml-i18n-extract; + +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-merge.in > xml-i18n-merge; +chmod ugo+x xml-i18n-merge; + +sed -e "s:@XML_I18N_TOOLS_PERL@:${XML_I18N_TOOLS_PERL}:;" < ${ac_given_srcdir}/xml-i18n-update.in > xml-i18n-update; +chmod ugo+x xml-i18n-update; +], XML_I18N_TOOLS_PERL=${XML_I18N_TOOLS_PERL}) + # Redirect the config.log output again, so that the ltconfig log is not # clobbered by the next message. exec 5>>./config.log diff --git a/xml-i18n-unicodify b/xml-i18n-unicodify deleted file mode 100755 index 041ac73..0000000 --- a/xml-i18n-unicodify +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/perl -w - -# -# The i18n Unicode Encoding Utility -# -# Copyright (C) 2001 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Authors: Kenneth Christiansen <kenneth@gnu.org> -# - -my $LANG = $ARGV[0]; -my $VERBOSE="1"; - -if (! $LANG) { - print "You must specify the language\n"; -} - -open IN, "$LANG.po"; - -while (<IN>) { - ## example: "Content-Type: text/plain; charset=ISO-8859-1\n" - if (/Content-Type\:.*charset=(.*)\\n/) { - $encoding_code_orig = $1; - last; - } -} - -close IN; - -print "Converting from $encoding_code_orig\n" if $VERBOSE; - -my $extern_conv="iconv --from=$encoding_code_orig " - ."--to=UTF-8 $LANG.po > $LANG.po-1"; - -system($extern_conv); - -my $source_orig; -{ - local (*IN); - local $/; #slurp mode - open (IN, "<$LANG.po-1") || die "can't open $LANG.po-1: $!"; - $source_orig = <IN>; -} - -$source_orig =~ s/Content-Type\:(.*)$encoding_code_orig/Content-Type\:$1UTF-8/; - -close IN; - -open OUT, ">$LANG.po-1"; -print OUT $source_orig; -close OUT; diff --git a/xml-i18n-unicodify.in b/xml-i18n-unicodify.in index 041ac73..44fea6c 100755 --- a/xml-i18n-unicodify.in +++ b/xml-i18n-unicodify.in @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!@PERL@ -w # # The i18n Unicode Encoding Utility diff --git a/xml-i18n-update.in b/xml-i18n-update.in deleted file mode 100644 index abdae55..0000000 --- a/xml-i18n-update.in +++ /dev/null @@ -1,495 +0,0 @@ -#!@PERL@ -w - -# The GNOME Translation Update Tool -# -# Copyright (C) 2000 Free Software Foundation. -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# This script is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author(s): Kenneth Christiansen - -## Release information -my $PROGRAM = "xml-i18n-update"; -my $VERSION = "@VERSION@"; -my $_PACKAGE = "@PACKAGE@"; - -## Loaded modules -## FIXME: use strict; -use Getopt::Long; -use Cwd; -use File::Copy; -use File::Find; - -## Scalars used by the option stuff -my $LANG = $ARGV[0]; -my $HELP_ARG = "0"; -my $VERSION_ARG = "0"; -my $DIST_ARG = "0"; -my $POT_ARG = "0"; -my $HEADERS_ARG = "0"; -my $MAINTAIN_ARG = "0"; -my $REPORT_ARG = "0"; -my $VERBOSE = "0"; - -my @languages; -my %po_files_by_lang = (); - -my $xml_extension = "xml|glade|desktop\.in|directory\.in|" - ."soundlist\.in|keys\.in|oaf(\.in)+"; - -my $PACKAGE = &find_package_name; - -## Always print as the first thing -$| = 1; - -## Give error if script is run without an argument -if (! $LANG){ - print "${PROGRAM}: missing file arguments\n"; - print "Try `${PROGRAM} --help' for more information.\n"; - exit; -} - -## Handle options -GetOptions ( - "help|h|?" => \$HELP_ARG, - "version|v" => \$VERSION_ARG, - "dist|d" => \$DIST_ARG, - "pot|p" => \$POT_ARG, - "headers|s" => \$HEADERS_ARG, - "maintain|m" => \$MAINTAIN_ARG, - "report|r" => \$REPORT_ARG, - "verbose|x" => \$VERBOSE - ) or &invalid_option; - - -## Use the supplied arguments -## Check for options. -## This section will check for the different options. - -sub split_on_argument { - - if ($VERSION_ARG) { - &version; - - } elsif ($HELP_ARG) { - &help; - - } elsif ($DIST_ARG) { - &merging; - &status; - - } elsif ($POT_ARG) { - &gen_headers; - &generate_pot; - - } elsif ($HEADERS_ARG) { - &gen_headers; - exit; - - } elsif ($MAINTAIN_ARG) { - &maintain; - - } elsif ($REPORT_ARG) { - &show_status; - - } elsif ($LANG) { - if ($LANG =~ /^-/){ ## not an option - &help; - } else { - &main; - } - - } else { - &help; - } -} - -&split_on_argument; - -sub main -{ - if(-s "$LANG.po"){ - print "Working, please wait..." unless $VERBOSE; - &gen_headers; - &generate_pot; - &merging; - &status; - } - - ## Report error if the language file supplied - ## to the command line is non-existent - else { - ¬_existing; - } -} - -sub determine_type($) { - - my $type = $_; - - if ($type =~ /\[type: (gettext\/[^\]].*)]/) { - $gettext_type=$1; - } - elsif ($type =~ /(?:xml|oaf(?:\.in)+)$/) { - $gettext_type="gettext\/xml"; - } - elsif ($type =~ /glade$/) { - $gettext_type="gettext\/glade"; - } - elsif ($type =~ /desktop(?:\.in)+$/) { - $gettext_type="gettext\/ini"; - } - elsif ($type =~ /keys(?:\.in)+$/) { - $gettext_type="gettext\/keys"; - } - else { $gettext_type=""; } -} - -sub version{ - - ## Print version information - print "${PROGRAM} (${_PACKAGE}) $VERSION\n"; - print "Written by Kenneth Christiansen <kenneth\@gnome.org>, 2000.\n\n"; - print "Copyright (C) 2000 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"; - exit; -} - -sub help -{ - ## Print usage information - print "Usage: ./${PROGRAM} [OPTIONS] ...LANGCODE\n"; - print "Updates pot files and merge them with the translations.\n\n"; - print " -H, --help shows this help page\n"; - print " -P, --pot generate the pot file only\n"; - print " -S, --headers generate the XML headerfiles in POTFILES.in\n"; - print " -M, --maintain search for missing files in POTFILES.in\n"; - print " -R, --report creates a status report for the module.\n"; - print " -X, --verbose show lots of feedback\n"; - print " -V, --version shows the version\n"; - print "\nExamples of use:\n"; - print "${PROGRAM} --pot just creates a new pot file from the source\n"; - print "${PROGRAM} da created new pot file and updated the da.po file\n\n"; - print "Report bugs to <kenneth\@gnome.org>.\n"; - exit; -} - -sub maintain -{ - my (@buf_i18n_plain, - @buf_i18n_xml, - @buf_potfiles, - @buf_potfiles_ignore, - @buf_allfiles_sorted, - @buf_potfiles_sorted - ); - - ## Search and find all translatable files - find sub { push @buf_i18n_plain, "$File::Find::name" if /\.(c|y|cc|c\+\+|h|gob)$/ }, ".."; - find sub { push @buf_i18n_xml, "$File::Find::name" if /\.($xml_extension)$/ }, ".."; - - open(POTFILES, "POTFILES.in") || die "$PROGRAM: there's no POTFILES.in!!!\n"; - @buf_potfiles = <POTFILES>; - - print "Searching for missing translatable files...\n"; - - ## Check if we should ignore some found files, when - ## comparing with POTFILES.in - if (-s "POTFILES.skip"){ - open FILE, "POTFILES.skip"; - while (<FILE>) { - if (/^[^#]/){ - push @buf_potfiles_ignore, $_; - } - } - print "Found POTFILES.skip: Ignoring files...\n"; - @buf_potfiles = (@buf_potfiles_ignore, @buf_potfiles); - } - - foreach my $file (@buf_i18n_plain){ - open FILE, "<$file"; - while (<FILE>) { - if (/_\(\"/){ - ## Remove the first 3 chars and add newline - push @buf_allfiles, unpack("x3 A*", $file) . "\n"; - last; - } - } - } - - foreach my $file (@buf_i18n_xml){ - open FILE, "<$file"; - while (<FILE>) { - if (/\s_(.*)="/){ - ## Remove the first 3 chars and add newline - push @buf_allfiles, unpack("x3 A*", $file) . "\n"; - last; - } - } - } - - @buf_allfiles_sorted = sort (@buf_allfiles); - @buf_potfiles_sorted = sort (@buf_potfiles); - - my %in2; - foreach (@buf_potfiles_sorted) { - $in2{$_} = 1; - } - - foreach (@buf_allfiles_sorted){ - if (!exists($in2{$_})){ - push @result, $_ - } - } - - ## Save file with information about the files missing - ## if any, and give information about this proceedier - if(@result){ - open OUT, ">missing"; - print OUT @result; - print "\nHere is the result:\n\n", @result, "\n"; - print "The file \"missing\" has been placed in the current directory.\n"; - print "Files supposed to be ignored should be placed in \"POTFILES.skip\"\n"; - } - - ## If there is nothing to complain about, notice the user - else{ - print "\nWell, it's all perfect! Congratulation!\n"; - } -} - -sub invalid_option -{ - ## Handle invalid arguments - print "${PROGRAM}: invalid option -- $LANG\n"; - print "Try `${PROGRAM} --help' for more information.\n"; - exit 1; -} - -sub gen_headers -{ - my $XML_I18N_EXTRACT = `which xml-i18n-extract 2>/dev/null`; - chomp $XML_I18N_EXTRACT; - - $XML_I18N_EXTRACT = $ENV{"XML_I18N_EXTRACT"} if $ENV{"XML_I18N_EXTRACT"}; - - ## Generate the .h header files, so we can allow glade and - ## xml translation support - if (! -s $XML_I18N_EXTRACT) - { - print "\n *** The xml-i18n-extract script wasn't found!" - ."\n *** Without this xml-i18n-update can not generate files.\n"; - exit; - } - else - { - open FILE, "<POTFILES.in"; - while (<FILE>) { - chomp; - - ## Find xml files in POTFILES.in and generate the - ## files with help from the xml-i18n-extract script - - my $gettext_type=&determine_type($1); - - if (/\.($xml_extension)$/ || /^\[/){ - $_ =~ s/^\[[^\[].*]\s*//; - $filename = "../$_"; - - if ($VERBOSE){ - system($XML_I18N_EXTRACT, "--update", "--type=$gettext_type", $filename); - } else { - system($XML_I18N_EXTRACT, "--update", "--type=$gettext_type", "--quiet", $filename); - } - } - } - close FILE; - } -} - -sub generate_pot -{ - ## Generate the potfiles from the POTFILES.in file - - print "Building the $PACKAGE.pot...\n" if $VERBOSE; - - move("POTFILES.in", "POTFILES.in.old"); - - open INFILE, "<POTFILES.in.old"; - open OUTFILE, ">POTFILES.in"; - while (<INFILE>) { - s/\.($xml_extension)$/$&.h/; - s/^\[.*]\s*(.*)/$1.h/; - print OUTFILE $_; - } - close OUTFILE; - close INFILE; - - my $gettext_test ="test \! -f $PACKAGE\.po \|\| \( rm -f \.\/$PACKAGE\.pot " - ."&& mv $PACKAGE\.po \.\/$PACKAGE\.pot \)"; - - system("xgettext", "--default-domain\=$PACKAGE", "--directory\=\.\.", - "--add-comments", "--keyword\=\_", "--keyword\=N\_", - "--files-from\=\.\/POTFILES\.in"); - - system($gettext_test); - - print "Wrote $PACKAGE.pot\n" if $VERBOSE; - - move("POTFILES.in.old", "POTFILES.in"); - - print "Removing generated header (.h) files..." if $VERBOSE; - - open FILE, "<POTFILES.in"; - while (<FILE>) - { - chomp; - unlink "../$_.h" if /\.($xml_extension)$/; - } - close FILE; - print "done\n" if $VERBOSE; -} - -sub merging -{ - if ($ARGV[1]){ - $LANG = $ARGV[1]; - } else { - $LANG = $ARGV[0]; - } - - if ($ARGV[0] ne "--dist" && $ARGV[0] ne "-D") { - print "Merging $LANG.po with $PACKAGE.pot..." if $VERBOSE; - } - - &perform_merge($LANG); - ## Remove the "messages" trash file generated by gettext - unlink "messages"; -} - -sub perform_merge -{ - my ($LANG) = @_; - - copy("$LANG.po", "$LANG.po.old") || die "copy failed: $!"; - - ## Preform merge - system("msgmerge", "$LANG.po.old", "$PACKAGE.pot", "-o", "$LANG.po"); - - ## Remove the backup file - unlink "$LANG.po.old"; -} - -sub not_existing -{ - ## Report error if supplied language file is non-existing - print "$PROGRAM: sorry, $LANG.po does not exist!\n"; - print "Try `$PROGRAM --help' for more information.\n"; - exit; -} - -sub gather_po_files -{ - my @po_files = glob("./*.po"); - - @languages = map (&po_file2lang, @po_files); - - foreach my $lang (@languages) { - $po_files_by_lang{$lang} = shift (@po_files); - } -} - -sub po_file2lang -{ - my $tmp = $_; - $tmp =~ s/^.*\/(.*)\.po$/$1/; - return $tmp; -} - -sub status -{ - ## Print statistics - system("msgfmt", "--statistics", "$LANG.po"); - print "\n"; -} - -sub show_status -{ - &gen_headers; - &generate_pot; - &gather_po_files; - - foreach my $lang (@languages){ - print "$lang: "; - &perform_merge($lang); - } - - print "\n\n * Current translation support in $PACKAGE \n\n"; - - foreach my $lang (@languages){ - print "$lang: "; - ## Print statistics - system("msgfmt", "--statistics", "$lang.po"); - } -} - -sub find_package_name -{ - my $base_dirname = getcwd(); - $base_dirname =~ s@.*/@@; - - my ($conf_in, $src_dir); - - if ($base_dirname eq "po") { - if (-f "../configure.in") { - $conf_in = "../configure.in"; - } else { - my $makefile_source; { - local (*IN); - local $/; # slurp mode - open (IN, "<Makefile") || die "can't open Makefile: $!"; - $makefile_source = <IN>; - } - if ($makefile_source =~ /^top_srcdir[ \t]*=/) { - $src_dir = $_; - $srcdir =~ s/top_srcdir[ \t]*=[ \t]*([^ \t\n\r]*)/$1/; - chomp $srcdir; - $conf_in = "$srcdir" . "/configure.in" . "\n"; - } - } - - my $conf_source; { - local (*IN); - local $/; # slurp mode - open (IN, "<$conf_in") || die "can't open $conf_in: $!"; - $conf_source = <IN>; - } - - if ($conf_source =~ /AM_INIT_AUTOMAKE\(([^,]*),(.*)/) { - $package_name = $1; - if ($package_name =~ /^[\$](.*)/){ - if ($conf_source =~ /$1=(.*)/) { - $package_name = $1; - } - } - } - return $package_name; - } - - print "$PROGRAM: Unable to determine package name.\n" . - "Make sure to run this script inside the po directory.\n"; - exit; -} diff --git a/xml-i18n-update.in.in b/xml-i18n-update.in.in index abdae55..e4d8d1b 100644 --- a/xml-i18n-update.in.in +++ b/xml-i18n-update.in.in @@ -1,4 +1,4 @@ -#!@PERL@ -w +#!@XML_I18N_TOOLS_PERL@ -w # The GNOME Translation Update Tool # |