2
######################################################################
3
## This program is copyright (c) 1999 Bruce Ravel
4
## <ravel@phys.washington.edu>
5
## http://feff.phys.washington.edu/~ravel/software/atoms/
7
## -------------------------------------------------------------------
8
## All rights reserved. This program is free software; you can
9
## redistribute it and/or modify it under the same terms as Perl
12
## This program is distributed in the hope that it will be useful,
13
## but WITHOUT ANY WARRANTY; without even the implied warranty of
14
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
## Artistic License for more details.
16
## -------------------------------------------------------------------
17
######################################################################
18
## Time-stamp: <99/04/20 22:00:15 bruce>
19
######################################################################
20
## This program generates the language files used in Atoms and TkAtoms
21
## from database files. The database files are flat text. Record are
22
## separated by newlines, fields are separated by vertical bar (|) and
23
## newlines in fields are represented by control-K. The fields are:
24
## hash-key | english | spanish | french
25
## More fields can be added.
27
## There are several database files -- I broke all the language data
28
## up into managable pieces. All the data gets written to a single
29
## (tk)atomsrc.?? file -- one for each language.
30
######################################################################
33
##use strict; # use strict doesn't seem to play well
34
##no strict qw/refs/; # with all the eval's I use
40
my $cvs_info = '$Id: language.PL,v 1.9 2000/03/30 08:11:11 bruce Exp $ ';
41
my $cvs_version = (split(' ', $cvs_info))[2] || "pre_release";
42
my $thisdir = &identify_self;
45
"Language file generation tool version $cvs_version for Atoms3.0beta9", $/;
47
## the anon array contains the file extension and the index of the
48
## language in the database files
49
my %lingos = ("english" => ["en", 1],
50
"spanish" => ["sp", 2],
51
"french" => ["fr", 3],
52
"german" => ["ge", 4],
54
my $sep = '\|'; # field separator in database files
55
#gaby# my $sep = ';'; # field separator in database files
56
my $nl = "\013"; #''; # newline token (control-K, ascii 13)
57
my @hashes = ("labels", "dialogs", "help", "file-dialog", "sgb",
58
"messages", "config");
59
my %written; # this is a counter
61
my $header; # read the tkatomsrc header from __DATA__
62
$header = '# -*- mode: cperl -*-';
63
$header .= "$/# Language file generation tool, version $cvs_version$/";
69
## open a file for each language and write out the header
70
foreach my $lang (keys %lingos) {
71
my $ext = $lingos{$lang}->[0];
72
my $file = "tkatomsrc." . $ext;
73
#$file = File::Spec -> catfile($thisdir, 'language', $file);
74
$file = File::Spec -> catfile($thisdir, $file);
75
$fh{$ext} = IO::File -> new();
77
open ($fh, ">$file") or die "Failed to open $file for writing: $!";
81
## open each database file and parcel out each language's entries into
82
## a hash named for the language. The purpose of the eval's is to
83
## construct names of hashes on the fly. This allows me to not know
84
## in advance what languages are in the data files. (Well, that is
85
## not strictly true -- I have to maintain %lingos by hand.)
86
print STDOUT " Reading language data for TkAtoms", $/;
87
foreach my $hash (@hashes) {
88
my $file = $hash . ".dat";
89
#gaby# my $file = "table." . $hash;
90
#$file = File::Spec -> catfile($thisdir, 'language', $file);
91
$file = File::Spec -> catfile($thisdir, $file);
92
open DAT, "$file" or die $!;
95
my @line = split($sep, $_);
97
foreach my $i (0 .. $#line) { # clean up white space at ends
98
$line[$i] =~ s/^\s+//; # of words and convert the ^K
99
$line[$i] =~ s|$nl|$/|g; # characters to $/
100
$line[$i] =~ s/\s+$//;
102
foreach my $lang (keys %lingos) { # load up hashes for each language
103
my $index = $lingos{$lang}->[1];
104
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
109
## now dump the hashes to their appropriate data files using
110
## Data::Dumper. This, too, requires the use of eval's.
111
foreach my $lang (keys %lingos) {
112
my $ext = $lingos{$lang}->[0];
113
unless ($written{$lang}) {
115
printf STDOUT " Writing %-7s file : %15s$/", $lang, "tkatomsrc.$ext";
118
eval "\$ref = \\\%$lang;"; # dump each hash to each language file
119
my $hash_dump = Data::Dumper->Dump([$ref], [$hash]);
120
eval "undef \%$lang";
123
## having to change file_dialog to file-dialog was an unfortunate
124
## aspect of switching to Gaby for managing these databases
125
$hash_dump =~ s/file-dialog/file_dialog/g;
126
print $fh $hash_dump, $/;
130
foreach my $lang (keys %lingos) { # close 'em up
131
my $ext = $lingos{$lang}->[0];
133
print $fh $/, "1;", $/;
137
####################################################################
138
## now write out the atomsrc.?? files. The procedure is the same as
141
## open a file for each language and write out the header
142
foreach my $lang (keys %lingos) {
143
my $ext = $lingos{$lang}->[0];
144
my $file = "atomsrc." . $ext;
145
#$file = File::Spec -> catfile($thisdir, 'language', $file);
146
$file = File::Spec -> catfile($thisdir, $file);
148
open $fh, ">$file" or die $!;
152
print STDOUT " Reading language data for Atoms", $/;
153
my $file = "messages.dat";
154
#gaby# my $file = "table.messages";
155
#$file = File::Spec -> catfile($thisdir, 'language', $file);
156
$file = File::Spec -> catfile($thisdir, $file);
157
open DAT, "$file" or die $!;
160
my @line = split($sep, $_);
162
foreach my $i (0 .. $#line) { # clean up white space at ends
163
$line[$i] =~ s/^\s+//; # of words and convert the ^K
164
$line[$i] =~ s|$nl|$/|g; # characters to $/
165
$line[$i] =~ s/\s+$//;
166
$line[$i] =~ s/\"/\"/;
167
#gaby# $line[$i] =~ s/\n$//;
169
foreach my $lang (keys %lingos) {
170
my $index = $lingos{$lang}->[1];
171
eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
177
foreach my $lang (keys %lingos) {
178
my $ext = $lingos{$lang}->[0];
179
unless ($written{$lang}) {
181
printf STDOUT " Writing %-7s file : %15s$/", $lang, "atomsrc.$ext";
184
eval "\$ref = \\\%$lang;";
185
my $hash_dump = Data::Dumper->Dump([$ref], [qw/messages/]);
186
eval "undef \%$lang";
189
print $fh $hash_dump, $/;
192
foreach my $lang (keys %lingos) {
193
my $ext = $lingos{$lang}->[0];
195
print $fh $/, "1;", $/;
202
use File::Basename qw(dirname);
203
return dirname($caller[1]);
209
######################################################################
210
## Atoms language configuration file
211
## copyright (c) 1999 Bruce Ravel
212
## ravel@phys.washington.edu
213
## http://feff.phys.washington.edu/~ravel/
215
## The latest version of Atoms can always be found at
216
## http://feff.phys.washington.edu/~ravel/software/atoms/
218
## -------------------------------------------------------------------
219
## All rights reserved. This program is free software; you can
220
## redistribute it and/or modify it under the same terms as Perl
223
## This program is distributed in the hope that it will be useful,
224
## but WITHOUT ANY WARRANTY; without even the implied warranty of
225
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
226
## Artistic License for more details.
227
## -------------------------------------------------------------------
228
######################################################################
230
## This is a language configuration file for atoms or for tkatoms.
231
## This file is read after atoms starts running. The contents of this
232
## file are used to fill in labels on the screen, messages in help
233
## balloons, and other uses of text in the programs.
235
## To make another language file, copy this file to "(tk)atomsrc.??"
236
## where ?? is a two letter symbol for your language. Translate all
237
## of the hash values (but NOT the keys) and add an entry to the
238
## %languages hash in Atoms.pm for the new language. And please send
239
## your translation to Bruce Ravel <ravel@phys.washingon.edu> so he
240
## can include it with future distributions of Atoms.
248
## Here is an example from the "help" hash. Pardon my crappy language
249
## skills. Note that the key doesn't get translated, only the value --
250
## that is very important!
254
## "Add one more site to the list of unique crystallographic sites",
258
## "Ponga un otro sitio en la lista de sitios crystalograficos",
261
## "Placez une autre site au liste des uniques sites cristalographiques",
262
####################################################################