diff options
author | Swedish Language Team <swedish> | 2000-02-26 17:41:28 +0000 |
---|---|---|
committer | Swedish Language Team <swedish> | 2000-02-26 17:41:28 +0000 |
commit | aaad09b704adb6467ae8f8463483674320ae4ad0 (patch) | |
tree | 05649fbd96195761a2c59e457febcd4f2b0809f7 /copypage.pl | |
parent | df5248bb7718bcd2254d2e9eaed865b30e6f6673 (diff) |
Added script that automates creation of new translations; it will copy the
requested page from the English directory to the local translation directory
(as specified in language.conf) and add the '<!--translation x.x-->' line.
If the destination directory does not exist, it will be created and the
Makefile copied.
It will unfortunately not translate the page for you... :-)
CVS version numbers
copypage.pl: INITIAL -> 1.1
Diffstat (limited to 'copypage.pl')
-rwxr-xr-x | copypage.pl | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/copypage.pl b/copypage.pl new file mode 100755 index 00000000000..db919acbbd8 --- /dev/null +++ b/copypage.pl @@ -0,0 +1,125 @@ +#!/usr/bin/perl -w + +# This script copies the file named on the command line to the translation +# named in copypage.conf, and adds the <!--translation x.x--> string to it. +# It also will create the destination directory if necessary, and copy the +# Makefile from the source. + +# Written on 2000-02-26 by peter karlsson <peter@softwolves.pp.se> +# © Copyright 2000 Software in the public intereset, Inc. +# This program is released under the GNU General Public License, v2. + +# $Id$ + +# Get command line and configuration +$page = $ARGV[0]; + +if (open CONF, "<language.conf") +{ + $language = <CONF>; + chomp $language; + close CONF; +} +else +{ + $language = 'swedish'; +} + +# Check usage. +unless ($page) +{ + print "Usage: $0 page\n"; + print "Copies the page from the english/ directory to the $language/ directory\n"; + print "and adds the translation string\n"; + print "If the directory does not exist, it will be created, and the Makefile\n"; + print "copied.\n"; + print "You can either keep or not keep the 'english/' part of the path.\n"; + exit; +} + +# Check if valid source +unless ($page =~ /wml$/) +{ + print "$page does not seem to be a valid page.\n"; + exit; +} + +# Remove english/ from path +if ($page =~ m[^english/]) +{ + $page =~ s[^english/][]; +} + +# Create needed file and directory names +$srcfile = "english/$page"; # Source file path +$dstfile = "$language/$page"; # Destination file path + +$srcdir = $srcfile; +$srcdir =~ s[(.*/).*][$1]; # Source directory (trailing /) +$dstdir = $dstfile; +$dstdir =~ s[(.*/).*][$1]; # Desination directory (trailing /) + +$filename = $srcfile; +$filename =~ s[$srcdir][]; # Pathless filename + +$cvsfile = "$srcdir/CVS/Entries"; # Name of file with CVS revisions + +$srcmake = $srcdir . "Makefile"; # Name of source Makefile +$dstmake = $dstdir . "Makefile"; # Name of destination Makefile + +# Sanity checks +die "Directory $srcdir does not exist\n" unless -d $srcdir; +die "File $srcfile does not exist\n" unless -e $srcfile; + +# Check if destination exists, if not - create it +unless (-d $dstdir) +{ + print "Destination directory $dstdir does not exist,\n"; + print "creating and copying $dstmake\n"; + + mkdir $dstdir, 0755 + or die "Could not create $dstdir: $!\n"; + system "cp $srcmake $dstmake"; +} + +# Open the files +open CVS, $cvsfile + or die "Could not read $cvsfile ($!)\n"; + +open SRC, $srcfile + or die "Could not read $srcfile ($!)\n"; + +open DST, ">$dstfile" + or die "Could not create $dstfile ($!)\n"; + +# Retrieve CVS revision number +while (<CVS>) +{ + if (m[^/$filename/([0-9]*\.[0-9])*/]o) + { + $revision = $1; + } +} + +close CVS; + +print "Could not get revision number\n" unless $revision; + +# Copy the file and insert the revision number +$insertedrevision = 0; + +while (<SRC>) +{ + unless ($insertedrevision || /^#/) + { + print DST "# <!--translation $revision-->\n"; + $insertedrevision = 1; + } + print DST $_; +} + +close SRC; +close DST; + +# We're done +print "Copying done, remember to edit $dstfile\n"; |