# HG changeset patch # User cin # Date 1371166375 -14400 # Node ID 86336d451b82c7af9c9d1fd9e50b742bed3cab35 # Parent e8be9062ecf2e76f0bd773c9f82cd899b93ad8de sync diff -r e8be9062ecf2 -r 86336d451b82 Lib/IMPL/Web/View/TTFactory.pm --- a/Lib/IMPL/Web/View/TTFactory.pm Thu Jun 13 20:13:24 2013 +0400 +++ b/Lib/IMPL/Web/View/TTFactory.pm Fri Jun 14 03:32:55 2013 +0400 @@ -7,6 +7,8 @@ use IMPL::lang qw(:hash is); use IMPL::Exception(); use Scalar::Util qw(weaken); +use IMPL::Resources::Format qw(FormatMessage); +use IMPL::Resources::Strings(); use IMPL::Const qw(:prop); @@ -29,6 +31,7 @@ base => PROP_RW, registry => PROP_RO, blocks => PROP_RO, + path => PROP_RO, _instance => PROP_RW ] }; @@ -50,6 +53,7 @@ $this->template($template); $this->context($context); $this->baseLocation($baseLocation); + $this->path($path); $this->registry($registry); if (my $baseTplName = $template->extends) { @@ -98,12 +102,14 @@ } } - $context->stash->update({ require => sub { - my ($module) = @_; - - $module =~ s/^\.\//$baseLocation\//; - return $registry->Require($module); - }}); + $context->stash->update({ + require => sub { + my ($module) = @_; + + $module =~ s/^\.\//$baseLocation\//; + return $registry->Require($module); + } + }); } sub MergeParameters { @@ -119,6 +125,41 @@ $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); } diff -r e8be9062ecf2 -r 86336d451b82 Lib/IMPL/Web/View/TTLoader.pm --- a/Lib/IMPL/Web/View/TTLoader.pm Thu Jun 13 20:13:24 2013 +0400 +++ b/Lib/IMPL/Web/View/TTLoader.pm Fri Jun 14 03:32:55 2013 +0400 @@ -3,6 +3,7 @@ use Template::Constants qw(:status); +use File::Spec(); use IMPL::Const qw(:prop); use IMPL::declare { require => { @@ -118,6 +119,15 @@ return $tt; } +sub ResolveFileName { + my ($this,$fname) = @_; + + $fname = $this->_appendExt($fname); + + my @files = grep -f , map File::Spec->catfile($_,$fname), @{$this->provider->paths()}; + return shift @files; +} + sub _appendExt { my ($this,$name) = @_;