#!/usr/bin/perl -w -I/opt/eprints2/perl_lib ###################################################################### # # This script is provided without warrently in the hope it will be # useful. It is *not* part of the offical GNU EPrints pacakge. # (c)2002 University of Southampton # ###################################################################### =pod =head1 NAME B - Assist the updating of a translated XML phrase file. =head1 SYNOPSIS B I I I I =head1 DESCRIPTION This tool is to assist people who translated version A of a eprints phrase file and want to apply all the changes made between version A & B to their translation. This script outputs to stdout a XML phrase file based on I but with comments put in near phrases which have changed between I and I. Phrases which have been added are added in english to the file (with a comment). This is a pretty rough and dirty script. It needs to know the location of the archive config dir (eg. /opt/eprints2/archives/foo/cfg/) to find the DTD. You will need to clean up the comment at the top of the file (it will claim to be in english), and edit the DTD link in the XML header by hand. Mail support@eprints.org if this makes no sense. =cut use EPrints::XML; use strict; use Getopt::Long; use Pod::Usage; my $version = 0; my $verbose = 0; my $quiet = 0; my $help = 0; my $man = 0; GetOptions( 'help|?' => \$help, 'man' => \$man, 'version' => \$version, 'verbose+' => \$verbose, 'silent' => \$quiet, 'quiet' => \$quiet ) || pod2usage( 2 ); EPrints::Utils::cmd_version( "update_phrase_file" ) if $version; pod2usage( 1 ) if $help; pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; pod2usage( 2 ) if( scalar @ARGV != 4 ); my $noise = 1; $noise = 0 if( $quiet ); $noise = 1+$verbose if( $verbose ); # Set STDOUT to auto flush (without needing a \n) $|=1; my $old_phr_en = EPrints::XML::parse_xml( $ARGV[1], $ARGV[0], 1); my $new_phr_en = EPrints::XML::parse_xml( $ARGV[2], $ARGV[0], 1); my $old_phr_other = EPrints::XML::parse_xml( $ARGV[3], $ARGV[0], 1); my $phrases; my $old_phr_en_phrases = {}; $phrases = ( $old_phr_en->getElementsByTagName( "phrases" ) )[0]; foreach my $node ( $phrases->getChildNodes ) { next unless( EPrints::XML::is_dom( $node, "Element" ) ); my $ref= $node->getAttribute( "ref" ); $old_phr_en_phrases->{$ref} = $node; } my $old_phr_other_phrases = {}; $phrases = ( $old_phr_other->getElementsByTagName( "phrases" ) )[0]; foreach my $node ( $phrases->getChildNodes ) { next unless( EPrints::XML::is_dom( $node, "Element" ) ); my $ref= $node->getAttribute( "ref" ); $old_phr_other_phrases->{$ref} = $node; } $phrases = ( $new_phr_en->getElementsByTagName( "phrases" ) )[0]; foreach my $node ( $phrases->getChildNodes ) { next unless( EPrints::XML::is_dom( $node, "Element" ) ); my $ref= $node->getAttribute( "ref" ); print $ref." "; if( !defined $old_phr_en_phrases->{$ref} ) { my $c1 = $new_phr_en->createComment( " TRANSLATE $ref (New) " ); $phrases->insertBefore( $c1, $node ); $phrases->insertBefore( $new_phr_en->createTextNode( "\n" ), $node ); print "NEW"; } elsif( $node->toString eq $old_phr_en_phrases->{$ref}->toString ) { my $forign = EPrints::XML::clone_and_own( $old_phr_other_phrases->{$ref}, $new_phr_en, 1 ); print "same"; $phrases->replaceChild( $forign, $node ); } else { my @c = (); push @c, "\nTRANSLATE $ref (Changed)\nOLD ENGLISH: "; foreach( $old_phr_en_phrases->{$ref}->getChildNodes ) { push @c, $_->toString; } push @c, "\nOLD TRANSLATION: "; foreach( $old_phr_other_phrases->{$ref}->getChildNodes ) { push @c, $_->toString; } push @c, "\n"; my $c1 = $new_phr_en->createComment( join( "", @c ) ); $phrases->insertBefore( $c1, $node ); $phrases->insertBefore( $new_phr_en->createTextNode( "\n" ), $node ); print "DIFF"; } print "\n"; } print $new_phr_en->toString; exit;