PHP code example of imponeer / symfony-translations-constants-loader

1. Go to this page and download the library: Download imponeer/symfony-translations-constants-loader 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/ */

    

imponeer / symfony-translations-constants-loader example snippets


// translations/en/messages.php

define('HELLO', 'Hello!');
define('GOODBYE', 'Goodbye!');

use Symfony\Component\Translation\Translator;
use Imponeer\SymfonyTranslationsConstantsLoader\PHPFileLoader;

$translator = new Translator('en');

// Register the loader for the 'php_consts' format
$translator->addLoader('php_consts', new PHPFileLoader());

// Add your translation resource
$translator->addResource('php_consts', __DIR__ . '/translations/en/messages.php', 'en');

// Use translations
echo $translator->trans('HELLO');   // Outputs: Hello!
echo $translator->trans('GOODBYE'); // Outputs: Goodbye!