Browse files

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

…ion found
  • Loading branch information...
1 parent 192237c commit 0da62b9552d6c733741df3bd93fcc71e9bd91b9b @candidasa candidasa committed Apr 18, 2012
Showing with 29 additions and 2 deletions.
  1. +4 −1 i18n/i18n.php
  2. +25 −1 tests/i18n/i18nTest.php
View
5 i18n/i18n.php
@@ -1503,7 +1503,10 @@ static function _t($entity, $string = "", $context = "", $injection = "") {
$translation = $adapter->translate($entity, $locale);
// Return translation only if we found a match thats not the entity itself (Zend fallback)
- if($translation && $translation != $entity) $returnValue = $translation;
+ if($translation && $translation != $entity) {
+ $returnValue = $translation;
+ break 2;
+ }
}
}
View
26 tests/i18n/i18nTest.php
@@ -171,10 +171,14 @@ function testTemplateTranslation() {
i18n::set_locale('en_US');
i18n::get_translator('core')->getAdapter()->addTranslation(array(
'i18nTestModule.MAINTEMPLATE' => 'Main Template',
+ 'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'My replacement no namespace: %s',
'i18nTestModule.LAYOUTTEMPLATE' => 'Layout Template',
+ 'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'Layout Template no namespace',
'i18nTestModule.SPRINTFNAMESPACE' => 'My replacement: %s',
'i18nTestModule.WITHNAMESPACE' => 'Include Entity with Namespace',
+ 'i18nTestModuleInclude.ss.NONAMESPACE' => 'Include Entity without Namespace',
'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'My include replacement: %s',
+ 'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'My include replacement no namespace: %s'
), 'en_US');
$viewer = new SSViewer('i18nTestModule');
@@ -183,14 +187,22 @@ function testTemplateTranslation() {
"Layout Template\n",
$parsedHtml
);
+ $this->assertContains(
+ "Layout Template no namespace\n",
+ $parsedHtml
+ );
i18n::set_locale('de_DE');
i18n::get_translator('core')->getAdapter()->addTranslation(array(
'i18nTestModule.MAINTEMPLATE' => 'TRANS Main Template',
+ 'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'TRANS My replacement no namespace: %s',
'i18nTestModule.LAYOUTTEMPLATE' => 'TRANS Layout Template',
+ 'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'TRANS Layout Template no namespace',
'i18nTestModule.SPRINTFNAMESPACE' => 'TRANS My replacement: %s',
'i18nTestModule.WITHNAMESPACE' => 'TRANS Include Entity with Namespace',
+ 'i18nTestModuleInclude.ss.NONAMESPACE' => 'TRANS Include Entity without Namespace',
'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'TRANS My include replacement: %s',
+ 'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'TRANS My include replacement no namespace: %s'
), 'de_DE');
$viewer = new SSViewer('i18nTestModule');
@@ -204,6 +216,10 @@ function testTemplateTranslation() {
$parsedHtml
);
$this->assertContains(
+ "TRANS Layout Template no namespace",
+ $parsedHtml
+ );
+ $this->assertContains(
"TRANS My replacement: TestPropertyValue",
$parsedHtml
);
@@ -212,10 +228,18 @@ function testTemplateTranslation() {
$parsedHtml
);
$this->assertContains(
+ "TRANS Include Entity without Namespace",
+ $parsedHtml
+ );
+ $this->assertContains(
"TRANS My include replacement: TestPropertyValue",
$parsedHtml
);
-
+ $this->assertContains(
+ "TRANS My include replacement no namespace: TestPropertyValue",
+ $parsedHtml
+ );
+
i18n::set_locale($oldLocale);
}

0 comments on commit 0da62b9

Please sign in to comment.