Skip to content

Commit 0bea6e4

Browse files
wouterjweaverryan
authored andcommitted
Rewrote component article
1 parent 091a798 commit 0bea6e4

File tree

2 files changed

+163
-194
lines changed

2 files changed

+163
-194
lines changed

book/translation.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,43 @@ not exist in the user's locale.
9393
The locale used in translations is the one stored on the request. This is
9494
typically set via a ``_locale`` attribute on your routes (see :ref:`book-translation-locale-url`).
9595

96+
Fallback and Default Locale
97+
---------------------------
98+
99+
If the locale hasn't been set explicitly in the session, the ``fallback_locale``
100+
configuration parameter will be used by the ``Translator``. The parameter
101+
defaults to ``en`` (see `Configuration`_).
102+
103+
Alternatively, you can guarantee that a locale is set on each user's request
104+
by defining a ``default_locale`` for the framework:
105+
106+
.. configuration-block::
107+
108+
.. code-block:: yaml
109+
110+
# app/config/config.yml
111+
framework:
112+
default_locale: en
113+
114+
.. code-block:: xml
115+
116+
<!-- app/config/config.xml -->
117+
<framework:config>
118+
<framework:default-locale>en</framework:default-locale>
119+
</framework:config>
120+
121+
.. code-block:: php
122+
123+
// app/config/config.php
124+
$container->loadFromExtension('framework', array(
125+
'default_locale' => 'en',
126+
));
127+
128+
.. versionadded:: 2.1
129+
The ``default_locale`` parameter was defined under the session key
130+
originally, however, as of 2.1 this has been moved. This is because the
131+
locale is now set on the request instead of the session.
132+
96133
.. index::
97134
single: Translations; Translation resource locations
98135

@@ -259,6 +296,11 @@ support for both Twig and PHP templates.
259296
Twig Templates
260297
~~~~~~~~~~~~~~
261298

299+
..
300+
However, the ``%var%``
301+
notation is required when translating in Twig templates, and is overall a
302+
sensible convention to follow.
303+
262304
Symfony2 provides specialized Twig tags (``trans`` and ``transchoice``) to
263305
help with message translation of *static blocks of text*:
264306

@@ -469,6 +511,13 @@ Create a translation file under the ``validators`` catalog for the constraint me
469511
# validators.en.yml
470512
author.name.not_blank: Please enter an author name.
471513
514+
Translating Database Content
515+
----------------------------
516+
517+
The translation of database content should be handled by Doctrine through
518+
the `Translatable Extension`_. For more information, see the documentation
519+
for that library.
520+
472521
Summary
473522
-------
474523

@@ -490,3 +539,4 @@ steps:
490539
.. _`i18n`: http://en.wikipedia.org/wiki/Internationalization_and_localization
491540
.. _`ISO3166 Alpha-2`: http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes
492541
.. _`ISO639-1`: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
542+
.. _`Translatable Extension`: https://github.com/l3pp4rd/DoctrineExtensions

0 commit comments

Comments
 (0)