| 1 | package Apache::UploadSvr::Dictionary; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use IO::File; | ||
| 5 | use vars qw( $VERSION $D ); | ||
| 6 | |||
| 7 | $VERSION = sprintf "%d.%03d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/; | ||
| 8 | |||
| 9 | sub init { | ||
| 10 | $D = {}; | ||
| 11 | local($/) = ""; | ||
| 12 | my $file = __FILE__; | ||
| 13 | $file =~ s/\.pm$/.data/; | ||
| 14 | my $fh = IO::File->new; | ||
| 15 | $fh->open($file) or die "Could not open file[$file]: $!"; | ||
| 16 | while (<$fh>) { | ||
| 17 | my($lang,$code) = /(..):(\w+)/ or last; | ||
| 18 | die "strange string $_" unless $code; | ||
| 19 | my $string = <$fh> or "No string for lang[$lang]code[$code]"; | ||
| 20 | $D->{$lang}{$code} = $string; | ||
| 21 | } | ||
| 22 | $fh->close; | ||
| 23 | } | ||
| 24 | |||
| 25 | &init; | ||
| 26 | |||
| 27 | sub fetch { | ||
| 28 | my($class,$lang,$code,@arg) = @_; | ||
| 29 | # May be inefficient if they do not use arguments, but conveniently to use | ||
| 30 | # if they do | ||
| 31 | unless (exists $D->{$lang} && exists $D->{$lang}{$code}){ | ||
| 32 | warn "Not in dictionary: lang[$lang]code[$code]"; | ||
| 33 | return "<B>INCOMPLETE DICTIONARY</B>"; | ||
| 34 | } | ||
| 35 | sprintf $D->{$lang}{$code}, @arg; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub exists { | ||
| 39 | my($class,$lang) = @_; | ||
| 40 | exists $D->{$lang}; | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 |