Skip to content

[Serializer] Add TranslatableNormalizer #18726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,20 @@ The Serializer component provides several built-in normalizers:
Also it can denormalize ``uuid`` or ``ulid`` strings to :class:`Symfony\\Component\\Uid\\Uuid`
or :class:`Symfony\\Component\\Uid\\Ulid`. The format does not matter.

:class:`Symfony\\Component\\Serializer\\Normalizer\\TranslatableNormalizer`
This normalizer converts objects that implement
:class:`Symfony\\Contracts\\Translation\\TranslatableInterface` into
translated strings, using the
:method:`Symfony\\Contracts\\Translation\\TranslatableInterface::trans`
method. You can define the locale to use to translate the object by
setting the ``TranslatableNormalizer::NORMALIZATION_LOCALE_KEY`` serializer
context option.

.. versionadded:: 6.4

The :class:`Symfony\\Component\\Serializer\\Normalizer\\TranslatableNormalizer`
was introduced in Symfony 6.4.

.. note::

You can also create your own Normalizer to use another structure. Read more at
Expand Down
1 change: 1 addition & 0 deletions serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ As well as the following normalizers:
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ConstraintViolationListNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\BackedEnumNormalizer`
* :class:`Symfony\\Component\\Serializer\\Normalizer\\TranslatableNormalizer`

Other :ref:`built-in normalizers <component-serializer-normalizers>` and
custom normalizers and/or encoders can also be loaded by tagging them as
Expand Down