fe1bca7db2af02b5e4c41bb8136c0fbe191108f3
[spider.git] / perl / DXM.pm
1 #
2 # DX cluster message strings for output
3 #
4 # Each message string will substitute $_[x] positionally. What this means is
5 # that if you don't like the order in which fields in each message is output then 
6 # you can change it. Also you can include various globally accessible variables
7 # in the string if you want. 
8 #
9 # Largely because I don't particularly want to have to change all these messages
10 # in every upgrade I shall attempt to add new field to the END of the list :-)
11 #
12 # Copyright (c) 1998 - Dirk Koopman G1TLH
13 #
14 # $Id$
15 #
16
17 package DXM;
18
19 use DXVars;
20 use DXDebug;
21
22 my $localfn = "$main::root/local/Messages";
23 my $fn = "$main::root/perl/Messages";
24
25 sub msg
26 {
27         my $lang = shift;
28         my $m = shift;
29         my $ref = $msgs{$lang};
30         my $s = $ref->{$m} if $ref;
31         if (!$s && $lang ne 'en') {
32                 $ref = $msgs{'en'};
33                 $s = $ref->{$m};
34         }
35         return "unknown message '$m' in lang '$lang'" if !defined $s;
36         my $ans = eval qq{ "$s" };
37         warn $@ if $@;
38         return $ans;
39 }
40
41 sub load
42 {
43         my $ref = shift;
44         if (-e $localfn) {
45                 do $localfn;
46                 return ($@) if $@ && ref $ref;
47                 confess $@ if $@;
48                 return ();
49         }
50         do $fn;
51         return ($@) if $@ && ref $ref;
52         confess $@ if $@;
53         return ();
54 }
55
56 sub init
57 {
58         load();
59 }