src/Controller/v1/Localization/LanguageController.php
<?php
declare(strict_types = 1);
/**
* /src/Controller/v1/Localization/LanguageController.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
namespace App\Controller\v1\Localization;
use App\Service\Localization;
use OpenApi\Attributes as OA;
use OpenApi\Attributes\JsonContent;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
/**
* @package App\Controller\v1\Localization
* @author TLe, Tarmo Leppänen <tarmo.leppanen@pinja.com>
*/
#[AsController]
#[OA\Tag(name: 'Localization')]
class LanguageController
{
public function __construct(
private readonly Localization $localization,
) {
}
/**
* Endpoint action to get supported languages. This is for use to choose
* what language your frontend application can use within its translations.
*/
#[Route(
path: '/v1/localization/language',
methods: [Request::METHOD_GET],
)]
#[OA\Response(
response: 200,
description: 'List of language strings.',
content: new JsonContent(
type: 'array',
items: new OA\Items(
type: 'string',
example: 'en',
),
example: ['en', 'fi'],
),
)]
public function __invoke(): JsonResponse
{
return new JsonResponse($this->localization->getLanguages());
}
}