get_locale()
Sets the global variable $locale and gets the current site locale (for example, en_US).
For the second and subsequent calls, the function will return $locale global variable passed through the locale filter.
You can get the list of locales here.
Until version 4.0, the locale was defined by WPLANG constant within the wp-config.php. Now this constant is deprecated.
Usually this function is used by one of localization functions, like load_textdomain().
Since version 5.0, it's better to use a wrapper of this function: determine_locale().
Used By: determine_locale()
1 time — 0.000015 sec (very fast) | 50000 times — 0.05 sec (speed of light)
Hooks from the function
Return
String
. The locale of the blog or from the locale hook.
Usage
get_locale();
Examples
#1 Get the current locale
echo get_locale(); // output is `en_US`
#2 Set locale on the server
This example demonstrates how to set the LC_MONETARY locale. If the base locale is not set, then specify the 'en_US' locale this way:
setlocale( LC_MONETARY, get_locale() ); $my_local_settings = localeconv(); if( ! $my_local_settings['int_curr_symbol'] ){ setlocale( LC_MONETARY, 'en_US' ); }
#3 Get the value of the current locale
setlocale( LC_MONETARY, get_locale() ); $my_local_settings = localeconv(); print_r( $my_local_settings );
Notes
- Global. String. $locale The current locale.
- Global. String. $wp_local_package Locale code of the package.
Changelog
Since 1.5.0 | Introduced. |