From d39080c45aef572261cc66d9b5219afa03aeacd5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 10 Aug 2021 14:26:47 +0100 Subject: [PATCH] TranslationContainer: Add support for named translation parameters this also fixes use cases like: [1] = something; [0] = match(...) It made no sense whatsoever to discard the keys anyway. Language::translateString() already supported named parameters since forever anyway. --- src/lang/TranslationContainer.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lang/TranslationContainer.php b/src/lang/TranslationContainer.php index 3e2905f6f..bcafb38c0 100644 --- a/src/lang/TranslationContainer.php +++ b/src/lang/TranslationContainer.php @@ -36,11 +36,8 @@ final class TranslationContainer{ public function __construct(string $text, array $params = []){ $this->text = $text; - $i = 0; - foreach($params as $str){ - $this->params[$i] = (string) $str; - - ++$i; + foreach($params as $k => $str){ + $this->params[$k] = (string) $str; } } @@ -55,7 +52,7 @@ final class TranslationContainer{ return $this->params; } - public function getParameter(int $i) : ?string{ + public function getParameter(int|string $i) : ?string{ return $this->params[$i] ?? null; } }