Mercurial > pub > Impl
diff Lib/IMPL/Web/View/TTFactory.pm @ 336:86336d451b82
sync
author | cin |
---|---|
date | Fri, 14 Jun 2013 03:32:55 +0400 |
parents | 75a78cbf7dcf |
children | f4e14f32cf54 |
line wrap: on
line diff
--- 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); }