added the hooks for internationalisation
[spider.git] / perl / DXM.pm
index e1579fabbd64d52cb25ea3cdb8b7be566460bb9c..5a3b22e3b086415804cde6ab1c317e9fae16bed8 100644 (file)
@@ -1,6 +1,14 @@
 #
 # DX cluster message strings for output
 #
+# Each message string will substitute $_[x] positionally. What this means is
+# that if you don't like the order in which fields in each message is output then 
+# you can change it. Also you can include various globally accessible variables
+# in the string if you want. 
+#
+# Largely because I don't particularly want to have to change all these messages
+# in every upgrade I shall attempt to add new field to the END of the list :-)
+#
 # Copyright (c) 1998 - Dirk Koopman G1TLH
 #
 # $Id$
 
 package DXM;
 
-require Exporter;
-@ISA = qw(Exporter);
-@EXPORT = qw(m);
+use DXVars;
+use Carp;
+
+my $localfn = "$main::root/local/Messages";
+my $fn = "$main::root/perl/Messages";
+
+sub msg
+{
+       my $lang = shift;
+       my $m = shift;
+       my $ref = $msgs{$lang};
+       my $s = $ref->{$m} if $ref;
+       return "unknown message '$m' in lang '$lang'" if !defined $s;
+       my $ans = eval qq{ "$s" };
+       confess $@ if $@;
+       return $ans;
+}
 
-%msgs = (
-  l1 => "Sorry $a[0], you are already logged on on another channel",
-  l2 => "Hello $a[0], this is $a[1] located in $a[2]",
-);
+sub load
+{
+       my $ref = shift;
+       if (-e $localfn) {
+               do $localfn;
+               return ($@) if $@ && ref $ref;
+               confess $@ if $@;
+               return ();
+       }
+       do $fn;
+       return ($@) if $@ && ref $ref;
+       confess $@ if $@;
+       return ();
+}
 
-sub m
+sub init
 {
-  my $self = shift;
-  local @a = @_;
-  my $s = $msg{$self};
-  return "unknown message '$self'" if !defined $s;
-  return eval $s;
+       load();
 }
-