Skip to content

Commit

Permalink
Respect instance of Message for translations
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed Aug 12, 2024
1 parent bfa1ad7 commit 6303e70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 12 additions & 7 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6303e70

Please sign in to comment.