imponeer / symfony-translations-constants-loader
symfony/translation extension to load PHP files that are defined all translations as constants
Installs: 23 384
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.3
- ext-json: *
- ext-mbstring: *
- ext-pcre: *
- symfony/translation: ^7.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: >=11
README
Symfony Translations Constants Loader
Extension for symfony/translation package to load translations defined as constants list in PHP file.
Installation
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.
Usage Example
1. Create a file with define()
constants:
// translations/en/messages.php define('HELLO', 'Hello!'); define('GOODBYE', 'Goodbye!');
💡 You can create separate files for other locales, such as
translations/fr/messages.php
.
2. Load the constants using the PHPFileLoader:
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!
How to contribute?
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.