@@ -113,15 +113,16 @@ Setting the Locale Based on the User's Preferences
113
113
You might want to improve this technique even further and define the locale based on
114
114
the user entity of the logged in user. However, since the ``LocaleListener `` is called
115
115
before the ``FirewallListener ``, which is responsible for handling authentication and
116
- is setting the user token into the ``TokenStorage ``, you have no access to the user
116
+ setting the user token on the ``TokenStorage ``, you have no access to the user
117
117
which is logged in.
118
118
119
- Let's pretend you have defined a property "locale" in your user entity which you
120
- want to be used as the locale for the given user. In order to achieve the wanted locale
121
- configuration, you can set the locale which is defined for the user to the session right
122
- after the login. Fortunately, you can hook into the login process and update the user's
123
- session before the redirect to the first page. For this you need an event listener for the
124
- ``security.interactive_login `` event:
119
+ Let's pretend you have defined a ``locale" `` property on your ``User `` entity
120
+ and you want to use this as the locale for the given user. To accomplish this,
121
+ you can hook into the login process and update the user's session with the
122
+ this locale value before they are redirected to their first page.
123
+
124
+ To do this, you need an event listener for the ``security.interactive_login ``
125
+ event:
125
126
126
127
.. code-block :: php
127
128
@@ -209,9 +210,6 @@ Then register the listener:
209
210
210
211
.. caution ::
211
212
212
- With this configuration you are all set for having the locale based on the user's
213
- locale. If however the locale changes during the session, it would not be updated
214
- since with the current implementation the user locale will only be stored to the
215
- session on login. In order to update the language immediately after a user has
216
- changed their language, you need to update the session after an update to
217
- the user entity.
213
+ In order to update the language immediately after a user has changed
214
+ their language preferences, you need to update the session after an update
215
+ to the ``User `` entity.
0 commit comments