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) (from r97797)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102534 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-12 23:39:15 +00:00
parent b9c0a14ecc
commit d62b3303f0

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)) {
@ -513,7 +519,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);