Skip to content

Translation reference

Text

Translates simple text or string properties. This is the most common type.

Typetext
ClassEnhavo\Bundle\TranslationBundle\Translation\Type\TextTranslationType
ParentEnhavo\Bundle\TranslationBundle\Translation\Type\TranslationType
Optionshtml, allow_fallback, allow_auto_translate, overwrite, context_groups
php
#[Translate('text')]
private ?string $title = null;

#[Translate('text', ['html' => true, 'allow_fallback' => true])]
private ?string $description = null;
yaml
properties:
    title:
        type: text
    description:
        type: text
        html: true
        allow_fallback: true

allow_fallback

type: boolean default: false

Whether to fall back to the default locale if no translation exists.

allow_auto_translate

type: boolean default: true

Only if true, the auto-translation will be applied to this property.

html

type: boolean default: false

Whether the content should be treated as HTML. This is useful for auto translation.

overwrite

type: boolean default: false

Set to true to overwrite existing translations during auto-translation.

context_groups

type: array default: ['endpoint', 'translation_context']

Use a serialization group to generate an output that is used as a context for auto translation.

Slug

Extends text and is specialized for URL slugs. Supports all options from text.

Typeslug
ClassEnhavo\Bundle\TranslationBundle\Translation\Type\SlugTranslationType
ParentEnhavo\Bundle\TranslationBundle\Translation\Type\TextTranslationType
php
#[Translate('slug', ['allow_fallback' => true])]
private ?string $slug = null;
yaml
properties:
    slug:
        type: slug
        allow_fallback: true

Route

Translates route objects.

Typeroute
ClassEnhavo\Bundle\TranslationBundle\Translation\Type\RouteTranslationType
ParentEnhavo\Bundle\TranslationBundle\Translation\Type\TranslationType
Optionsallow_null
php
#[Translate('route')]
private ?Route $route = null;
yaml
properties:
    route:
        type: route

allow_null

type: boolean default: false

Whether null routes are allowed.

File

Translates file or media associations, so different files can be used per locale.

Typefile
ClassEnhavo\Bundle\TranslationBundle\Translation\Type\FileTranslationType
ParentEnhavo\Bundle\TranslationBundle\Translation\Type\TranslationType
php
#[Translate('file')]
private ?File $image = null;
yaml
properties:
    image:
        type: file

Model

Recursively translates nested model objects and collections. Use this for related entities that themselves contain translatable properties, such as content blocks or tree structures.

Typemodel
ClassEnhavo\Bundle\TranslationBundle\Translation\Type\ModelTranslationType
ParentEnhavo\Bundle\TranslationBundle\Translation\Type\TranslationType
php
#[Translate('model')]
private Collection $content;
yaml
properties:
    content:
        type: model