| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use Data::Dumper; |
| 4 |
use File::Spec; |
| 5 |
use IO::File; |
| 6 |
#use diagnostics; |
| 7 |
|
| 8 |
my $cvs_info = '$Id: language.PL,v 1.1 2000/04/02 20:52:56 bruce Exp $ '; |
| 9 |
my $cvs_version = (split(' ', $cvs_info))[2] || "pre_release"; |
| 10 |
my $thisdir = &identify_self; |
| 11 |
|
| 12 |
print STDOUT |
| 13 |
"Xtal.pm language generation tool version $cvs_version for Xray::Xtal 0.30", |
| 14 |
$/; |
| 15 |
|
| 16 |
## the anon array contains the file extension and the index of the |
| 17 |
## language in the database files |
| 18 |
my %lingos = ("english" => ["en", 1], |
| 19 |
"spanish" => ["sp", 2], |
| 20 |
"french" => ["fr", 3], |
| 21 |
"german" => ["ge", 4], |
| 22 |
); |
| 23 |
my $sep = '\|'; # field separator in database files |
| 24 |
#gaby# my $sep = ';'; # field separator in database files |
| 25 |
my $nl = "\013"; #''; # newline token (control-K, ascii 13) |
| 26 |
|
| 27 |
my $header; # read the tkatomsrc header from __DATA__ |
| 28 |
$header = '# -*- mode: cperl -*-'; |
| 29 |
$header .= "$/# Xtal.pm language file generation tool, version $cvs_version$/"; |
| 30 |
while (<DATA>) { |
| 31 |
$header .= $_; |
| 32 |
}; |
| 33 |
|
| 34 |
my %fh = (); |
| 35 |
## open a file for each language and write out the header |
| 36 |
foreach my $lang (keys %lingos) { |
| 37 |
my $ext = $lingos{$lang}->[0]; |
| 38 |
my $file = "xtalrc." . $ext; |
| 39 |
$file = File::Spec -> catfile($thisdir, $file); |
| 40 |
$fh{$ext} = IO::File -> new(); |
| 41 |
my $fh = $fh{$ext}; |
| 42 |
open $fh, ">$file" or die $!; |
| 43 |
print $fh $header; |
| 44 |
}; |
| 45 |
print STDOUT " Reading language data for Xtal", $/; |
| 46 |
my $file = "xtal.dat"; |
| 47 |
#gaby# my $file = "table.xtal"; |
| 48 |
$file = File::Spec -> catfile($thisdir, $file); |
| 49 |
open DAT, "$file" or die $!; |
| 50 |
while (<DAT>) { |
| 51 |
next if /^\s*$/; |
| 52 |
my @line = split($sep, $_); |
| 53 |
#gaby# shift @line; |
| 54 |
foreach my $i (0 .. $#line) { # clean up white space at ends |
| 55 |
$line[$i] =~ s/^\s+//; # of words and convert the ^K |
| 56 |
$line[$i] =~ s|$nl|$/|g; # characters to $/ |
| 57 |
$line[$i] =~ s/\s+$//; |
| 58 |
$line[$i] =~ s/\"/\"/; |
| 59 |
#gaby# $line[$i] =~ s/\n$//; |
| 60 |
}; |
| 61 |
foreach my $lang (keys %lingos) { |
| 62 |
my $index = $lingos{$lang}->[1]; |
| 63 |
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";"; |
| 64 |
}; |
| 65 |
}; |
| 66 |
close DAT; |
| 67 |
|
| 68 |
%written = (); |
| 69 |
foreach my $lang (keys %lingos) { |
| 70 |
my $ext = $lingos{$lang}->[0]; |
| 71 |
unless ($written{$lang}) { |
| 72 |
++$written{$lang}; |
| 73 |
printf STDOUT " Writing %-7s file : %15s$/", $lang, "xtalrc.$ext"; |
| 74 |
}; |
| 75 |
my $ref; |
| 76 |
eval "\$ref = \\\%$lang;"; |
| 77 |
my $hash_dump = Data::Dumper->Dump([$ref], [qw/Xray::Xtal::strings/]); |
| 78 |
eval "undef \%$lang"; |
| 79 |
undef $ref; |
| 80 |
my $fh = $fh{$ext}; |
| 81 |
print $fh $hash_dump, $/; |
| 82 |
}; |
| 83 |
|
| 84 |
foreach my $lang (keys %lingos) { |
| 85 |
my $ext = $lingos{$lang}->[0]; |
| 86 |
my $fh = $fh{$ext}; |
| 87 |
print $fh $/, "1;", $/; |
| 88 |
close $fh; |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
sub identify_self { |
| 94 |
my @caller = caller; |
| 95 |
use File::Basename qw(dirname); |
| 96 |
return dirname($caller[1]); |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
__DATA__ |
| 101 |
|
| 102 |
###################################################################### |
| 103 |
## Xtal.pm language configuration file |
| 104 |
## copyright (c) 2000 Bruce Ravel |
| 105 |
## [email protected] |
| 106 |
## http://feff.phys.washington.edu/~ravel/ |
| 107 |
## |
| 108 |
## The latest version of Atoms can always be found at |
| 109 |
## http://feff.phys.washington.edu/~ravel/software/atoms/ |
| 110 |
## |
| 111 |
## ------------------------------------------------------------------- |
| 112 |
## All rights reserved. This program is free software; you can |
| 113 |
## redistribute it and/or modify it under the same terms as Perl |
| 114 |
## itself. |
| 115 |
## |
| 116 |
## This program is distributed in the hope that it will be useful, |
| 117 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 118 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 119 |
## Artistic License for more details. |
| 120 |
## ------------------------------------------------------------------- |
| 121 |
###################################################################### |
| 122 |
## |
| 123 |
## This is a language configuration file for Xtal.pm. This file is |
| 124 |
## read after atoms starts running. The contents of this file are |
| 125 |
## used is messages generated by Xtal.pm. |
| 126 |
## |
| 127 |
## To make another language file, copy this file to "xtalrc.??" where |
| 128 |
## ?? is a two letter symbol for your language. Translate all of the |
| 129 |
## hash values (but NOT the keys) and add an entry to the %languages |
| 130 |
## hash in the language file for the new language. And please send |
| 131 |
## your translation to Bruce Ravel <[email protected]> so he |
| 132 |
## can include it with future distributions of Atoms. |
| 133 |
## |
| 134 |
## Some languages: |
| 135 |
## en = English |
| 136 |
## fr = French |
| 137 |
## sp = Spanish |
| 138 |
## and so on... |
| 139 |
## |
| 140 |
## Here is an example. Pardon my crappy language skills. Note that |
| 141 |
## the key doesn't get translated, only the value -- that is very |
| 142 |
## important! |
| 143 |
## |
| 144 |
## English: |
| 145 |
## 'not_a_group' => |
| 146 |
## 'You have specified an unknown space group symbol.', |
| 147 |
## |
| 148 |
## Spanish: |
| 149 |
## 'not_a_group' => |
| 150 |
## 'Ud ha specificado un grupo de simetria inconecido.' |
| 151 |
## |
| 152 |
## French: |
| 153 |
## 'not_a_group' => |
| 154 |
## 'Vous avez specifie une groupe de symmetrie inconnu.' |
| 155 |
#################################################################### |
| 156 |
## code: |