-
Notifications
You must be signed in to change notification settings - Fork 3
Translate annotations
BowlOfSoup edited this page Apr 10, 2026
·
2 revisions
Note: Legacy docblock annotations are still supported. But since version 6 you should use PHP attributes.
By default, the translation must be in a Resources/translations/messages.en.xliff. You can specify a custom domain (xliff file)
/**
* @Bos\Normalize(group={"somegroup"}, name="automobile")
* @Bos\Translate(group={"translation"}, domain="some_domain")
*/
#[Bos\Normalize(group: ['somegroup'], name: 'automobile')]
#[Bos\Translate(group: ['translation'], domain: 'some_domain')]
private $propertyToBeNormalized;
This tries to find the translation in Resources/translations/some_domain.en.xliff.
You can specify your locale, if you did not set that globally in Symfony.
/**
* @Bos\Normalize(group={"somegroup"}, name="automobile")
* @Bos\Translate(group={"translation"}, domain="some_domain", locale="nl")
*/
#[Bos\Normalize(group: ['somegroup'], name: 'automobile')]
#[Bos\Translate(group: ['translation'], domain: 'some_domain', locale: 'nl')]
private $propertyToBeNormalized;
This will search for the translation in Resources/translations/some_domain.nl.xliff, notice the nl in the file name (Dutch language).