Mercurial > pub > Impl
changeset 337:f4e14f32cf54
fixed bugs with string and local $_
added support for localized labels
author | cin |
---|---|
date | Fri, 14 Jun 2013 15:37:34 +0400 |
parents | 86336d451b82 |
children | c78dfbe658bd |
files | Lib/IMPL/Resources/Strings.pm Lib/IMPL/Web/View/TTFactory.pm |
diffstat | 2 files changed, 38 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Resources/Strings.pm Fri Jun 14 03:32:55 2013 +0400 +++ b/Lib/IMPL/Resources/Strings.pm Fri Jun 14 15:37:34 2013 +0400 @@ -87,8 +87,8 @@ sub ParseStringsMap { my ($fname) = @_; - open my $hRes, "<:encoding($Encoding)", findFile($fname) or die "Failed to open file $fname: $!"; - + open my $hRes, "<:encoding($Encoding)", $fname or die "Failed to open file $fname: $!"; + local $_; my %Map; my $line = 1; while (<$hRes>) {
--- a/Lib/IMPL/Web/View/TTFactory.pm Fri Jun 14 03:32:55 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Fri Jun 14 15:37:34 2013 +0400 @@ -110,6 +110,42 @@ return $registry->Require($module); } }); + $this->LoadLabelsToContext($context); +} + +#TODO optimize labels loading for extended classes +sub LoadLabelsToContext { + my ($this,$context) = @_; + + $this->base->LoadLabelsToContext($context) + if $this->base; + + if(my $fname = $this->registry->loader->ResolveFileName($this->path)) { + my $flabels = "$fname.labels"; + + if (-f $flabels) { + my %vars; + my %labels; + $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels"); + + while(my($label,$text) = each %{$labels{default}}) { + warn "LABEL: $label"; + $vars{$label} = sub { + my ($params) = @_; + my $locale = 'ru_RU'; + + unless ($labels{$locale}) { + $labels{$locale} = -f "$fname.$locale" ? + IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") : + {}; + } + + return FormatMessage(($labels{$locale}{$label} || $text),$params); + } + } + $context->stash->update(\%vars); + } + } } sub MergeParameters { @@ -125,41 +161,6 @@ $refProps->{factory} = $this; my $ctx = $this->CloneContext(); - - my $t = $ctx; - weaken($t); - - $ctx->stash->update({ - strings => sub { - my ($labels) = @_; - if(ref($labels) eq 'HASH') { - #TODO make strings map shared between controls - my $map; - my $vars; - while(my ($label,$text) = each %$labels) { - $vars->{$label} = sub { - my ($params) = @_; - - my $locale = 'ru_RU'; - - unless($map->{$locale}) { - my $file = $this->registry->loader->ResolveFileName($this->path); - if($file and -f "$file.$locale") { - warn "STRINGS: $file.$locale"; - $map->{$locale} = IMPL::Resources::String::ParseStringsMap("$file.$locale"); - } else { - $map->{$locale} = {}; - } - } - - return FormatMessage(($map->{$locale}{$label} || $text),$params); - } - } - $t->stash->update($vars); - } - return; - } - }); return ($this->template, $ctx, $refProps); }