From 81ca0c8fbf2e9ef6f52976f586b6a77bbfc64be0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 8 Jan 2023 20:56:12 +0000 Subject: [PATCH] Language: do not parse translations if the text was a plain key this unintentionally allowed translations to reference other translations 1 level deep, which is not desired behaviour. This also improves performance for the cases where formatting isn't used. --- src/lang/Language.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lang/Language.php b/src/lang/Language.php index 301376364..d6e2b2214 100644 --- a/src/lang/Language.php +++ b/src/lang/Language.php @@ -144,8 +144,10 @@ class Language{ * @param (float|int|string|Translatable)[] $params */ public function translateString(string $str, array $params = [], ?string $onlyPrefix = null) : string{ - $baseText = $this->get($str); - $baseText = $this->parseTranslation(($onlyPrefix === null || str_starts_with($str, $onlyPrefix)) ? $baseText : $str, $onlyPrefix); + $baseText = ($onlyPrefix === null || str_starts_with($str, $onlyPrefix)) ? $this->internalGet($str) : null; + if($baseText === null){ //key not found, embedded inside format string, or doesn't match prefix + $baseText = $this->parseTranslation($str, $onlyPrefix); + } foreach($params as $i => $p){ $replacement = $p instanceof Translatable ? $this->translate($p) : (string) $p; @@ -157,7 +159,9 @@ class Language{ public function translate(Translatable $c) : string{ $baseText = $this->internalGet($c->getText()); - $baseText = $this->parseTranslation($baseText ?? $c->getText()); + if($baseText === null){ //key not found or embedded inside format string + $baseText = $this->parseTranslation($c->getText()); + } foreach($c->getParameters() as $i => $p){ $replacement = $p instanceof Translatable ? $this->translate($p) : $p;