@@ -22,8 +22,8 @@ into the language of the user::
22
22
23
23
The term *locale * refers roughly to the user's language and country. It
24
24
can be any string that your application uses to manage translations and
25
- other format differences (e.g. currency format). The `ISO639 -1 `_
26
- *language * code, an underscore (``_ ``), then the `ISO3166 Alpha -2 `_
25
+ other format differences (e.g. currency format). The `ISO 639 -1 `_
26
+ *language * code, an underscore (``_ ``), then the `ISO 3166-1 alpha -2 `_
27
27
*country * code (e.g. ``fr_FR `` for French/France) is recommended.
28
28
29
29
In this chapter, you'll learn how to use the Translation component in the
@@ -41,7 +41,8 @@ to learn even more. Overall, the process has several steps:
41
41
for each supported locale that translate each message in the application;
42
42
43
43
#. Determine, :ref: `set and manage the user's locale <book-translation-user-locale >`
44
- for the request and optionally on the user's entire session.
44
+ for the request and optionally
45
+ :doc: `on the user's entire session </cookbook/session/locale_sticky_session >`.
45
46
46
47
.. _book-translation-configuration :
47
48
@@ -147,11 +148,12 @@ different formats, XLIFF being the recommended format:
147
148
# messages.fr.yml
148
149
Symfony2 is great : J'aime Symfony2
149
150
150
- For information on where these files should be located, see :ref: `book-translation-resource-locations `.
151
+ For information on where these files should be located, see
152
+ :ref: `book-translation-resource-locations `.
151
153
152
154
Now, if the language of the user's locale is French (e.g. ``fr_FR `` or ``fr_BE ``),
153
155
the message will be translated into ``J'aime Symfony2 ``. You can also translate
154
- message inside your :ref: `templates <book-translation-tags >`.
156
+ the message inside your :ref: `templates <book-translation-tags >`.
155
157
156
158
The Translation Process
157
159
~~~~~~~~~~~~~~~~~~~~~~~
@@ -278,8 +280,8 @@ texts* and complex expressions:
278
280
Using the translation tags or filters have the same effect, but with
279
281
one subtle difference: automatic output escaping is only applied to
280
282
translations using a filter. In other words, if you need to be sure
281
- that your translated is *not * output escaped, you must apply the
282
- ``raw `` filter after the translation filter:
283
+ that your translated message is *not * output escaped, you must apply
284
+ the ``raw `` filter after the translation filter:
283
285
284
286
.. code-block :: jinja
285
287
@@ -290,7 +292,7 @@ texts* and complex expressions:
290
292
291
293
{% set message = '<h3>foo</h3>' %}
292
294
293
- {# strings and variables translated via a filter is escaped by default #}
295
+ {# strings and variables translated via a filter are escaped by default #}
294
296
{{ message|trans|raw }}
295
297
{{ '<h3>bar</h3>'|trans|raw }}
296
298
@@ -303,7 +305,7 @@ texts* and complex expressions:
303
305
{% trans_default_domain "app" %}
304
306
305
307
Note that this only influences the current template, not any "included"
306
- templates (in order to avoid side effects).
308
+ template (in order to avoid side effects).
307
309
308
310
PHP Templates
309
311
~~~~~~~~~~~~~
@@ -346,7 +348,7 @@ The filename of the translation files is also important: each message file
346
348
must be named according to the following path: ``domain.locale.loader ``:
347
349
348
350
* **domain **: An optional way to organize messages into groups (e.g. ``admin ``,
349
- ``navigation `` or the default ``messages ``) - see " :ref: `using-message-domains `" ;
351
+ ``navigation `` or the default ``messages ``) - see :ref: `using-message-domains `;
350
352
351
353
* **locale **: The locale that the translations are for (e.g. ``en_GB ``, ``en ``, etc);
352
354
@@ -374,7 +376,7 @@ taste. For more options, see :ref:`component-translator-message-catalogs`.
374
376
375
377
Each time you create a *new * translation resource (or install a bundle
376
378
that includes a translation resource), be sure to clear your cache so
377
- that Symfony can discover the new translation resource :
379
+ that Symfony can discover the new translation resources :
378
380
379
381
.. code-block :: bash
380
382
@@ -481,11 +483,13 @@ by the routing system using the special ``_locale`` parameter:
481
483
return $collection;
482
484
483
485
When using the special ``_locale `` parameter in a route, the matched locale
484
- will *automatically be set on the user's session *. In other words, if a user
486
+ will *automatically be set on the Request * and can be retrieved via the
487
+ :method: `Symfony\\ Component\\ HttpFoundation\\ Request::getLocale ` method.
488
+ In other words, if a user
485
489
visits the URI ``/fr/contact ``, the locale ``fr `` will automatically be set
486
- as the locale for the user's session .
490
+ as the locale for the current request .
487
491
488
- You can now use the user's locale to create routes to other translated pages
492
+ You can now use the locale to create routes to other translated pages
489
493
in your application.
490
494
491
495
Setting a Default Locale
@@ -651,7 +655,7 @@ steps:
651
655
* Abstract messages in your application by wrapping each in either the
652
656
:method: `Symfony\\ Component\\ Translation\\ Translator::trans ` or
653
657
:method: `Symfony\\ Component\\ Translation\\ Translator::transChoice ` methods
654
- (learn about this in " :doc: `/components/translation/usage `" );
658
+ (learn about this in :doc: `/components/translation/usage `);
655
659
656
660
* Translate each message into multiple locales by creating translation message
657
661
files. Symfony2 discovers and processes each file because its name follows
@@ -661,6 +665,6 @@ steps:
661
665
be set on the user's session.
662
666
663
667
.. _`i18n` : http://en.wikipedia.org/wiki/Internationalization_and_localization
664
- .. _`ISO3166 Alpha -2` : http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
665
- .. _`ISO639 -1` : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
668
+ .. _`ISO 3166-1 alpha -2` : http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
669
+ .. _`ISO 639 -1` : http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
666
670
.. _`Translatable Extension` : https://github.com/l3pp4rd/DoctrineExtensions
0 commit comments