b6d191bbd30a03f1c019c8ae35303e226d3ed08a
[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($VERSION $BRANCH);
28 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
29 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
30 $main::build += $VERSION;
31 $main::branch += $BRANCH;
32
33 use vars qw(%msgs);
34
35 sub msg
36 {
37         my $lang = shift;
38         my $m = shift;
39         my $ref = $msgs{$lang};
40         my $s = $ref->{$m} if $ref;
41         if (!$s && $lang ne 'en') {
42                 $ref = $msgs{'en'};
43                 $s = $ref->{$m};
44         }
45         return "unknown message '$m' in lang '$lang'" if !defined $s;
46         my $ans = eval qq{ "$s" };
47         warn $@ if $@;
48         return $ans;
49 }
50
51 sub load
52 {
53         my $ref = shift;
54         if (-e $localfn) {
55                 do $localfn;
56                 return ($@) if $@ && ref $ref;
57                 confess $@ if $@;
58                 return ();
59         }
60         do $fn;
61         return ($@) if $@ && ref $ref;
62         confess $@ if $@;
63         return ();
64 }
65
66 sub init
67 {
68         load();
69 }
70
71 1;