WordPress at a glance
function is not described

WP_Locale_Switcher::switch_to_locale() public WP 4.7.0

Switches the translations according to the given locale.

{} It's a method of the class: WP_Locale_Switcher{}

Hooks from the method
Return

true/false. True on success, false on failure.

Usage

$WP_Locale_Switcher = new WP_Locale_Switcher();
$WP_Locale_Switcher->switch_to_locale( $locale );
$locale(string) (required)
The locale to switch to.

Changelog

Since 4.7.0 Introduced.

Code of WP_Locale_Switcher::switch_to_locale() WP 5.5.1

<?php
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;
}