From 6303e702bea24c0e90b2aa50fee5c6ef542398f9 Mon Sep 17 00:00:00 2001 From: juniwalk Date: Mon, 12 Aug 2024 14:34:34 +0200 Subject: [PATCH] Respect instance of Message for translations --- composer.json | 1 + src/Html.php | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 3b979ac..efb711a 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ }, "require-dev": { + "contributte/translation": "^2.0", "juniwalk/orm": ">=0.10 <1.0 | ^1.0", "latte/latte": "^3.0", "nette/application": "^3.2", diff --git a/src/Html.php b/src/Html.php index 2042a6e..02fba90 100644 --- a/src/Html.php +++ b/src/Html.php @@ -7,6 +7,7 @@ namespace JuniWalk\Utils; +use Contributte\Translation\Wrappers\Message; use JuniWalk\Utils\Enums\Color; use JuniWalk\Utils\Enums\Interfaces\Currency; use JuniWalk\Utils\Enums\Interfaces\LabeledEnum; @@ -299,20 +300,24 @@ public static function progressBar(float $percent, Color $color): self /** - * @param Stringable|scalar|null $value + * @param Stringable|scalar|null $message */ - private static function translate(mixed $value, bool $translate = true): null|string|Stringable + private static function translate(mixed $message, bool $translate = true): null|string|Stringable { - $value = strval($value) ?: null; + $content = strval($message) ?: null; if (!$translate || static::$disableTranslation || !static::$translator) { - return $value; + return $content; } - if (!$value || !Strings::match($value, static::TranslationRegEx)) { - return $value; + if (!$content || !Strings::match($content, static::TranslationRegEx)) { + return $content; } - return static::$translator->translate($value); + if ($message instanceof Message) { + $content = $message; + } + + return static::$translator->translate($content); } }