[Originally posted by exiftool on 2007-09-22 13:39:38-07]I assume you have a utility that will do the german-to-english
translation? Using the command line utility for this purpose
wouldn't be ideal because each keyword in the list should be
written individually. But it is fairly easy to do exactly what you
want with a bit of Perl scripting. The following script will do
this to the XMP:Subject and XMP:Title tags:
#!/usr/bin/perl -w
BEGIN {
my $exeDir = ($0 =~ /(.*)[\\\/]/) ? $1 : '.';
unshift @INC, "$exeDir/lib";
}
use Image::ExifTool qw{:Public};
my $file = shift or die "Usage: SCRIPTNAME FILE\n";
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo($file, 'XMP:Subject', 'XMP:Title');
my $tag;
foreach $tag (keys %$info) {
my @vals = $exifTool->GetValue($tag);
my $writeTag = $exifTool->GetGroup($tag) . ':' . GetTagName($tag);
my $val;
foreach $val (@vals) {
my $translated = `translate_to_english "$val"`;
chomp $translated;
if (length $translated) {
print "$tag: $val -> $translated\n";
} else {
print "$tag: $val -> NOT TRANSLATED\n";
next;
}
$exifTool->SetNewValue($writeTag, $translated);
}
}
my $success = $exifTool->WriteInfo($file);
foreach $tag ('Warning', 'Error') {
my $val = $exifTool->GetValue($tag);
print "$tag: $val\n" if $val;
}
if ($success == 2) {
print "Nothing changed\n";
} elsif ($success == 1) {
print "File updated OK\n";
} else {
print "An error occurred\n";
}
# end
Of course, you will have to insert the name of your translation
routine instead of "traslate_to_english" here.
- Phil