Mercurial > pub > Impl
changeset 380:1eca08048ba9
TTContext migrated to the unified localization mechanism IMPL::Resources::StringLocaleMap
author | cin |
---|---|
date | Fri, 17 Jan 2014 15:58:57 +0400 |
parents | a471e8b77544 |
children | ced5937ff21a |
files | Lib/IMPL/Resources/StringLocaleMap.pm Lib/IMPL/Web/View/TTContext.pm |
diffstat | 2 files changed, 53 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/IMPL/Resources/StringLocaleMap.pm Thu Jan 16 18:10:50 2014 +0400 +++ b/Lib/IMPL/Resources/StringLocaleMap.pm Fri Jan 17 15:58:57 2014 +0400 @@ -37,6 +37,8 @@ my $locale = Resources->currentLocale || 'default'; my $map; + warn "id: $id,\t\tlocale: $locale"; + if(not $map = $this->_maps->{$locale}) { $map = $this->LoadMap($locale,$this->_maps->{default}); if (is($map,StringMap)) {
--- a/Lib/IMPL/Web/View/TTContext.pm Thu Jan 16 18:10:50 2014 +0400 +++ b/Lib/IMPL/Web/View/TTContext.pm Fri Jan 17 15:58:57 2014 +0400 @@ -16,7 +16,8 @@ Resources => 'IMPL::Resources', Loader => 'IMPL::Code::Loader', MetadataBase => '-IMPL::Web::View::Metadata::BaseMeta', - Metadata => 'IMPL::Web::View::Metadata::ObjectMeta' + Metadata => 'IMPL::Web::View::Metadata::ObjectMeta', + StringMap => 'IMPL::Resources::StringLocaleMap' }, base => [ 'Template::Context' => '@_' @@ -38,10 +39,10 @@ includes modules aliases - id metadata model + templateInfo )) { my $t = $prop; @@ -93,6 +94,7 @@ } my @inc = ($this->base, @{$this->includes || []}); + #my @inc = @{$this->includes || []}; my $ext = $this->tt_ext || ""; @@ -101,7 +103,11 @@ foreach my $dir (@inc) { $file = $dir ? "$dir/$name" : $name; - my $base = join('/',splice([split(/\/+/,$file)],0,-1)); + my @parts = split(/\/+/,$file); + + my $templateName = pop @parts; + + my $base = join('/',@parts); $file = $ext ? "$file.$ext" : $file; @@ -118,10 +124,11 @@ } my $info = { base => $base, - labels => $this->load_labels($file), + name => $templateName, template => $tt, initialized => 0, - class => $class + class => $class, + file => $file }; $this->modules->{$file} = $info; return $cache->{$name} = $info; @@ -246,7 +253,10 @@ display_model => sub { $ctx->display_model(@_); }, - tt_cache => {} + tt_cache => {}, + labels => sub { + $ctx->load_labels(@_); + } }, $env ) @@ -309,15 +319,13 @@ } else { return $ctx->include($info->{template},$args); } - }, - hashMerge( - $info->{labels} || {}, - { - base => $info->{base}, - parent => $this, - id => $this->get_next_id - } - ) + }, + { + base => $info->{base}, + parent => $this, + id => $this->get_next_id, + templateInfo => $info + } ) } @@ -393,6 +401,8 @@ sub get_real_file { my ($this,$fname) = @_; + return unless length $fname; + my @path = split(/\/+/,$fname); foreach my $provider (@{$this->load_templates || []}) { @@ -404,36 +414,36 @@ } sub load_labels { - my ($this,$fname) = @_; + my ($this,$data) = @_; - $fname = $this->get_real_file($fname); + die ArgException->new("A hash reference is required") + unless ref($data) eq 'HASH'; - my %vars; + my $stringMap = StringMap->new($data); - my $flabels = "$fname.labels"; - - if (-f $flabels) { - - my %labels; - $labels{default} = IMPL::Resources::Strings::ParseStringsMap($flabels); - - while(my($label,$text) = each %{$labels{default}}) { - $vars{$label} = sub { - my ($params) = @_; - my $locale = Resources->currentLocale; - - unless ($labels{$locale}) { - $labels{$locale} = -f "$fname.$locale" ? - IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") : - {}; - } - - return FormatMessage(($labels{$locale}{$label} || $text),$params); - } - } - } + $this->stash->update({ + map { + my $id = $_; + $id, + sub { + $stringMap->GetString($id,@_); + }; + } keys %$data + }); + + my $ti = $this->templateInfo || {}; - return \%vars; + if (my $fullName = $this->get_real_file($ti->{file})) { + my ($vol,$dir,$fname) = File::Spec->splitpath($fullName); + + my $name = $this->templateInfo->{name}; + + my $localePath = File::Spec->catpath($vol, File::Spec->catdir($dir,'locale'),''); + + $stringMap->name($name); + $stringMap->paths($localePath); + } + return; } 1;