Mercurial > pub > Impl
comparison Lib/IMPL/Resources/StringLocaleMap.pm @ 382:99ac2e19c0cc
Implemented a strings map for a DOM schema
author | sergey |
---|---|
date | Thu, 23 Jan 2014 02:35:28 +0400 |
parents | 1eca08048ba9 |
children | 2f16f13b000c |
comparison
equal
deleted
inserted
replaced
381:ced5937ff21a | 382:99ac2e19c0cc |
---|---|
26 | 26 |
27 if (is($data, StringMap)) { | 27 if (is($data, StringMap)) { |
28 $this->_maps({ default => $data }); | 28 $this->_maps({ default => $data }); |
29 } elsif ( ref($data) eq 'HASH' ) { | 29 } elsif ( ref($data) eq 'HASH' ) { |
30 $this->_maps({ default => StringMap->new($data,$parent)}); | 30 $this->_maps({ default => StringMap->new($data,$parent)}); |
31 } else { | |
32 # в данном случае таблица строк по-умолчанию будет загружена | |
33 # из файла при необходимости | |
34 $this->_maps({}); | |
31 } | 35 } |
32 } | 36 } |
33 | 37 |
34 sub GetString { | 38 sub GetString { |
35 my ($this,$id,$args) = @_; | 39 my ($this,$id,$args) = @_; |
36 | 40 |
37 my $locale = Resources->currentLocale || 'default'; | 41 my $locale = Resources->currentLocale || 'default'; |
38 my $map; | 42 my $map; |
39 | 43 |
40 warn "id: $id,\t\tlocale: $locale"; | 44 #warn "id: $id,\t\tlocale: $locale"; |
41 | 45 |
42 if(not $map = $this->_maps->{$locale}) { | 46 if(not $map = $this->_maps->{$locale}) { |
43 $map = $this->LoadMap($locale,$this->_maps->{default}); | 47 my $default = $this->GetDefaultMap(); |
48 $map = $this->LoadMap($locale,$default); | |
44 if (is($map,StringMap)) { | 49 if (is($map,StringMap)) { |
45 #nop | 50 #nop |
46 } elsif (ref($map) eq 'HASH') { | 51 } elsif (ref($map) eq 'HASH') { |
47 $map = StringMap->new($map,$this->_maps->{default}); | 52 $map = StringMap->new($map,$default); |
48 } elsif( not $map ) { | 53 } elsif( not $map ) { |
49 $map = $this->_maps->{default}; | 54 $map = $default; |
50 } else { | 55 } else { |
51 die Exception->new("ResolveLocale returned unexpected data", $map); | 56 die Exception->new("ResolveLocale returned unexpected data", $map); |
52 } | 57 } |
53 | 58 |
54 $this->_maps->{$locale} = $map; | 59 $this->_maps->{$locale} = $map; |
55 } | 60 } |
56 | 61 |
57 return $map->GetString($id,$args); | 62 return $map->GetString($id,$args); |
63 } | |
64 | |
65 sub GetDefaultMap { | |
66 my ($this) = @_; | |
67 | |
68 my $map = $this->_maps->{default}; | |
69 return $map | |
70 if $map; | |
71 | |
72 $map = $this->LoadMap('default') || StringMap->new({}); | |
73 $this->_maps->{default} = $map; | |
74 | |
75 return $map; | |
58 } | 76 } |
59 | 77 |
60 sub LoadMap { | 78 sub LoadMap { |
61 my ($this,$locale,$default) = @_; | 79 my ($this,$locale,$default) = @_; |
62 | 80 |