src/Controller/TranslationYamlController.php line 49
<?php
namespace App\Controller;
use App\Repository\SettingsRepository;
use App\Service\FlexySettingsProvider;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Yaml\Yaml;
#[Route(path: '/{_locale}')]
class TranslationYamlController extends AbstractController
{
#[Route(path: '/api-trans/translations-yaml', name: 'api_translations_yaml')]
public function api_translations_yaml(Request $request,FlexySettingsProvider $flexySettingsProvider)
{
// Construct the path to the YAML translation file
$nameSpaceTrans = strtolower($flexySettingsProvider->get()->getProjectName());
$yamlFilePath = $this->getParameter('kernel.project_dir') . '/translations/'.$nameSpaceTrans. '/'.$nameSpaceTrans. '.' . $request->getLocale() . '.yaml';
// Check if the YAML file exists
if (!file_exists($yamlFilePath)) {
return $this->json([]);
}
// Read and parse the YAML file
$yamlContent = file_get_contents($yamlFilePath);
$translations = Yaml::parse($yamlContent);
// Return translations as JSON response
// Return translations as JSON response using $this->json()
return $this->json($translations);
}
#[Route(path: '/api-trans/translations-yaml-admin', name: 'api_translations_yaml_admin')]
public function api_translations_yaml_admin(Request $request,FlexySettingsProvider $flexySettingsProvider)
{
// Construct the path to the YAML translation file
$nameSpaceTrans = strtolower($flexySettingsProvider->get()->getProjectName());
$yamlFilePath = $this->getParameter('kernel.project_dir') . '/translations/'.$nameSpaceTrans. '/'.$nameSpaceTrans. '-admin.' . $request->getLocale() . '.yaml';
// Check if the YAML file exists
if (!file_exists($yamlFilePath)) {
return $this->json([]);
}
// Read and parse the YAML file
$yamlContent = file_get_contents($yamlFilePath);
$translations = Yaml::parse($yamlContent);
// Return translations as JSON response
// Return translations as JSON response using $this->json()
return $this->json($translations);
}
}