Skip to content

Commit 6fd285a

Browse files
committed
Consolidate translation docs + review of the contents
1 parent a9cce3c commit 6fd285a

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

translation.rst

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,17 @@ are located:
103103
;
104104
};
105105
106-
The locale used in translations is the one stored on the request. This is
107-
typically set via a ``_locale`` attribute on your routes (see :ref:`translation-locale-url`).
108-
109106
.. _translation-basic:
110107

111108
Basic Translation
112109
-----------------
113110

114-
Translation of text is done through the ``translator`` service
115-
(:class:`Symfony\\Component\\Translation\\Translator`). To translate a block
116-
of text (called a *message*), use the
111+
Translation of text is done through the ``translator`` service
112+
(:class:`Symfony\\Component\\Translation\\Translator`). To translate a block of
113+
text (called a *message*), use the
117114
:method:`Symfony\\Component\\Translation\\Translator::trans` method. Suppose,
118-
for example, that you're translating a static message from inside a controller::
115+
for example, that you're translating a static message from inside a
116+
controller::
119117

120118
// ...
121119
use Symfony\Contracts\Translation\TranslatorInterface;
@@ -251,25 +249,19 @@ The Translation Process
251249
To actually translate the message, Symfony uses the following process when
252250
using the ``trans()`` method:
253251

254-
#. The ``locale`` of the current user, which is stored on the request is determined;
252+
#. The ``locale`` of the current user, which is stored on the request is
253+
determined; this is typically set via a ``_locale`` attribute on your routes
254+
(see :ref:`translation-locale-url`);
255255

256-
#. A catalog (e.g. big collection) of translated messages is loaded from translation
257-
resources defined for the ``locale`` (e.g. ``fr_FR``). Messages from the
258-
:ref:`fallback locale <translation-fallback>` are also loaded and
259-
added to the catalog if they don't already exist. The end result is a large
260-
"dictionary" of translations. This catalog is cached in production to
261-
minimize performance impact.
256+
#. A catalog of translated messages is loaded from translation resources
257+
defined for the ``locale`` (e.g. ``fr_FR``). Messages from the
258+
:ref:`fallback locale <translation-fallback>` are also loaded and added to
259+
the catalog if they don't already exist. The end result is a large
260+
"dictionary" of translations.
262261

263262
#. If the message is located in the catalog, the translation is returned. If
264263
not, the translator returns the original message.
265264

266-
.. tip::
267-
268-
When translating strings that are not in the default domain (``messages``),
269-
you must specify the domain as the third argument of ``trans()``::
270-
271-
$translator->trans('Symfony is great', [], 'admin');
272-
273265
.. _message-placeholders:
274266
.. _pluralization:
275267

@@ -297,22 +289,6 @@ To manage these situations, Symfony follows the `ICU MessageFormat`_ syntax by
297289
using PHP's :phpclass:`MessageFormatter` class. Read more about this in
298290
:doc:`/translation/message_format`.
299291

300-
.. tip::
301-
302-
If you don't use the ICU MessageFormat syntax in your translation files,
303-
pass a parameter named "%count%" to select the best plural form of the message:
304-
305-
.. code-block:: twig
306-
307-
{{ message|trans({'%name%': '...', '%count%': 1}, 'app') }}
308-
309-
The ``message`` variable must include all the different versions of this
310-
message based on the value of the ``count`` parameter. For example:
311-
312-
.. code-block:: text
313-
314-
{0}%name% has no apples|{1}%name% has one apple|]1,Inf[ %name% has %count% apples
315-
316292
.. _translatable-objects:
317293

318294
Translatable Objects

0 commit comments

Comments
 (0)