Getting the Default Locale Being Used

Problem

You want to get the currently used default locale.

Solution

Use the Lang::getLocale() method.

Or the alias, Lang::locale().

This returns the current default locale the translator is using.

echo Lang::getLocale();

Discussion

Differences between Lang::getLocale() and App::getLocale().

The Lang::getLocale() method returns the default locale for the currently loaded translator. App::getLocale() returns the default locale for the currently loaded configuration.

The translator is initialized when the Lang facade is first used. This is when it sets its default locale from the currently loaded configuration.

Most of the time these values will be identical. But if you call Lang::setLocale() it will change the translator's locale without affecting the loaded configuration value. This is the one case the values could be different.

comments powered by Disqus