From 7ae5eadeaa7b26c65e22b59840b130f4f9119c46 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Tue, 7 Jan 2025 13:46:32 +1300 Subject: [PATCH] FIX Finish removing deprecated i18n functionality. This deprecated functionality was partially removed in #10594. This commit finishes the job. --- src/i18n/i18n.php | 28 ++++------------------------ src/includes/functions.php | 2 +- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/src/i18n/i18n.php b/src/i18n/i18n.php index 61ab1ec159b..390af9ecbdc 100644 --- a/src/i18n/i18n.php +++ b/src/i18n/i18n.php @@ -10,6 +10,7 @@ use SilverStripe\i18n\Messages\MessageProvider; use SilverStripe\View\TemplateGlobalProvider; use InvalidArgumentException; +use SilverStripe\Core\ArrayLib; /** * Base-class for storage and retrieval of translated entities. @@ -170,20 +171,9 @@ public static function _t($entity, $arg = null) user_error("Missing default for localisation key $entity", E_USER_WARNING); } - // Deprecate legacy injection format (`string %s, %d`) - // inject the variables from injectionArray (if present) - $sprintfArgs = []; - if ($default && !preg_match('/\{[\w\d]*\}/i', $default ?? '') && preg_match('/%[s,d]/', $default ?? '')) { - $sprintfArgs = array_values($injection ?? []); - $injection = []; - } - - // If injection isn't associative, assume legacy injection format - $failUnlessSprintf = false; - if ($injection && array_values($injection ?? []) === $injection) { - $failUnlessSprintf = true; // Note: Will trigger either a deprecation error or exception below - $sprintfArgs = array_values($injection ?? []); - $injection = []; + // Injection must be associative + if (!empty($injection) && !ArrayLib::is_associative($injection)) { + throw new InvalidArgumentException('Injection must be an associative array'); } // Detect plurals: Has a {count} argument as well as a `|` pipe delimited string (if provided) @@ -201,16 +191,6 @@ public static function _t($entity, $arg = null) $result = static::getMessageProvider()->translate($entity, $default, $injection); } - if (!$default && !preg_match('/\{[\w\d]*\}/i', $result ?? '') && preg_match('/%[s,d]/', $result ?? '')) { - throw new Exception('sprintf style localisation cannot be used in translations - detected in $result'); - } - - if ($failUnlessSprintf) { - // Note: After removing deprecated code, you can move this error up into the is-associative check - // Neither default nor translated strings were %s substituted, and our array isn't associative - throw new InvalidArgumentException('Injection must be an associative array'); - } - return $result; } diff --git a/src/includes/functions.php b/src/includes/functions.php index 86c93de0950..dc57fdea64f 100644 --- a/src/includes/functions.php +++ b/src/includes/functions.php @@ -60,6 +60,6 @@ function project() */ function _t($entity, $arg = null) { - // Pass args directly to handle deprecation + // Pass args directly as we allow variable args. return call_user_func_array([i18n::class, '_t'], func_get_args()); }