PHP code example of phpnomad / symfony-translation-integration

1. Go to this page and download the library: Download phpnomad/symfony-translation-integration 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/ */

    

phpnomad / symfony-translation-integration example snippets




use PHPNomad\Symfony\Translation\Strategies\TranslationStrategy;
use PHPNomad\Translations\Interfaces\HasLanguage;
use PHPNomad\Translations\Interfaces\HasTextDomain;
use PHPNomad\Translations\Interfaces\TranslationStrategy as TranslationStrategyInterface;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Translation\TranslatorInterface;

$container->bind(TranslatorInterface::class, function () {
    $translator = new Translator('en_US');
    $translator->addLoader('array', new ArrayLoader());
    $translator->addResource('array', ['hello' => 'Hello'], 'en_US', 'messages');

    return $translator;
});

$container->bind(HasTextDomain::class, MyTextDomainProvider::class);
$container->bind(HasLanguage::class, MyLanguageProvider::class);
$container->bind(TranslationStrategyInterface::class, TranslationStrategy::class);