diff --git a/src/i18n/TextCollection/i18nTextCollector.php b/src/i18n/TextCollection/i18nTextCollector.php index cb4a3b495..00fa87e30 100644 --- a/src/i18n/TextCollection/i18nTextCollector.php +++ b/src/i18n/TextCollection/i18nTextCollector.php @@ -556,11 +556,16 @@ class i18nTextCollector $inTransFn = false; $inConcat = false; $inNamespace = false; - $inClass = false; + $inClass = false; // after `class` but before `{` $inArrayClosedBy = false; // Set to the expected closing token, or false if not in array $currentEntity = array(); $currentClass = []; // Class components + $previousToken = null; + $thisToken = null; // used to populate $previousToken on next iteration foreach ($tokens as $token) { + // Shuffle last token to $lastToken + $previousToken = $thisToken; + $thisToken = $token; if (is_array($token)) { list($id, $text) = $token; @@ -577,6 +582,10 @@ class i18nTextCollector // Check class if ($id === T_CLASS) { + // Skip if previous token was '::'. E.g. 'Object::class' + if (is_array($previousToken) && $previousToken[0] === T_DOUBLE_COLON) { + continue; + } $inClass = true; continue; } diff --git a/tests/php/i18n/i18nTextCollectorTest.php b/tests/php/i18n/i18nTextCollectorTest.php index e30cf777a..44b5b52fd 100644 --- a/tests/php/i18n/i18nTextCollectorTest.php +++ b/tests/php/i18n/i18nTextCollectorTest.php @@ -324,7 +324,10 @@ PHP; namespace SilverStripe\Framework\Core; class MyClass extends Base implements SomeService { - public function getNewLines() { + public function getNewLines(\$class) { + if (!is_subclass_of(\$class, DataObject::class) || !Object::has_extension(\$class, Versioned::class)) { + return null; + } return _t( __CLASS__.'.NEWLINES', 'New Lines' @@ -455,7 +458,6 @@ PHP; $php = <<