# HG changeset patch # User cin # Date 1371209854 -14400 # Node ID f4e14f32cf548dc7aa4fdafba6c5985aed337361 # Parent 86336d451b82c7af9c9d1fd9e50b742bed3cab35 fixed bugs with string and local $_ added support for localized labels diff -r 86336d451b82 -r f4e14f32cf54 Lib/IMPL/Resources/Strings.pm --- 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>) { diff -r 86336d451b82 -r f4e14f32cf54 Lib/IMPL/Web/View/TTFactory.pm --- 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); }