From edbf7cfea4bf1726413cebd5400a7d5adac3d6ef Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 31 May 2006 00:22:14 +0000 Subject: [PATCH] Loc3.01: -seperator, -langs --- Lirama/Loc3.pm | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Lirama/Loc3.pm b/Lirama/Loc3.pm index 2a89689..d7f4d49 100644 --- a/Lirama/Loc3.pm +++ b/Lirama/Loc3.pm @@ -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", -- 2.30.0