Problem
You want to change your application's locale.
Solution
Use the App::setLocale() method.
// Change to Spanish
App::setLocale('es');
Now the locale is es for the remainder of the request.
Remember: the next request the locale will be back to whatever the configuration specifies.
Discussion
This does more than simply changing app.locale in the configuration.
It does three things:
- Changes
app.localein the currently loaded configuration values. - Sets the locale of the translator.
- Fires a
locale.changedevent which your application can listen for.
