Refactor helper drift in lib: centralize theme/translation and remove app() hotspots
This commit is contained in:
19
lib/Service/I18n/ServiceTranslator.php
Normal file
19
lib/Service/I18n/ServiceTranslator.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\I18n;
|
||||
|
||||
final class ServiceTranslator
|
||||
{
|
||||
public static function translate(string $text, mixed ...$args): string
|
||||
{
|
||||
if (function_exists('t')) {
|
||||
return t($text, ...$args);
|
||||
}
|
||||
|
||||
if ($args === []) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
return vsprintf($text, array_map(static fn (mixed $arg): string => (string) $arg, $args));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user