On this page
WP_Locale_Switcher::switch_to_locale( string $locale ): bool
Switches the translations according to the given locale.
Parameters
$localestring Required-
The locale to switch to.
Return
bool True on success, false on failure.
Source
File: wp-includes/class-wp-locale-switcher.php. View all references
public function switch_to_locale( $locale ) {
$current_locale = determine_locale();
if ( $current_locale === $locale ) {
return false;
}
if ( ! in_array( $locale, $this->available_languages, true ) ) {
return false;
}
$this->locales[] = $locale;
$this->change_locale( $locale );
/**
* Fires when the locale is switched.
*
* @since 4.7.0
*
* @param string $locale The new locale.
*/
do_action( 'switch_locale', $locale );
return true;
}
Hooks
- do_action( 'switch_locale',
string $locale ) -
Fires when the locale is switched.
Related
Uses
| Uses | Description |
|---|---|
| determine_locale() wp-includes/l10n.php | Determines the current locale desired for the request. |
| WP_Locale_Switcher::change_locale() wp-includes/class-wp-locale-switcher.php | Changes the site’s locale to the given one. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Used By
| Used By | Description |
|---|---|
| switch_to_locale() wp-includes/l10n.php | Switches the translations according to the given locale. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_locale_switcher/switch_to_locale