WP_Locale_Switcher::change_locale()privateWP 4.7.0

Changes the site's locale to the given one.

Loads the translations, changes the global $wp_locale object and updates all post type labels.

Method of the class: WP_Locale_Switcher{}

Hooks from the method

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->change_locale( $locale );
$locale(string) (required)
The locale to change to.

Notes

  • Global. WP_Locale. $wp_locale WordPress date and time locale object.

Changelog

Since 4.7.0 Introduced.

WP_Locale_Switcher::change_locale() code WP 6.5.2

private function change_locale( $locale ) {
	global $wp_locale;

	$this->load_translations( $locale );

	$wp_locale = new WP_Locale();

	WP_Translation_Controller::get_instance()->set_locale( $locale );

	/**
	 * Fires when the locale is switched to or restored.
	 *
	 * @since 4.7.0
	 *
	 * @param string $locale The new locale.
	 */
	do_action( 'change_locale', $locale );
}