<?php
namespace Harmonizely\Service\Common;
use Symfony\Contracts\Translation\TranslatorInterface;
class TranslateHelper
{
/**
* Instance
*
* @var TranslateHelper
*/
private static TranslateHelper $instance;
/**
* Translator
*
* @var TranslatorInterface
*/
private TranslatorInterface $translator;
/**
* Constructor
*
* @param TranslatorInterface $translator
*/
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* Init instance
*
* @return void
*/
public function init(): void
{
self::$instance = $this;
}
/**
* Translate method
*
* @param string $text
* @param array $parameters
* @param string|null $domain
* @param string|null $locale
* @return string
*/
public static function translate(string $text, array $parameters = [], string $domain = null, string $locale = null): string
{
return self::$instance->translator->trans($text, $parameters, $domain, $locale);
}
}
function trans(string $text, array $parameters = [], string $domain = null, string $locale = null): string
{
return TranslateHelper::translate($text, $parameters, $domain, $locale);
}