Skip to content

Commit 56b02be

Browse files
wouterjweaverryan
authored andcommitted
Reread component docs
1 parent cde0f7f commit 56b02be

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

components/translation/introduction.rst

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ You can install the component in many different ways:
1919
Constructing the Translator
2020
---------------------------
2121

22-
Before you can use the Translator, you need to configure it and load the
23-
message catalogues.
22+
The main access point of the Translation Component is
23+
:class:`Symfony\\Component\\Translation\\Translator`. Before you can use it,
24+
you need to configure it and load the messages to translate (called *message
25+
catalogues*).
2426

2527
Configuration
2628
~~~~~~~~~~~~~
2729

28-
The constructor of the ``Translator`` class needs to arguments: The locale and
29-
a :class:`Symfony\\Component\\Translation\\MessageSelector` to use when using
30-
pluralization (more about that later)::
30+
The constructor of the ``Translator`` class needs two arguments: The locale
31+
and the :class:`Symfony\\Component\\Translation\\MessageSelector` to use when
32+
using pluralization (more about that later)::
3133

3234
use Symfony\Component\Translation\Translator;
3335
use Symfony\Component\Translation\MessageSelector;
@@ -56,9 +58,9 @@ Loader too. The default loaders are:
5658
* :class:`Symfony\\Component\\Translation\\Loader\\ArrayLoader` - to load
5759
catalogues from PHP arrays.
5860
* :class:`Symfony\\Component\\Translation\\Loader\\CsvFileLoader` - to load
59-
catalogues from Csv files.
61+
catalogues from CSV files.
6062
* :class:`Symfony\\Component\\Translation\\Loader\\PhpFileLoader` - to load
61-
catalogues from Php files.
63+
catalogues from PHP files.
6264
* :class:`Symfony\\Component\\Translation\\Loader\\XliffFileLoader` - to load
6365
catalogues from Xliff files.
6466
* :class:`Symfony\\Component\\Translation\\Loader\\YamlFileLoader` - to load
@@ -67,21 +69,21 @@ Loader too. The default loaders are:
6769
All loaders, except the ``ArrayLoader``, requires the
6870
:doc:`Config component</components/config/index>`.
6971

70-
At first, you should add a loader to the ``Translator``::
72+
At first, you should add one or more loaders to the ``Translator``::
7173

7274
// ...
7375
$translator->addLoader('array', new ArrayLoader());
7476

75-
The first argument is the key to which we can refer the loader in the translator
76-
and the second argument is an instance of the loader itself. After this, you
77-
can add your resources using the correct loader.
77+
The first argument is the name to which you can refer the loader in the
78+
translator and the second argument is an instance of the loader itself. After
79+
this, you can add your resources using the correct loader.
7880

7981
Loading Messages with the ``ArrayLoader``
8082
.........................................
8183

8284
Loading messages can be done by calling
8385
:method:`Symfony\\Component\\Translation\\Translator::addResource`. The first
84-
argument is the loader name (the first argument of the ``addLoader``
86+
argument is the loader name (this was the first argument of the ``addLoader``
8587
method), the second is the resource and the third argument is the locale::
8688

8789
// ...
@@ -106,24 +108,26 @@ The Translation Process
106108
To actually translate the message, the Translator uses a simple process:
107109

108110
* A catalog of translated messages is loaded from translation resources defined
109-
for the ``locale`` (e.g. ``fr_FR``). Messages from the fallback locale are
110-
also loaded and added to the catalog if they don't already exist. The end
111-
result is a large "dictionary" of translations;
111+
for the ``locale`` (e.g. ``fr_FR``). Messages from the
112+
:ref:`fallback locale <Fallback Locale>` are also loaded and added to the
113+
catalog if they don't already exist. The end result is a large "dictionary"
114+
of translations;
112115

113116
* If the message is located in the catalog, the translation is returned. If
114117
not, the translator returns the original message.
115118

116119
You start this process by calling
117-
:method:`Symfony\\Component\\Translation\\Translator::trans`. Then, the
120+
:method:`Symfony\\Component\\Translation\\Translator::trans` or
121+
:method:`Symfony\\Component\\Translation\\Translator::transChoice`. Then, the
118122
Translator looks for the exact string inside the appropriate message catalog
119123
and returns it (if it exists).
120124

121125
.. tip::
122126

123127
When a translation does not exist for a locale, the translator first tries
124-
to find the translation for the language (``fr`` if the locale is
125-
``fr_FR`` for instance). If this also fails, it looks for a translation
126-
using the fallback locale.
128+
to find the translation for the language (e.g. ``fr`` if the locale is
129+
``fr_FR``). If this also fails, it looks for a translation using the
130+
fallback locale.
127131

128132
Fallback Locale
129133
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)