Skip to content
This repository
Browse code

BUGFIX: fixing i18n _t function breaking out of when correct translat…

…ion found
  • Loading branch information...
commit 0da62b9552d6c733741df3bd93fcc71e9bd91b9b 1 parent 192237c
Julian Seidenberg authored
5  i18n/i18n.php
@@ -1503,7 +1503,10 @@ static function _t($entity, $string = "", $context = "", $injection = "") {
1503 1503
 				$translation = $adapter->translate($entity, $locale);
1504 1504
 
1505 1505
 				// Return translation only if we found a match thats not the entity itself (Zend fallback)
1506  
-				if($translation && $translation != $entity) $returnValue = $translation;
  1506
+				if($translation && $translation != $entity) {
  1507
+					$returnValue = $translation;
  1508
+					break 2;
  1509
+				}
1507 1510
 			}
1508 1511
 		}
1509 1512
 
26  tests/i18n/i18nTest.php
@@ -171,10 +171,14 @@ function testTemplateTranslation() {
171 171
 		i18n::set_locale('en_US');
172 172
 		i18n::get_translator('core')->getAdapter()->addTranslation(array(
173 173
 			'i18nTestModule.MAINTEMPLATE' => 'Main Template',
  174
+			'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'My replacement no namespace: %s',
174 175
 			'i18nTestModule.LAYOUTTEMPLATE' => 'Layout Template',
  176
+			'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'Layout Template no namespace',
175 177
 			'i18nTestModule.SPRINTFNAMESPACE' => 'My replacement: %s',
176 178
 			'i18nTestModule.WITHNAMESPACE' => 'Include Entity with Namespace',
  179
+			'i18nTestModuleInclude.ss.NONAMESPACE' => 'Include Entity without Namespace',
177 180
 			'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'My include replacement: %s',
  181
+			'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'My include replacement no namespace: %s'
178 182
 		), 'en_US');
179 183
 		
180 184
 		$viewer = new SSViewer('i18nTestModule');
@@ -183,14 +187,22 @@ function testTemplateTranslation() {
183 187
 			"Layout Template\n",
184 188
 			$parsedHtml
185 189
 		);
  190
+		$this->assertContains(
  191
+			"Layout Template no namespace\n",
  192
+			$parsedHtml
  193
+		);
186 194
 		
187 195
 		i18n::set_locale('de_DE');
188 196
 		i18n::get_translator('core')->getAdapter()->addTranslation(array(
189 197
 			'i18nTestModule.MAINTEMPLATE' => 'TRANS Main Template',
  198
+			'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'TRANS My replacement no namespace: %s',
190 199
 			'i18nTestModule.LAYOUTTEMPLATE' => 'TRANS Layout Template',
  200
+			'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'TRANS Layout Template no namespace',
191 201
 			'i18nTestModule.SPRINTFNAMESPACE' => 'TRANS My replacement: %s',
192 202
 			'i18nTestModule.WITHNAMESPACE' => 'TRANS Include Entity with Namespace',
  203
+			'i18nTestModuleInclude.ss.NONAMESPACE' => 'TRANS Include Entity without Namespace',
193 204
 			'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'TRANS My include replacement: %s',
  205
+			'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'TRANS My include replacement no namespace: %s'
194 206
 		), 'de_DE');
195 207
 
196 208
 		$viewer = new SSViewer('i18nTestModule');
@@ -204,6 +216,10 @@ function testTemplateTranslation() {
204 216
 			$parsedHtml
205 217
 		);
206 218
 		$this->assertContains(
  219
+			"TRANS Layout Template no namespace",
  220
+			$parsedHtml
  221
+		);
  222
+		$this->assertContains(
207 223
 			"TRANS My replacement: TestPropertyValue",
208 224
 			$parsedHtml
209 225
 		);
@@ -212,10 +228,18 @@ function testTemplateTranslation() {
212 228
 			$parsedHtml
213 229
 		);
214 230
 		$this->assertContains(
  231
+			"TRANS Include Entity without Namespace",
  232
+			$parsedHtml
  233
+		);
  234
+		$this->assertContains(
215 235
 			"TRANS My include replacement: TestPropertyValue",
216 236
 			$parsedHtml
217 237
 		);
218  
-
  238
+		$this->assertContains(
  239
+			"TRANS My include replacement no namespace: TestPropertyValue",
  240
+			$parsedHtml
  241
+		);
  242
+		
219 243
 		i18n::set_locale($oldLocale);
220 244
 	}
221 245
 

0 notes on commit 0da62b9

Please sign in to comment.
Something went wrong with that request. Please try again.