API CHANGE Fixed i18n _t() calls without namespaces in template includes: They now default to setting the include filename as namespace, rather than the including template (#4915, #3400 - thanks Henk_Poley, jwalsoe, walec51)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@97797 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-01-29 02:20:31 +00:00 committed by Sam Minnee
parent b34315a35d
commit 5170f33915
2 changed files with 12 additions and 3 deletions

View File

@ -281,6 +281,12 @@ class SSViewer {
$content = file_get_contents(SSViewer::getTemplateFile($identifier));
// $content = "<!-- getTemplateContent() :: identifier: $identifier -->". $content;
// Adds an i18n namespace to all <% _t(...) %> calls without an existing one
// to avoid confusion when using the include in different contexts.
// Entities without a namespace are deprecated, but widely used.
$content = ereg_replace('<' . '% +_t\((\'([^\.\']*)\'|"([^\."]*)")(([^)]|\)[^ ]|\) +[^% ])*)\) +%' . '>', '<?= _t(\''. $identifier . '.ss' . '.\\2\\3\'\\4) ?>', $content);
// Remove UTF-8 byte order mark
// This is only necessary if you don't have zend-multibyte enabled.
if(substr($content, 0,3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
@ -519,7 +525,10 @@ class SSViewer {
// CAUTION: No spaces allowed between arguments for all i18n calls!
ereg('.*[\/](.*)',$template,$path);
// i18n _t(...) - with entity only (no dots in namespace), meaning the current template filename will be added as a namespace
// i18n _t(...) - with entity only (no dots in namespace),
// meaning the current template filename will be added as a namespace.
// This applies only to "root" templates, not includes which should always have their namespace set already.
// See getTemplateContent() for more information.
$content = ereg_replace('<' . '% +_t\((\'([^\.\']*)\'|"([^\."]*)")(([^)]|\)[^ ]|\) +[^% ])*)\) +%' . '>', '<?= _t(\''. $path[1] . '.\\2\\3\'\\4) ?>', $content);
// i18n _t(...)
$content = ereg_replace('<' . '% +_t\((\'([^\']*)\'|"([^"]*)")(([^)]|\)[^ ]|\) +[^% ])*)\) +%' . '>', '<?= _t(\'\\2\\3\'\\4) ?>', $content);

View File

@ -85,7 +85,7 @@ class i18nTest extends SapphireTest {
$lang['en_US']['i18nTest_DataObject']['MyProperty'] = 'MyProperty';
$lang['de_DE']['i18nTest_DataObject']['MyProperty'] = 'Mein Attribut';
$this->assertEquals(
$obj->fieldLabel('MyProperty'),
'Mein Attribut'
@ -163,7 +163,7 @@ class i18nTest extends SapphireTest {
$lang['de_DE']['i18nTestModule.ss']['LAYOUTTEMPLATENONAMESPACE'] = 'TRANS Layout Template no namespace';
$lang['de_DE']['i18nTestModule']['SPRINTFNAMESPACE'] = 'TRANS My replacement: %s';
$lang['de_DE']['i18nTestModule']['WITHNAMESPACE'] = 'TRANS Include Entity with Namespace';
$lang['de_DE']['i18nTestModule.ss']['NONAMESPACE'] = 'TRANS Include Entity without Namespace';
$lang['de_DE']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'TRANS Include Entity without Namespace';
$lang['de_DE']['i18nTestModuleInclude.ss']['SPRINTFINCLUDENAMESPACE'] = 'TRANS My include replacement: %s';
$lang['de_DE']['i18nTestModule.ss']['SPRINTFINCLUDENONAMESPACE'] = 'TRANS My include replacement no namespace: %s';
$viewer = new SSViewer('i18nTestModule');