diff 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
line wrap: on
line diff
--- a/Lib/IMPL/Resources/StringLocaleMap.pm	Wed Jan 22 16:56:10 2014 +0400
+++ b/Lib/IMPL/Resources/StringLocaleMap.pm	Thu Jan 23 02:35:28 2014 +0400
@@ -28,6 +28,10 @@
 		$this->_maps({ default => $data });
 	} elsif ( ref($data) eq 'HASH' ) {
 		$this->_maps({ default => StringMap->new($data,$parent)});
+	} else {
+		# в данном случае таблица строк по-умолчанию будет загружена
+		# из файла при необходимости
+		$this->_maps({});
 	}
 }
 
@@ -37,16 +41,17 @@
 	my $locale = Resources->currentLocale || 'default';
 	my $map;
 	
-	warn "id: $id,\t\tlocale: $locale";
+	#warn "id: $id,\t\tlocale: $locale";
 	
 	if(not $map = $this->_maps->{$locale}) {
-		$map = $this->LoadMap($locale,$this->_maps->{default});
+		my $default = $this->GetDefaultMap();
+		$map = $this->LoadMap($locale,$default);
 		if (is($map,StringMap)) {
 			#nop
 		} elsif (ref($map) eq 'HASH') {
-			$map = StringMap->new($map,$this->_maps->{default});
+			$map = StringMap->new($map,$default);
 		} elsif( not $map ) {
-			$map = $this->_maps->{default};
+			$map = $default;
 		} else {
 			die Exception->new("ResolveLocale returned unexpected data", $map);
 		}
@@ -57,6 +62,19 @@
 	return $map->GetString($id,$args);
 }
 
+sub GetDefaultMap {
+	my ($this) = @_;
+	
+	my $map = $this->_maps->{default};
+	return $map
+		if $map;
+	
+	$map = $this->LoadMap('default') || StringMap->new({});
+	$this->_maps->{default} = $map;
+	
+	return $map;
+}
+
 sub LoadMap {
 	my ($this,$locale,$default) = @_;