From 7268f055d4484ba0134feea34ca47c58f247c037 Mon Sep 17 00:00:00 2001 From: Kevin Hamilton Date: Thu, 16 May 2024 13:23:25 +0100 Subject: [PATCH] #7: Pass translated message through placeholder compile Signed-off-by: Kevin Hamilton --- src/Translator/PlaceholderPluginManager.php | 3 ++- src/Translator/Translator.php | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Translator/PlaceholderPluginManager.php b/src/Translator/PlaceholderPluginManager.php index be6a6dd4..802bb372 100644 --- a/src/Translator/PlaceholderPluginManager.php +++ b/src/Translator/PlaceholderPluginManager.php @@ -21,12 +21,13 @@ * * @template InstanceType of Placeholder\PlaceholderInterface * @extends AbstractPluginManager - * @method Placeholder\PlaceholderInterface get(string $name) + * @method Placeholder\PlaceholderInterface get(string $name, ?array $options = null) */ class PlaceholderPluginManager extends AbstractPluginManager { /** @inheritDoc */ protected $aliases = [ + 'segment' => Placeholder\SegmentPlaceholder::class, 'colon' => Placeholder\SegmentPlaceholder::class, 'laravel' => Placeholder\SegmentPlaceholder::class, 'handlebar' => Placeholder\HandlebarPlaceholder::class, diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index c54cc7fb..2923821e 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -446,7 +446,13 @@ protected function getTranslatedMessage( } if (isset($this->messages[$textDomain][$locale][$message])) { - return $this->messages[$textDomain][$locale][$message]; + return $this->placeholder ? + $this->placeholder->compile( + $locale, + $this->messages[$textDomain][$locale][$message], + $placeholders + ) : + $this->messages[$textDomain][$locale][$message]; } /** @@ -463,7 +469,13 @@ protected function getTranslatedMessage( * ] */ if (isset($this->messages[$textDomain][$locale][$textDomain . "\x04" . $message])) { - return $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]; } if ($this->isEventManagerEnabled()) {