therichcourt / translations-testing-bundle
A simple way to test translations in your Symfony application
Requires
- symfony/framework-bundle: ^5.4|^6.0|^7.0
- twig/intl-extra: ^3.0
Requires (Dev)
- php: ~8.1|~8.2|~8.3
- ext-xdebug: *
- matthiasnoback/symfony-config-test: ^4.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- squizlabs/php_codesniffer: ^3.5
- symfony/browser-kit: ^5.4|^6.0|^7.0
- symfony/phpunit-bridge: ^5.1|^6.0|^7.0
- symfony/routing: ^5.4|^6.0|^7.0
- symfony/translation: ^5.4|^6.0|^7.0
- symfony/twig-bundle: ^5.4|^6.0|^7.0
- symfony/yaml: ^5.4|^6.0|^7.0
README
A simple way to test translations in your Symfony application.
A Symfony bundle, which provides a page in your application to input translation keys and arguments and instantly see the translation results. Useful for testing / debugging ICU based translations with multiple arguments, without having to change the state of your application for each variant, or hunt down the page which uses the translation.
Installation
composer require --dev therichcourt/translations-testing-bundle
Configuration
1. Register the bundle in config/bundles.php
TheRichCourt\TranslationsTestingBundle\TranslationsTestingBundle::class => ['dev' => true],
2. Create a configuration for the bundle in config/packages/dev/translations_testing.yaml
translations_testing: locales: - 'en' - 'es' - 'fr' # ...
3. Set up the routes in config/routes/dev/routes.yaml
_translations_testing: resource: '@TranslationsTestingBundle/Resources/config/routes.yaml' # Change the prefix to wherever you'd like the translations testing page to be. # Keep in mind any path prefixes you have on your site, for example the page may # end up at `/en_GB/tests/translations` prefix: /tests/translations
That's all the set-up done. You can now go to the page on your site, and start testing translations.
Features
- Translate your keys into all locales
- Test ICU translations, by passing arguments
- Highlights potential issues, e.g. if the translated message matches the key (which could mean you're missing a translation definiton)
N.B. this is not an automated testing solution - it just makes it much easier for you to manually test the results of your translations.
Contributing
Any PRs with fixes or improvements gratefully received.
Setting the project up
Simply fork, clone and then run:
docker build -t translations-testing-bundle .
docker run -it --name translations-testing-bundle --volume .:/usr/src/app translations-testing-bundle
Connect to the container, then in there, run:
composer install
Testing
Run composer test
to run all tests and lints.