Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/TTFactory.pm @ 337:f4e14f32cf54
fixed bugs with string and local $_
added support for localized labels
author | cin |
---|---|
date | Fri, 14 Jun 2013 15:37:34 +0400 |
parents | 86336d451b82 |
children | c78dfbe658bd |
comparison
equal
deleted
inserted
replaced
336:86336d451b82 | 337:f4e14f32cf54 |
---|---|
108 | 108 |
109 $module =~ s/^\.\//$baseLocation\//; | 109 $module =~ s/^\.\//$baseLocation\//; |
110 return $registry->Require($module); | 110 return $registry->Require($module); |
111 } | 111 } |
112 }); | 112 }); |
113 $this->LoadLabelsToContext($context); | |
114 } | |
115 | |
116 #TODO optimize labels loading for extended classes | |
117 sub LoadLabelsToContext { | |
118 my ($this,$context) = @_; | |
119 | |
120 $this->base->LoadLabelsToContext($context) | |
121 if $this->base; | |
122 | |
123 if(my $fname = $this->registry->loader->ResolveFileName($this->path)) { | |
124 my $flabels = "$fname.labels"; | |
125 | |
126 if (-f $flabels) { | |
127 my %vars; | |
128 my %labels; | |
129 $labels{default} = IMPL::Resources::Strings::ParseStringsMap("$flabels"); | |
130 | |
131 while(my($label,$text) = each %{$labels{default}}) { | |
132 warn "LABEL: $label"; | |
133 $vars{$label} = sub { | |
134 my ($params) = @_; | |
135 my $locale = 'ru_RU'; | |
136 | |
137 unless ($labels{$locale}) { | |
138 $labels{$locale} = -f "$fname.$locale" ? | |
139 IMPL::Resources::Strings::ParseStringsMap("$fname.$locale") : | |
140 {}; | |
141 } | |
142 | |
143 return FormatMessage(($labels{$locale}{$label} || $text),$params); | |
144 } | |
145 } | |
146 $context->stash->update(\%vars); | |
147 } | |
148 } | |
113 } | 149 } |
114 | 150 |
115 sub MergeParameters { | 151 sub MergeParameters { |
116 my $this = shift; | 152 my $this = shift; |
117 my $refProps = shift || {}; | 153 my $refProps = shift || {}; |
123 $refProps->{name} ||= $name; | 159 $refProps->{name} ||= $name; |
124 } | 160 } |
125 | 161 |
126 $refProps->{factory} = $this; | 162 $refProps->{factory} = $this; |
127 my $ctx = $this->CloneContext(); | 163 my $ctx = $this->CloneContext(); |
128 | |
129 my $t = $ctx; | |
130 weaken($t); | |
131 | |
132 $ctx->stash->update({ | |
133 strings => sub { | |
134 my ($labels) = @_; | |
135 if(ref($labels) eq 'HASH') { | |
136 #TODO make strings map shared between controls | |
137 my $map; | |
138 my $vars; | |
139 while(my ($label,$text) = each %$labels) { | |
140 $vars->{$label} = sub { | |
141 my ($params) = @_; | |
142 | |
143 my $locale = 'ru_RU'; | |
144 | |
145 unless($map->{$locale}) { | |
146 my $file = $this->registry->loader->ResolveFileName($this->path); | |
147 if($file and -f "$file.$locale") { | |
148 warn "STRINGS: $file.$locale"; | |
149 $map->{$locale} = IMPL::Resources::String::ParseStringsMap("$file.$locale"); | |
150 } else { | |
151 $map->{$locale} = {}; | |
152 } | |
153 } | |
154 | |
155 return FormatMessage(($map->{$locale}{$label} || $text),$params); | |
156 } | |
157 } | |
158 $t->stash->update($vars); | |
159 } | |
160 return; | |
161 } | |
162 }); | |
163 | 164 |
164 return ($this->template, $ctx, $refProps); | 165 return ($this->template, $ctx, $refProps); |
165 } | 166 } |
166 | 167 |
167 sub CreateObject { | 168 sub CreateObject { |