Prepare for git repository
[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 strict;
20  
21 use DXVars;
22 use DXDebug;
23
24 my $localfn = "$main::root/local/Messages";
25 my $fn = "$main::root/perl/Messages";
26
27 use vars qw(%msgs);
28
29 sub msg
30 {
31         my $lang = shift;
32         my $m = shift;
33         my $ref = $msgs{$lang};
34         my $s = $ref->{$m} if $ref;
35         if (!$s && $lang ne 'en') {
36                 $ref = $msgs{'en'};
37                 $s = $ref->{$m};
38         }
39         return "unknown message '$m' in lang '$lang'" if !defined $s;
40         my $ans = eval qq{ "$s" };
41         warn $@ if $@;
42         return $ans;
43 }
44
45 sub load
46 {
47         my $ref = shift;
48         if (-e $localfn) {
49                 do $localfn;
50                 return ($@) if $@ && ref $ref;
51                 confess $@ if $@;
52                 return ();
53         }
54         do $fn;
55         return ($@) if $@ && ref $ref;
56         confess $@ if $@;
57         return ();
58 }
59
60 sub init
61 {
62         load();
63 }
64
65 1;