1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Core;
6:
7: use Atk4\Core\Translator\Translator;
8:
9: /**
10: * If a class use this trait, string can be translated calling method translate.
11: */
12: trait TranslatableTrait
13: {
14: /**
15: * Translate the given message.
16: *
17: * @param string $message The message to be translated
18: * @param array<string, mixed> $parameters Array of parameters used to translate message
19: * @param string|null $domain The domain for the message or null to use the default
20: * @param string|null $locale The locale or null to use the default
21: *
22: * @return string The translated string
23: */
24: public function _(string $message, array $parameters = [], string $domain = null, string $locale = null): string
25: {
26: if (TraitUtil::hasAppScopeTrait($this) && $this->issetApp() && method_exists($this->getApp(), '_')) {
27: return $this->getApp()->_($message, $parameters, $domain, $locale);
28: }
29:
30: return Translator::instance()->_($message, $parameters, $domain, $locale);
31: }
32: }
33: