@@ -19,15 +19,17 @@ You can install the component in many different ways:
19
19
Constructing the Translator
20
20
---------------------------
21
21
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 *).
24
26
25
27
Configuration
26
28
~~~~~~~~~~~~~
27
29
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)::
31
33
32
34
use Symfony\Component\Translation\Translator;
33
35
use Symfony\Component\Translation\MessageSelector;
@@ -56,9 +58,9 @@ Loader too. The default loaders are:
56
58
* :class: `Symfony\\ Component\\ Translation\\ Loader\\ ArrayLoader ` - to load
57
59
catalogues from PHP arrays.
58
60
* :class: `Symfony\\ Component\\ Translation\\ Loader\\ CsvFileLoader ` - to load
59
- catalogues from Csv files.
61
+ catalogues from CSV files.
60
62
* :class: `Symfony\\ Component\\ Translation\\ Loader\\ PhpFileLoader ` - to load
61
- catalogues from Php files.
63
+ catalogues from PHP files.
62
64
* :class: `Symfony\\ Component\\ Translation\\ Loader\\ XliffFileLoader ` - to load
63
65
catalogues from Xliff files.
64
66
* :class: `Symfony\\ Component\\ Translation\\ Loader\\ YamlFileLoader ` - to load
@@ -67,21 +69,21 @@ Loader too. The default loaders are:
67
69
All loaders, except the ``ArrayLoader ``, requires the
68
70
:doc: `Config component</components/config/index> `.
69
71
70
- At first, you should add a loader to the ``Translator ``::
72
+ At first, you should add one or more loaders to the ``Translator ``::
71
73
72
74
// ...
73
75
$translator->addLoader('array', new ArrayLoader());
74
76
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.
78
80
79
81
Loading Messages with the ``ArrayLoader ``
80
82
.........................................
81
83
82
84
Loading messages can be done by calling
83
85
: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 ``
85
87
method), the second is the resource and the third argument is the locale::
86
88
87
89
// ...
@@ -106,24 +108,26 @@ The Translation Process
106
108
To actually translate the message, the Translator uses a simple process:
107
109
108
110
* 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;
112
115
113
116
* If the message is located in the catalog, the translation is returned. If
114
117
not, the translator returns the original message.
115
118
116
119
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
118
122
Translator looks for the exact string inside the appropriate message catalog
119
123
and returns it (if it exists).
120
124
121
125
.. tip ::
122
126
123
127
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.
127
131
128
132
Fallback Locale
129
133
~~~~~~~~~~~~~~~
0 commit comments