~ubuntu-branches/ubuntu/vivid/horae/vivid

« back to all changes in this revision

Viewing changes to language/language.script

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2006-12-26 11:54:29 UTC
  • Revision ID: james.westby@ubuntu.com-20061226115429-kjuhf6h9w6bohlwj
Tags: upstream-063
ImportĀ upstreamĀ versionĀ 063

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
######################################################################
 
3
##  This program is copyright (c) 1999 Bruce Ravel
 
4
##  <ravel@phys.washington.edu>
 
5
##  http://feff.phys.washington.edu/~ravel/software/atoms/
 
6
##
 
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
 
10
##     itself.
 
11
##
 
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.
 
26
##
 
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
######################################################################
 
31
## Code:
 
32
 
 
33
##use strict;                   # use strict doesn't seem to play well
 
34
##no strict qw/refs/;           # with all the eval's I use
 
35
use Data::Dumper;
 
36
use File::Spec;
 
37
use IO::File;
 
38
#use diagnostics;
 
39
 
 
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;
 
43
 
 
44
print STDOUT
 
45
  "Language file generation tool version $cvs_version for Atoms3.0beta9", $/;
 
46
 
 
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],
 
53
             );
 
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
 
60
 
 
61
my $header;                     # read the tkatomsrc header from __DATA__
 
62
$header  = '# -*- mode: cperl -*-';
 
63
$header .= "$/# Language file generation tool, version $cvs_version$/";
 
64
while (<DATA>) {
 
65
  $header .= $_;
 
66
};
 
67
 
 
68
my %fh = ();
 
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();
 
76
  my $fh = $fh{$ext};
 
77
  open ($fh, ">$file") or die "Failed to open $file for writing: $!";
 
78
  print $fh $header;
 
79
};
 
80
 
 
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 $!;
 
93
  while (<DAT>) {
 
94
    next if /^\s*$/;
 
95
    my @line = split($sep, $_);
 
96
    #gaby# shift @line;
 
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+$//;
 
101
    };
 
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]\";";
 
105
    };
 
106
  };
 
107
  close DAT;
 
108
 
 
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}) {
 
114
      ++$written{$lang};
 
115
      printf STDOUT "    Writing %-7s file : %15s$/", $lang, "tkatomsrc.$ext";
 
116
    };
 
117
    my $ref;
 
118
    eval "\$ref = \\\%$lang;";  # dump each hash to each language file
 
119
    my $hash_dump = Data::Dumper->Dump([$ref], [$hash]);
 
120
    eval "undef \%$lang";
 
121
    undef $ref;
 
122
    my $fh = $fh{$ext};
 
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, $/;
 
127
  };
 
128
};
 
129
 
 
130
foreach my $lang (keys %lingos) { # close 'em up
 
131
  my $ext = $lingos{$lang}->[0];
 
132
  my $fh = $fh{$ext};
 
133
  print $fh $/, "1;", $/;
 
134
  close $fh;
 
135
};
 
136
 
 
137
####################################################################
 
138
## now write out the atomsrc.?? files.  The procedure is the same as
 
139
## above.
 
140
 
 
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);
 
147
  my $fh = $fh{$ext};
 
148
  open $fh, ">$file" or die $!;
 
149
  print $fh $header;
 
150
};
 
151
 
 
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 $!;
 
158
while (<DAT>) {
 
159
  next if /^\s*$/;
 
160
  my @line = split($sep, $_);
 
161
  #gaby# shift @line;
 
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$//;
 
168
  };
 
169
  foreach my $lang (keys %lingos) {
 
170
    my $index = $lingos{$lang}->[1];
 
171
    eval "\$$lang\{\'$line[0]\'\} = \"$line[$index]\";";
 
172
  };
 
173
};
 
174
close DAT;
 
175
 
 
176
%written = ();
 
177
foreach my $lang (keys %lingos) {
 
178
  my $ext = $lingos{$lang}->[0];
 
179
  unless ($written{$lang}) {
 
180
    ++$written{$lang};
 
181
    printf STDOUT "    Writing %-7s file : %15s$/", $lang, "atomsrc.$ext";
 
182
  };
 
183
  my $ref;
 
184
  eval "\$ref = \\\%$lang;";
 
185
  my $hash_dump = Data::Dumper->Dump([$ref], [qw/messages/]);
 
186
  eval "undef \%$lang";
 
187
  undef $ref;
 
188
  my $fh = $fh{$ext};
 
189
  print $fh $hash_dump, $/;
 
190
};
 
191
 
 
192
foreach my $lang (keys %lingos) {
 
193
  my $ext = $lingos{$lang}->[0];
 
194
  my $fh = $fh{$ext};
 
195
  print $fh $/, "1;", $/;
 
196
  close $fh;
 
197
};
 
198
 
 
199
 
 
200
sub identify_self {
 
201
  my @caller = caller;
 
202
  use File::Basename qw(dirname);
 
203
  return dirname($caller[1]);
 
204
};
 
205
 
 
206
 
 
207
__DATA__
 
208
 
 
209
######################################################################
 
210
## Atoms language configuration file
 
211
##                                     copyright (c) 1999 Bruce Ravel
 
212
##                                          ravel@phys.washington.edu
 
213
##                            http://feff.phys.washington.edu/~ravel/
 
214
##
 
215
##        The latest version of Atoms can always be found at
 
216
##      http://feff.phys.washington.edu/~ravel/software/atoms/
 
217
##
 
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
 
221
##     itself.
 
222
##
 
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
######################################################################
 
229
##
 
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.
 
234
##
 
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.
 
241
##
 
242
## Some languages:
 
243
##   en = English
 
244
##   fr = French
 
245
##   sp = Spanish
 
246
## and so on...
 
247
##
 
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!
 
251
##
 
252
## English:
 
253
## 'add' =>
 
254
##  "Add one more site to the list of unique crystallographic sites",
 
255
##
 
256
## Spanish:
 
257
## 'add' =>
 
258
##  "Ponga un otro sitio en la lista de sitios crystalograficos",
 
259
##
 
260
## French: 'add' =>
 
261
##  "Placez une autre site au liste des uniques sites cristalographiques",
 
262
####################################################################
 
263
## code: