BUGFIX: fixing i18n _t function breaking out of when correct translation found

This commit is contained in:
Julian Seidenberg 2012-04-18 13:21:07 +12:00
parent 192237cb7d
commit 0da62b9552
2 changed files with 29 additions and 2 deletions

View File

@ -1503,7 +1503,10 @@ class i18n extends Object implements TemplateGlobalProvider {
$translation = $adapter->translate($entity, $locale); $translation = $adapter->translate($entity, $locale);
// Return translation only if we found a match thats not the entity itself (Zend fallback) // 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 File

@ -171,10 +171,14 @@ class i18nTest extends SapphireTest {
i18n::set_locale('en_US'); i18n::set_locale('en_US');
i18n::get_translator('core')->getAdapter()->addTranslation(array( i18n::get_translator('core')->getAdapter()->addTranslation(array(
'i18nTestModule.MAINTEMPLATE' => 'Main Template', 'i18nTestModule.MAINTEMPLATE' => 'Main Template',
'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'My replacement no namespace: %s',
'i18nTestModule.LAYOUTTEMPLATE' => 'Layout Template', 'i18nTestModule.LAYOUTTEMPLATE' => 'Layout Template',
'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'Layout Template no namespace',
'i18nTestModule.SPRINTFNAMESPACE' => 'My replacement: %s', 'i18nTestModule.SPRINTFNAMESPACE' => 'My replacement: %s',
'i18nTestModule.WITHNAMESPACE' => 'Include Entity with Namespace', 'i18nTestModule.WITHNAMESPACE' => 'Include Entity with Namespace',
'i18nTestModuleInclude.ss.NONAMESPACE' => 'Include Entity without Namespace',
'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'My include replacement: %s', 'i18nTestModuleInclude.ss.SPRINTFINCLUDENAMESPACE' => 'My include replacement: %s',
'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'My include replacement no namespace: %s'
), 'en_US'); ), 'en_US');
$viewer = new SSViewer('i18nTestModule'); $viewer = new SSViewer('i18nTestModule');
@ -183,14 +187,22 @@ class i18nTest extends SapphireTest {
"Layout Template\n", "Layout Template\n",
$parsedHtml $parsedHtml
); );
$this->assertContains(
"Layout Template no namespace\n",
$parsedHtml
);
i18n::set_locale('de_DE'); i18n::set_locale('de_DE');
i18n::get_translator('core')->getAdapter()->addTranslation(array( i18n::get_translator('core')->getAdapter()->addTranslation(array(
'i18nTestModule.MAINTEMPLATE' => 'TRANS Main Template', 'i18nTestModule.MAINTEMPLATE' => 'TRANS Main Template',
'i18nTestModule.ss.SPRINTFNONAMESPACE' => 'TRANS My replacement no namespace: %s',
'i18nTestModule.LAYOUTTEMPLATE' => 'TRANS Layout Template', 'i18nTestModule.LAYOUTTEMPLATE' => 'TRANS Layout Template',
'i18nTestModule.ss.LAYOUTTEMPLATENONAMESPACE' => 'TRANS Layout Template no namespace',
'i18nTestModule.SPRINTFNAMESPACE' => 'TRANS My replacement: %s', 'i18nTestModule.SPRINTFNAMESPACE' => 'TRANS My replacement: %s',
'i18nTestModule.WITHNAMESPACE' => 'TRANS Include Entity with Namespace', '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.SPRINTFINCLUDENAMESPACE' => 'TRANS My include replacement: %s',
'i18nTestModuleInclude.ss.SPRINTFINCLUDENONAMESPACE' => 'TRANS My include replacement no namespace: %s'
), 'de_DE'); ), 'de_DE');
$viewer = new SSViewer('i18nTestModule'); $viewer = new SSViewer('i18nTestModule');
@ -203,6 +215,10 @@ class i18nTest extends SapphireTest {
"TRANS Layout Template\n", "TRANS Layout Template\n",
$parsedHtml $parsedHtml
); );
$this->assertContains(
"TRANS Layout Template no namespace",
$parsedHtml
);
$this->assertContains( $this->assertContains(
"TRANS My replacement: TestPropertyValue", "TRANS My replacement: TestPropertyValue",
$parsedHtml $parsedHtml
@ -211,11 +227,19 @@ class i18nTest extends SapphireTest {
"TRANS Include Entity with Namespace", "TRANS Include Entity with Namespace",
$parsedHtml $parsedHtml
); );
$this->assertContains(
"TRANS Include Entity without Namespace",
$parsedHtml
);
$this->assertContains( $this->assertContains(
"TRANS My include replacement: TestPropertyValue", "TRANS My include replacement: TestPropertyValue",
$parsedHtml $parsedHtml
); );
$this->assertContains(
"TRANS My include replacement no namespace: TestPropertyValue",
$parsedHtml
);
i18n::set_locale($oldLocale); i18n::set_locale($oldLocale);
} }