5 use utf8; #todo: does it even matter?
10 our @ISA = qw(Exporter);
11 our @EXPORT = qw(langpref);
12 our @EXPORT_OK = qw(loc);
14 our @langpref;# = qw(en eo nl sv el hu de fr ru kr);
17 @langpref = @_ if @_; # set order of languages (prefered language first)
18 return wantarray ? @langpref : $langpref[0];
23 # get one value from a hash of multiple options
24 # if it isn't, we're done already:
25 ref $_[0] eq "HASH" or return $_[0];
26 # localize to most preferred language
27 defined $_[0]{$_} and return $_[0]{$_} for @langpref;
31 return bless $_[1], $_[0]; # bless the l10n hash
36 # custom expand: get preferred language from given hash
37 # return $this->loc($_[0]) if ref $_[0] eq "HASH"; # deprecated in favor of loc()
38 # array ref used for passing arguments
39 @_ = @{$_[0]} if ref $_[0] eq "ARRAY";
40 # get localized string by identifier
42 #todo: shouldn't occur - find out where this is done, then fix and remove this check
43 # defined $_ or return '';
44 $_ = $this->loc($this->{$_}) if exists $this->{$_};
45 # $_ = ref $this->{$_} eq "HASH" ? $this->loc($this->{$_}) : $this->{$_} if exists $this->{$_};
46 # static output if no arguments given
47 return $_ unless @_; # unnecessary but faster for common case
48 # adaptive string (code)
49 $_ = $_->(@_) if ref $_ eq "CODE";
51 return sprintf $_, @_;
54 # Same as found in Tie::StdHash
56 sub EXISTS { exists $_[0]->{$_[1]} }
57 sub FIRSTKEY { my $a = scalar keys %{$_[0]}; each %{$_[0]} }
58 sub NEXTKEY { each %{$_[0]} }
67 Lirama::Loc - Localize strings
73 langpref(qw/nl en eo/); # prefer I<nl> (dutch) texts
75 tie my %loc, "Lirama::Loc", {
77 en => "this is a test",
78 eo => "cxi tio estas testo",
82 print $loc{test}; # "this is a test", since dutch is unavailable
86 Returns a text in the most preferred language available.
87 Mainly intended for translation of different strings on a website.
93 Shared so we only have to set one var to change all translations;
94 may yet be a very bad idea (does it work correctly in modperl?)
102 True if identifier is localized; non-existing strings still return
103 themselves, so in standard meaning everything would exist.
109 L<Lirama::Loc::Auto|Lirama::Loc::Auto>
111 L<Locale::Maketext|Locale::Maketext>
115 Mischa POSLAWSKY <shiar@shiar.org>
117 Copyright 2005 Mischa POSLAWSKY. All rights reserved.