You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The curly brace syntax allows to "modify" the output of the variable. One of
80
-
these functions is the ``switch`` function. It acts like PHP's `switch statement`_
82
+
these functions is the ``select`` function. It acts like PHP's `switch statement`_
81
83
and allows to use different strings based on the value of the variable. A
82
84
typical usage of this is gender:
83
85
@@ -102,7 +104,7 @@ typical usage of this is gender:
102
104
<body>
103
105
<trans-unitid="invitation_title">
104
106
<source>invitation_title</source>
105
-
<target>{organizer_gender, select, female {{organizer_name} has invited you for her party!} male {{organizer_name} has invited you for his party!} other {{organizer_name} have invited you for their party!}}</target>
107
+
<target>{organizer_gender, select, female {{organizer_name} has invited you for her party!} male {{organizer_name} has invited you for his party!} other {{organizer_name} have invited you for their party!}}</target>
106
108
</trans-unit>
107
109
</body>
108
110
</file>
@@ -120,12 +122,11 @@ typical usage of this is gender:
120
122
];
121
123
122
124
This might look very complex. The basic syntax for all functions is
123
-
``{variable_name, function_name, function_statement}``. In this case, the
124
-
function name is ``select`` and its statement contains the "cases" of this
125
+
``{variable_name, function_name, function_statement}`` (where, as you see
126
+
later, ``function_statement`` is optional for some functions). In this case,
127
+
the function name is ``select`` and its statement contains the "cases" of this
125
128
select. This function is applied over the ``organizer_gender`` variable::
126
129
127
-
// ...
128
-
129
130
// prints "Ryan has invited you for his party!"
130
131
echo $translator->trans('invition_title', [
131
132
'organizer_name' => 'Ryan',
@@ -154,23 +155,23 @@ you to use literal text in the select statements:
154
155
in the switch statement, it is better to use "complex arguments" at the
155
156
outermost structure of the message. The strings are in this way better
156
157
readable for translators and, as you can see in the ``other`` case, other
157
-
parts of the sentence mgith be influenced by the variable.
158
+
parts of the sentence might be influenced by the variables.
158
159
159
160
Pluralization
160
161
-------------
161
162
162
163
Another interesting function is ``plural``. It allows you to
163
164
handle pluralization in your messages (e.g. ``There are 3 apples`` vs
164
-
``There is one apple``). The function looks very similair to the ``select`` function:
165
+
``There is one apple``). The function looks very similar to the ``select`` function:
165
166
166
167
.. configuration-block::
167
168
168
169
.. code-block:: yaml
169
170
170
171
# translations/messages.en.yaml
171
-
nr_of_apples: >
172
+
num_of_apples: >
172
173
{apples, plural,
173
-
=0 {There are no apples :(}
174
+
=0 {There are no apples}
174
175
one {There is one apple...}
175
176
other {There are # apples!}
176
177
}
@@ -182,9 +183,9 @@ handle pluralization in your messages (e.g. ``There are 3 apples`` vs
0 commit comments