Skip to content

Commit

Permalink
laminas#7: Ensure text without a translation is still compiled
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Hamilton <[email protected]>
  • Loading branch information
TotalWipeOut committed May 16, 2024
1 parent 7268f05 commit 3f9c7c9
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function translate($message, $textDomain = 'default', $locale = null)
return $this->translate($message, $textDomain, $fallbackLocale);
}

return $message;
return $this->compileMessage($message, is_array($textDomain) ? $textDomain : []);
}

/**
Expand Down Expand Up @@ -446,13 +446,11 @@ protected function getTranslatedMessage(
}

if (isset($this->messages[$textDomain][$locale][$message])) {
return $this->placeholder ?
$this->placeholder->compile(
$locale,
$this->messages[$textDomain][$locale][$message],
$placeholders
) :
$this->messages[$textDomain][$locale][$message];
return $this->compileMessage(
$this->messages[$textDomain][$locale][$message],
$placeholders,
$locale
);
}

/**
Expand All @@ -469,13 +467,11 @@ protected function getTranslatedMessage(
* ]
*/
if (isset($this->messages[$textDomain][$locale][$textDomain . "\x04" . $message])) {
return $this->placeholder ?
$this->placeholder->compile(
$locale,
$this->messages[$textDomain][$locale][$textDomain . "\x04" . $message],
$placeholders
) :
$this->messages[$textDomain][$locale][$textDomain . "\x04" . $message];
return $this->compileMessage(
$this->messages[$textDomain][$locale][$textDomain . "\x04" . $message],
$placeholders,
$locale
);
}

if ($this->isEventManagerEnabled()) {
Expand Down Expand Up @@ -849,4 +845,15 @@ public function setPlaceholder(PlaceholderInterface $placeholder)
{
$this->placeholder = $placeholder;
}

protected function compileMessage(string $message, array $placeholders, string $locale): string
{
return $this->placeholder ?
$this->placeholder->compile(
$locale,
$message,
$placeholders
) :
$message;
}
}

0 comments on commit 3f9c7c9

Please sign in to comment.