Loc3.01: -seperator, -langs
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 31 May 2006 00:22:14 +0000 (00:22 +0000)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 10 Jun 2009 17:39:58 +0000 (17:39 +0000)
Lirama/Loc3.pm

index 2a89689b099dc9711d7c01f5364626faa7177193..d7f4d49b6be6dbcb260d367631744c94713c2d46 100644 (file)
@@ -3,7 +3,7 @@ package Lirama::Loc3;
 use strict;
 use warnings;
 
-our $VERSION = '3.00';
+our $VERSION = '3.01';
 
 sub loc($) {
        my $this = shift;
@@ -21,23 +21,26 @@ sub TIEHASH {
 
 sub FETCH {
        my $this = shift;
+       local $_ = shift;
        # get setting (denoted by leading dash)
-       return wantarray ? @{$this->{$_[0]}} : $this->{$_[0]}->[0]
-               if $_[0] eq "-langpref";
-       return $this->{$_[0]}
-               if $_[0] eq "-path";
+       return wantarray ? @{$this->{$_}} : $this->{$_}->[0]
+               if $_ eq "-langpref";
+       return $this->{$_}
+               if $_ eq "-path" or $_ eq "-seperator";
        # array ref used for passing arguments
-       @_ = @{$_[0]} if ref $_[0] eq "ARRAY";
-       # get localized string by identifier
-       local $_ = shift;
+       ($_, @_) = @$_ if ref $_ eq "ARRAY";
        # add default path unless specified
-       $_ = $this->{-path} . '_' . $_ unless /_/;
-                       #todo: shouldn't occur - find out where this is done, then fix and remove this check
-               #       defined $_ or return '';
-       $_ = $this->loc($this->{$_}) if exists $this->{$_};
-       #todo: else remove path
-       # adaptive string (code)
-       $_ = $_->(@_) if ref $_ eq "CODE";
+       $_ = $this->{-path} . $this->{-seperator} . $_
+               if defined $this->{-seperator} and not /\Q$this->{-seperator}/;
+       # get localized string by identifier
+       if (exists $this->{$_}) {
+               $_ = $this->loc($this->{$_});
+               # adaptive string (code)
+               $_ = $_->(@_) if ref $_ eq "CODE";
+       } else {
+               #todo: else remove path
+               s/.*\Q$this->{-seperator}//s if defined $this->{-seperator};
+       }
        # static output if no arguments given
        return $_ unless @_;  # unnecessary but faster for common case
        # dynamic output
@@ -50,6 +53,11 @@ sub STORE {
                # set order of languages (prefered language first)
                $this->{$option} = $val;
        } # -langpref
+       elsif ($option eq "-seperator") {
+               $this->{-path} =~ s/\Q$this->{$option}/$val/g
+                       if defined $this->{$option}; # replace old occurances
+               $this->{$option} = $val;
+       } # -seperator
        else {
                $this->{$option} = $val;
 #              $_[0]->{$_[1]} = $_[2];
@@ -77,6 +85,8 @@ Lirama::Loc3 - Localize strings
        use Lirama::Loc3;
 
        tie my %loc, "Lirama::Loc3", {
+               -langs => {en => 100, eo => 95},
+               -seperator => '_',
                _test => {
                        en => "this is a test",
                        eo => "cxi tio estas testo",