Mercurial > pub > Impl
changeset 336:86336d451b82
sync
author | cin |
---|---|
date | Fri, 14 Jun 2013 03:32:55 +0400 |
parents | e8be9062ecf2 |
children | f4e14f32cf54 |
files | Lib/IMPL/Web/View/TTFactory.pm Lib/IMPL/Web/View/TTLoader.pm |
diffstat | 2 files changed, 57 insertions(+), 6 deletions(-) [+] |
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); }
--- 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) = @_;