comparison Lib/IMPL/Web/View/TTFactory.pm @ 338:c78dfbe658bd

improved string maps loading for TT documents
author cin
date Sat, 15 Jun 2013 02:32:11 +0400
parents f4e14f32cf54
children 97628101b765
comparison
equal deleted inserted replaced
337:f4e14f32cf54 338:c78dfbe658bd
13 13
14 use IMPL::Const qw(:prop); 14 use IMPL::Const qw(:prop);
15 use IMPL::declare { 15 use IMPL::declare {
16 require => { 16 require => {
17 Loader => 'IMPL::Code::Loader', 17 Loader => 'IMPL::Code::Loader',
18 Resources => 'IMPL::Resources',
18 OpException => '-IMPL::InvalidOperationException', 19 OpException => '-IMPL::InvalidOperationException',
19 ArgException => '-IMPL::InvalidArgumentException' 20 ArgException => '-IMPL::InvalidArgumentException'
20 }, 21 },
21 base => [ 22 base => [
22 'IMPL::Object::Factory' => sub { 23 'IMPL::Object::Factory' => sub {
30 baseLocation => PROP_RW, 31 baseLocation => PROP_RW,
31 base => PROP_RW, 32 base => PROP_RW,
32 registry => PROP_RO, 33 registry => PROP_RO,
33 blocks => PROP_RO, 34 blocks => PROP_RO,
34 path => PROP_RO, 35 path => PROP_RO,
35 _instance => PROP_RW 36 _instance => PROP_RW,
37 _labels => PROP_RW
36 ] 38 ]
37 }; 39 };
38 40
39 sub CTOR { 41 sub CTOR {
40 my ($this,$class,$template,$context,$path,$registry) = @_; 42 my ($this,$class,$template,$context,$path,$registry) = @_;
115 117
116 #TODO optimize labels loading for extended classes 118 #TODO optimize labels loading for extended classes
117 sub LoadLabelsToContext { 119 sub LoadLabelsToContext {
118 my ($this,$context) = @_; 120 my ($this,$context) = @_;
119 121
120 $this->base->LoadLabelsToContext($context) 122 my %vars;
123
124 %vars = %{$this->base->_labels || {}}
121 if $this->base; 125 if $this->base;
126 $this->_labels(\%vars);
122 127
123 if(my $fname = $this->registry->loader->ResolveFileName($this->path)) { 128 if(my $fname = $this->registry->loader->ResolveFileName($this->path)) {
124 my $flabels = "$fname.labels"; 129 my $flabels = "$fname.labels";
125 130
126 if (-f $flabels) { 131 if (-f $flabels) {
127 my %vars; 132
128 my %labels; 133 my %labels;
129 $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels"); 134 $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels");
130 135
131 while(my($label,$text) = each %{$labels{default}}) { 136 while(my($label,$text) = each %{$labels{default}}) {
132 warn "LABEL: $label"; 137 warn "LABEL: $label";
133 $vars{$label} = sub { 138 $vars{$label} = sub {
134 my ($params) = @_; 139 my ($params) = @_;
135 my $locale = 'ru_RU'; 140 my $locale = Resources->currentLocale;
136 141
137 unless ($labels{$locale}) { 142 unless ($labels{$locale}) {
138 $labels{$locale} = -f "$fname.$locale" ? 143 $labels{$locale} = -f "$fname.$locale" ?
139 IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") : 144 IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") :
140 {}; 145 {};
141 } 146 }
142 147
143 return FormatMessage(($labels{$locale}{$label} || $text),$params); 148 return FormatMessage(($labels{$locale}{$label} || $text),$params);
144 } 149 }
145 } 150 }
146 $context->stash->update(\%vars); 151
147 } 152 }
148 } 153 }
154 $context->stash->update(\%vars);
149 } 155 }
150 156
151 sub MergeParameters { 157 sub MergeParameters {
152 my $this = shift; 158 my $this = shift;
153 my $refProps = shift || {}; 159 my $refProps = shift || {};