wexample / symfony-translations
A translations service overrides to support translations files includes and multiple domains in Symfony translations
Requires
- symfony/translation: >=6.2
- wexample/php-helpers: ^1.0.43
- wexample/php-yaml: ^1.0.16
- wexample/symfony-helpers: ^1.0.45
- wexample/symfony-testing: ^1.0.39
Requires (Dev)
- phpunit/phpunit: ^9.5
- wexample/symfony-testing: ^1.0.26
- dev-master
- 1.0.39
- 1.0.38
- 1.0.37
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.1.51
- 0.1.50
- 0.1.48
- 0.1.47
- 0.1.46
- 0.1.45
- 0.1.44
- 0.1.43
- 0.1.42
- 0.1.41
- 0.1.40
- 0.1.39
- 0.1.38
- 0.1.37
- 0.1.36
- 0.1.35
- 0.1.34
- 0.1.33
- 0.1.31
- 0.1.30
- 0.1.29
- 0.1.28
- 0.1.27
- 0.1.26
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-main
This package is auto-updated.
Last update: 2025-04-24 14:08:05 UTC
README
An extension for Symfony's Translation component that adds support for YAML includes, references, and inheritance through integration with the wexample/php-yaml package.
Developed by Wexample.
Features
- YAML Includes: Reference translations from other YAML files using the
@domain::key
syntax - Domain Aliases: Create aliases for translation domains to simplify references
- Context-Aware Translations: Automatically resolve translation paths based on the current controller/route
- Inheritance: Extend translation files with the
~extends
directive - Debug Tools: Twig functions to debug translation domains, locales, and catalogs
- Bundle Integration: Automatic handling of bundle translations with proper domain resolution
- Fallback Mechanism: Returns the full domain and key if a translation is not found, making debugging easier
Installation
composer require wexample/symfony-translations
Basic Usage
In Twig Templates
{# Use domain aliases for cleaner translation references #} {{ '@page::body' | trans }} {# Use domain and key directly #} {{ 'WexampleSymfonyDesignSystemBundle.pages.demo.index::page_title' | trans }} {# Debug translation information #} {{ dump_trans() }} {{ dump_trans_locales() }} {{ dump_trans_domains() }}
In YAML Files
# Reference another translation title: "@common.labels::welcome" # Use the same key from another domain description: "@common.labels::%" # Extend another translation file ~extends: "@common.base"
Domain Resolution
The translator automatically handles domain resolution in various contexts:
-
Bundle Translations: When using translations from bundles, the system automatically handles paths with or without the 'assets' directory:
// Both will work and point to the same translation $translator->trans('WexampleSymfonyDesignSystemBundle.pages.demo.index::page_title'); $translator->trans('WexampleSymfonyDesignSystemBundle.assets.pages.demo.index::page_title');
-
Domain Stack: You can push domains onto a stack for context-aware translations:
$translator->setDomain('page', 'app.pages.home'); $translator->trans('@page::title'); // Will use 'app.pages.home' as the domain
Console Commands
The package provides several useful console commands to help with translation management:
# Show all translations for 'en' locale php bin/console translations:catalogue en # Show translations for 'en' locale in the 'messages' domain php bin/console translations:catalogue en --domain=messages
php bin/console translations:locales
# Basic usage php bin/console translations:trans en "app.welcome" # With domain and parameters php bin/console translations:trans en "app.greeting" --domain=messages --parameters='{"name":"John"}'
Testing
phpunit