Extension for symfony/translation package to load translations defined as constants list in PHP file.
To install and use this package, we recommend to use Composer:
composer require imponeer/symfony-translations-constants-loader
Otherwise you need to include manualy files from src/
directory.
// translations/en/messages.php
define('HELLO', 'Hello!');
define('GOODBYE', 'Goodbye!');
💡 You can create separate files for other locales, such as
translations/fr/messages.php
.
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!
If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try read GitHub documentation about git.
If you found any bug or have some questions, use issues tab and write there your questions.