Set the Current Application Locale

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:

  1. Changes app.locale in the currently loaded configuration values.
  2. Sets the locale of the translator.
  3. Fires a locale.changed event which your application can listen for.
comments powered by Disqus