1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
#!/usr/bin/perl -w
######################################################################
## This program is copyright (c) 1999 Bruce Ravel
## <ravel@phys.washington.edu>
## http://feff.phys.washington.edu/~ravel/software/atoms/
##
## -------------------------------------------------------------------
## All rights reserved. This program is free software; you can
## redistribute it and/or modify it under the same terms as Perl
## itself.
##
## This program 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
## Artistic License for more details.
## -------------------------------------------------------------------
######################################################################
## Time-stamp: <99/04/20 22:00:15 bruce>
######################################################################
## This program generates the language files used in Atoms and TkAtoms
## from database files. The database files are flat text. Record are
## separated by newlines, fields are separated by vertical bar (|) and
## newlines in fields are represented by control-K. The fields are:
## hash-key | english | spanish | french
## More fields can be added.
##
## There are several database files -- I broke all the language data
## up into managable pieces. All the data gets written to a single
## (tk)atomsrc.?? file -- one for each language.
######################################################################
## Code:
##use strict; # use strict doesn't seem to play well
##no strict qw/refs/; # with all the eval's I use
use Data::Dumper;
use File::Spec;
use IO::File;
#use diagnostics;
my $cvs_info = '$Id: language.PL,v 1.9 2000/03/30 08:11:11 bruce Exp $ ';
my $cvs_version = (split(' ', $cvs_info))[2] || "pre_release";
my $thisdir = &identify_self;
print STDOUT
"Language file generation tool version $cvs_version for Atoms3.0beta9", $/;
## the anon array contains the file extension and the index of the
## language in the database files
my %lingos = ("english" => ["en", 1],
"spanish" => ["sp", 2],
"french" => ["fr", 3],
"german" => ["ge", 4],
);
my $sep = '\|'; # field separator in database files
#gaby# my $sep = ';'; # field separator in database files
my $nl = "\013"; #''; # newline token (control-K, ascii 13)
my @hashes = ("labels", "dialogs", "help", "file-dialog", "sgb",
"messages", "config");
my %written; # this is a counter
my $header; # read the tkatomsrc header from __DATA__
$header = '# -*- mode: cperl -*-';
$header .= "$/# Language file generation tool, version $cvs_version$/";
while (<DATA>) {
$header .= $_;
};
my %fh = ();
## open a file for each language and write out the header
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
my $file = "tkatomsrc." . $ext;
#$file = File::Spec -> catfile($thisdir, 'language', $file);
$file = File::Spec -> catfile($thisdir, $file);
$fh{$ext} = IO::File -> new();
my $fh = $fh{$ext};
open ($fh, ">$file") or die "Failed to open $file for writing: $!";
print $fh $header;
};
## open each database file and parcel out each language's entries into
## a hash named for the language. The purpose of the eval's is to
## construct names of hashes on the fly. This allows me to not know
## in advance what languages are in the data files. (Well, that is
## not strictly true -- I have to maintain %lingos by hand.)
print STDOUT " Reading language data for TkAtoms", $/;
foreach my $hash (@hashes) {
my $file = $hash . ".dat";
#gaby# my $file = "table." . $hash;
#$file = File::Spec -> catfile($thisdir, 'language', $file);
$file = File::Spec -> catfile($thisdir, $file);
open DAT, "$file" or die $!;
while (<DAT>) {
next if /^\s*$/;
my @line = split($sep, $_);
#gaby# shift @line;
foreach my $i (0 .. $#line) { # clean up white space at ends
$line[$i] =~ s/^\s+//; # of words and convert the ^K
$line[$i] =~ s|$nl|$/|g; # characters to $/
$line[$i] =~ s/\s+$//;
};
foreach my $lang (keys %lingos) { # load up hashes for each language
my $index = $lingos{$lang}->[1];
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
};
};
close DAT;
## now dump the hashes to their appropriate data files using
## Data::Dumper. This, too, requires the use of eval's.
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
unless ($written{$lang}) {
++$written{$lang};
printf STDOUT " Writing %-7s file : %15s$/", $lang, "tkatomsrc.$ext";
};
my $ref;
eval "\$ref = \\\%$lang;"; # dump each hash to each language file
my $hash_dump = Data::Dumper->Dump([$ref], [$hash]);
eval "undef \%$lang";
undef $ref;
my $fh = $fh{$ext};
## having to change file_dialog to file-dialog was an unfortunate
## aspect of switching to Gaby for managing these databases
$hash_dump =~ s/file-dialog/file_dialog/g;
print $fh $hash_dump, $/;
};
};
foreach my $lang (keys %lingos) { # close 'em up
my $ext = $lingos{$lang}->[0];
my $fh = $fh{$ext};
print $fh $/, "1;", $/;
close $fh;
};
####################################################################
## now write out the atomsrc.?? files. The procedure is the same as
## above.
## open a file for each language and write out the header
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
my $file = "atomsrc." . $ext;
#$file = File::Spec -> catfile($thisdir, 'language', $file);
$file = File::Spec -> catfile($thisdir, $file);
my $fh = $fh{$ext};
open $fh, ">$file" or die $!;
print $fh $header;
};
print STDOUT " Reading language data for Atoms", $/;
my $file = "messages.dat";
#gaby# my $file = "table.messages";
#$file = File::Spec -> catfile($thisdir, 'language', $file);
$file = File::Spec -> catfile($thisdir, $file);
open DAT, "$file" or die $!;
while (<DAT>) {
next if /^\s*$/;
my @line = split($sep, $_);
#gaby# shift @line;
foreach my $i (0 .. $#line) { # clean up white space at ends
$line[$i] =~ s/^\s+//; # of words and convert the ^K
$line[$i] =~ s|$nl|$/|g; # characters to $/
$line[$i] =~ s/\s+$//;
$line[$i] =~ s/\"/\"/;
#gaby# $line[$i] =~ s/\n$//;
};
foreach my $lang (keys %lingos) {
my $index = $lingos{$lang}->[1];
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
};
};
close DAT;
%written = ();
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
unless ($written{$lang}) {
++$written{$lang};
printf STDOUT " Writing %-7s file : %15s$/", $lang, "atomsrc.$ext";
};
my $ref;
eval "\$ref = \\\%$lang;";
my $hash_dump = Data::Dumper->Dump([$ref], [qw/messages/]);
eval "undef \%$lang";
undef $ref;
my $fh = $fh{$ext};
print $fh $hash_dump, $/;
};
foreach my $lang (keys %lingos) {
my $ext = $lingos{$lang}->[0];
my $fh = $fh{$ext};
print $fh $/, "1;", $/;
close $fh;
};
sub identify_self {
my @caller = caller;
use File::Basename qw(dirname);
return dirname($caller[1]);
};
__DATA__
######################################################################
## Atoms language configuration file
## copyright (c) 1999 Bruce Ravel
## ravel@phys.washington.edu
## http://feff.phys.washington.edu/~ravel/
##
## The latest version of Atoms can always be found at
## http://feff.phys.washington.edu/~ravel/software/atoms/
##
## -------------------------------------------------------------------
## All rights reserved. This program is free software; you can
## redistribute it and/or modify it under the same terms as Perl
## itself.
##
## This program 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
## Artistic License for more details.
## -------------------------------------------------------------------
######################################################################
##
## This is a language configuration file for atoms or for tkatoms.
## This file is read after atoms starts running. The contents of this
## file are used to fill in labels on the screen, messages in help
## balloons, and other uses of text in the programs.
##
## To make another language file, copy this file to "(tk)atomsrc.??"
## where ?? is a two letter symbol for your language. Translate all
## of the hash values (but NOT the keys) and add an entry to the
## %languages hash in Atoms.pm for the new language. And please send
## your translation to Bruce Ravel <ravel@phys.washingon.edu> so he
## can include it with future distributions of Atoms.
##
## Some languages:
## en = English
## fr = French
## sp = Spanish
## and so on...
##
## Here is an example from the "help" hash. Pardon my crappy language
## skills. Note that the key doesn't get translated, only the value --
## that is very important!
##
## English:
## 'add' =>
## "Add one more site to the list of unique crystallographic sites",
##
## Spanish:
## 'add' =>
## "Ponga un otro sitio en la lista de sitios crystalograficos",
##
## French: 'add' =>
## "Placez une autre site au liste des uniques sites cristalographiques",
####################################################################
## code:
|