8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(langpref);
10 our @EXPORT_OK = qw(@langpref loc);
12 our @langpref = qw(en eo nl sv el hu de fr ru kr fi);
15 # @_ is order of languages (prefered language last)
17 unshift @langpref, splice @langpref, $_, 1 # move to front
18 for grep $langpref[$_] eq $lang, 0..$#langpref;
19 } # find $lang and move to front of @langpref
24 # localize to most preferred language
25 ref $_[0] eq "HASH" or return $_[0];
26 defined $_[0]{$_} and return $_[0]{$_} for @langpref;
33 while (my ($id, $langs) = each %{$_[0]}) {
34 $node->{$id} = $this->loc($langs);
35 } # add each element of i18n hash
37 return bless $node, $this;
42 # custom expand: get preferred language from given hash
43 return $this->loc($_[0]) if ref $_[0] eq "HASH"; # deprecated in favor of loc()
44 # array ref used for passing arguments
45 @_ = @{$_[0]} if ref $_[0] eq "ARRAY";
46 # get localized string by identifier
48 #todo: shouldn't occur - find out where this is done, then fix and remove this check
49 defined $_ or return '';
50 $_ = $this->{$_} if exists $this->{$_};
51 # static output if no arguments given
52 return $_ unless @_; # unnecessary but faster for common case
53 # adaptive string (code)
54 $_ = $_->(@_) if ref $_ eq "CODE";
56 return sprintf $_, @_;
60 # true if identifier is localized; non-existing strings still return
61 # themselves, so in standard meaning everything would exist
62 return exists $_[0]->{$_[1]};
67 keys %$this; # reset iterator
83 Lirama::Loc - Localize strings
89 langpref(qw/en eo/); # prefer esperanto texts
91 tie my %loc, "Lirama::Loc", {
93 en => "this is a test",
94 eo => "cxi tio estas testo",
95 nl => "dit is een test",
103 Returns a text in the preferred language.
107 L<Locale::Maketext|Locale::Maketext>
111 Mischa POSLAWSKY <shiar@shiar.org>
113 Copyright 2005 Mischa POSLAWSKY. All rights reserved.