Skip to content

Commit 55a30ab

Browse files
wouterjweaverryan
authored andcommitted
Reread usage docs
1 parent 56b02be commit 55a30ab

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

components/translation/introduction.rst

+30-1
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,38 @@ this fallback locale by calling
140140
// ...
141141
$translator->setFallbackLocale('en_EN');
142142

143+
.. _using-message-domains:
144+
145+
Using Message Domains
146+
---------------------
147+
148+
As you've seen, message files are organized into the different locales that
149+
they translate. The message files can also be organized further into "domains".
150+
151+
The domain is specific in the fourth argument of the ``addResource()`` method.
152+
The default domain is ``messages``. For example, suppose that, for organization,
153+
translations were split into three different domains: ``messages``, ``admin``
154+
and ``navigation``. The French translation would be loaded like this::
155+
156+
// ...
157+
$translator->addLoader('xliff', new XliffLoader());
158+
159+
$translator->addResource('xliff', 'messages.fr.xliff', 'fr_FR');
160+
$translator->addResource('xliff', 'admin.fr.xliff', 'fr_FR', 'admin');
161+
$translator->addResource('xliff', 'navigation.fr.xliff', 'fr_FR', 'navigation');
162+
163+
When translating strings that are not in the default domain (``messages``),
164+
you must specify the domain as the third argument of ``trans()``::
165+
166+
$translator->trans('Symfony2 is great', array(), 'admin');
167+
168+
Symfony2 will now look for the message in the ``admin`` domain of the
169+
specified locale.
170+
can use ``-Inf`` and ``+Inf`` for the infinite.
171+
143172
Usage
144173
-----
145174

146-
Read how to use the Translation components in ":doc:`/components/translation/usage`"
175+
Read how to use the Translation components in ":doc:`/components/translation/usage`".
147176

148177
.. _Packagist: https://packagist.org/packages/symfony/translation

components/translation/usage.rst

+4-32
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Usage
55
=====
66

7-
Imagine you want to translate the string *"Symfony2 is great"* into french::
7+
Imagine you want to translate the string *"Symfony2 is great"* into French::
88

99
use Symfony\Component\Translation\Translator;
1010
use Symfony\Component\Translation\MessageSelector;
@@ -79,7 +79,8 @@ is done just as before:
7979
.. note::
8080

8181
The placeholders can take on any form as the full message is reconstructed
82-
using the PHP :phpfunction:`strtr function<strtr>`.
82+
using the PHP :phpfunction:`strtr function<strtr>`. But the ``%...%`` form
83+
is recommend, to avoid problems when using Twig.
8384

8485
As you've seen, creating a translation is a two-step process:
8586

@@ -342,37 +343,8 @@ Or numbers between two other numbers:
342343
The left delimiter can be ``[`` (inclusive) or ``]`` (exclusive). The right
343344
delimiter can be ``[`` (exclusive) or ``]`` (inclusive). Beside numbers, you
344345

345-
.. _using-message-domains:
346-
347-
Using Message Domains
348-
=====================
349-
350-
As you've seen, message files are organized into the different locales that
351-
they translate. The message files can also be organized further into "domains".
352-
353-
The domain is specific in the fourth argument of the ``addResource()`` method.
354-
The default domain is ``messages``. For example, suppose that, for organization,
355-
translations were split into three different domains: ``messages``, ``admin``
356-
and ``navigation``. The French translation would be loaded like this::
357-
358-
// ...
359-
$translator->addLoader('xliff', new XliffLoader());
360-
361-
$translator->addResource('xliff', 'messages.fr.xliff', 'fr_FR');
362-
$translator->addResource('xliff', 'admin.fr.xliff', 'fr_FR', 'admin');
363-
$translator->addResource('xliff', 'navigation.fr.xliff', 'fr_FR', 'navigation');
364-
365-
When translating strings that are not in the default domain (``messages``),
366-
you must specify the domain as the third argument of ``trans()``::
367-
368-
$translator->trans('Symfony2 is great', array(), 'admin');
369-
370-
Symfony2 will now look for the message in the ``admin`` domain of the
371-
specified locale.
372-
can use ``-Inf`` and ``+Inf`` for the infinite.
373-
374346
Forcing the Translator Locale
375-
=============================
347+
-----------------------------
376348

377349
When translating a message, the Translator uses the specified locale or the
378350
``fallback`` locale if necessary. You can also manually specify the locale to

0 commit comments

Comments
 (0)