PHP code example of locastic / symfony-translation-bundle

1. Go to this page and download the library: Download locastic/symfony-translation-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

locastic / symfony-translation-bundle example snippets




declare(strict_types=1);

namespace App\TranslationMigrations;

use Locastic\SymfonyTranslationBundle\Provider\ThemesProviderInterface;
use Locastic\SymfonyTranslationBundle\TranslationMigration\AbstractTranslationMigration;

final class Version20230201074700 extends AbstractTranslationMigration
{
    public function up(): void
    {
        $this->addTranslation('test.translation', 'messages', 'en', 'This is a test translation', ThemesProviderInterface::NAME_DEFAULT);
    }
}



declare(strict_types=1);

namespace App\Controller;

use Locastic\SymfonyTranslationBundle\Form\Type\SearchTranslationType;
use Locastic\SymfonyTranslationBundle\Model\SearchTranslation;
use Locastic\SymfonyTranslationBundle\Utils\SearchTranslationsUtilsInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

final class IndexTranslationAction
{
    public function __construct(
        private SearchTranslationsUtilsInterface $searchTranslationsUtils,
        private Environment $twig,
        private FormFactoryInterface $formFactory,
    ) {
    }

    public function __invoke(Request $request): Response
    {
        $search = new SearchTranslation();
        $searchForm = $this->formFactory->create(SearchTranslationType::class, $search);
        $searchForm->handleRequest($request);

        $pagerFanta = $this->searchTranslationsUtils->searchTranslationsFromRequest($request, $search, $searchForm);

        return new Response($this->twig->render('{yourTemplate}', [
            'translations' => $pagerFanta,
            'resources' => $pagerFanta,
            'searchForm' => $searchForm->createView(),
        ]));
    }
}