3 |
# This file is part of Bibulus. |
# This file is part of Bibulus. |
4 |
# For copyright and license, please refer to ../Bibulus.pm |
# For copyright and license, please refer to ../Bibulus.pm |
5 |
|
|
6 |
|
# This files contains various functions to deal with languages. |
7 |
|
|
8 |
sub setmainlang { |
sub setmainlang { |
9 |
my $self = shift; |
my $self = shift; |
10 |
my $lang = shift; |
my $lang = shift; |
12 |
$self->{MAINLANG} = $lang; |
$self->{MAINLANG} = $lang; |
13 |
} |
} |
14 |
|
|
15 |
# Language files are read for each object so that individual fields |
# A function to get and set languages. Originally, it verified the |
16 |
# can be easily overridden. |
# language, but that will make it difficult for users to add more |
17 |
sub initlang { |
# languages. Perhaps one should strip off _XX (country codes)? |
|
my $self = shift; |
|
|
# do 'lang.pl'; # auto-generated from lang/*.dat |
|
|
} |
|
|
|
|
|
|
|
|
# Language stuff |
|
18 |
sub lang { |
sub lang { |
19 |
my $self = shift; |
my $self = shift; |
20 |
|
|
21 |
if (@_) { |
if (@_) { |
22 |
my $l = shift; |
my $l = shift; |
23 |
if ($l =~ /^(en|da)$/) { # accepted languages |
$self->{LANG} = $l; |
|
$self->{LANG} = $l; |
|
|
} else { |
|
|
warn "Language $l unknown.\n"; |
|
|
} |
|
24 |
} |
} |
25 |
|
|
26 |
return $self->{LANG}; |
return $self->{LANG}; |
27 |
} |
} |
28 |
|
|
36 |
my ($self) = @_; |
my ($self) = @_; |
37 |
my ($pkg, $meth) = $AUTOLOAD =~ /(.*)::(.*)/; |
my ($pkg, $meth) = $AUTOLOAD =~ /(.*)::(.*)/; |
38 |
$meth =~ /DESTROY/ and return; |
$meth =~ /DESTROY/ and return; |
39 |
|
my $m; |
40 |
|
|
41 |
|
# Get into the right namespace: |
42 |
eval "require Bibulus::$self->{LANG}" or die $@; |
eval "require Bibulus::$self->{LANG}" or die $@; |
43 |
$meth = "Bibulus::$self->{LANG}::$meth"; |
|
44 |
goto &$meth; |
# Load some text strings into $self if they're not there already: |
45 |
|
$meth ne 'populate' and !defined($self->{LANGINIT}{$self->{LANG}}) |
46 |
|
and $self->populate; |
47 |
|
$m = "Bibulus::$self->{LANG}::$meth"; |
48 |
|
|
49 |
|
# Now go to the function if it's there |
50 |
|
defined(&$m) and goto &$m; |
51 |
|
|
52 |
|
# If it's not, look for it in general.pm: |
53 |
|
eval "require Bibulus::general" or die $@; |
54 |
|
$m = "Bibulus::general::$meth"; |
55 |
|
defined(&$m) and goto &$m; |
56 |
|
|
57 |
|
# Otherwise, die! |
58 |
|
die "$m not found in $self->{LANG} or general.\n"; |
59 |
} |
} |
60 |
|
|
61 |
1; |
1; |