first commit

This commit is contained in:
2025-11-11 17:00:02 +01:00
commit 921a74bbe2
549 changed files with 59325 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Services;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\Loader\JsonFileLoader;
class TranslationService
{
private string $langDir;
private array $supportedLocales;
private string $defaultLocale;
public function __construct(string $langDir, array $supportedLocales, string $defaultLocale)
{
$this->langDir = $langDir;
$this->supportedLocales = $supportedLocales;
$this->defaultLocale = $defaultLocale;
}
public function getTranslator(string $locale): Translator
{
$translator = new Translator($locale);
$translator->addLoader('json', new JsonFileLoader());
foreach ($this->supportedLocales as $supportedLocale) {
$filePath = $this->langDir . '/' . $supportedLocale . '.json';
if (file_exists($filePath)) {
$translator->addResource('json', $filePath, $supportedLocale);
}
}
return $translator;
}
}