10 # get one value from a hash of multiple options
11 # if it isn't, we're done already:
12 ref $_[0] eq "HASH" or return $_[0];
13 # localize to most preferred language
14 defined $_[0]{$_} and return $_[0]{$_} for @{$this->{-langpref}};
19 return bless $_[1], $_[0]; # bless the l10n hash
24 # get setting (denoted by leading dash)
25 return wantarray ? @{$this->{$_[0]}} : $this->{$_[0]}->[0]
26 if $_[0] eq "-langpref";
29 # array ref used for passing arguments
30 @_ = @{$_[0]} if ref $_[0] eq "ARRAY";
31 # get localized string by identifier
33 # add default path unless specified
34 $_ = $this->{-path} . '_' . $_ unless /_/;
35 #todo: shouldn't occur - find out where this is done, then fix and remove this check
36 # defined $_ or return '';
37 $_ = $this->loc($this->{$_}) if exists $this->{$_};
38 #todo: else remove path
39 # adaptive string (code)
40 $_ = $_->(@_) if ref $_ eq "CODE";
41 # static output if no arguments given
42 return $_ unless @_; # unnecessary but faster for common case
44 return sprintf $_, @_;
48 my ($this, $option, $val) = @_;
49 if ($option eq "-langpref") {
50 # set order of languages (prefered language first)
51 $this->{$option} = $val;
54 $this->{$option} = $val;
55 # $_[0]->{$_[1]} = $_[2];
59 # Same as found in Tie::StdHash
61 #todo: make path-aware
62 sub EXISTS { exists $_[0]->{$_[1]} }
63 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
64 sub NEXTKEY { each %{$_[0]} }
73 Lirama::Loc3 - Localize strings
79 tie my %loc, "Lirama::Loc3", {
81 en => "this is a test",
82 eo => "cxi tio estas testo",
86 $loc{-langpref} = [qw/nl en eo/]; # prefer I<nl> (dutch) texts
87 print $loc{test}; # "this is a test", since dutch is unavailable
91 Returns a text in the most preferred language available.
92 Mainly intended for translation of different strings on a website.
98 Shared so we only have to set one var to change all translations;
99 may yet be a very bad idea (does it work correctly in modperl?)
107 True if identifier is localized;
108 even though non-existing strings still return themselves.
114 L<Lirama::Loc3::Auto|Lirama::Loc3::Auto>
116 L<Locale::Maketext|Locale::Maketext>
120 Mischa POSLAWSKY <shiar@shiar.org>
122 Copyright 2005 Mischa POSLAWSKY. All rights reserved.