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.
This commit is contained in:
Dylan K. Taylor 2021-08-10 14:26:47 +01:00
parent de61417bb6
commit d39080c45a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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;
}
}