On this page
WP_Locale_Switcher::change_locale( string $locale )
This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
Changes the site’s locale to the given one.
Description
Loads the translations, changes the global $wp_locale object and updates all post type labels.
Parameters
$localestring Required-
The locale to change to.
Source
File: wp-includes/class-wp-locale-switcher.php. View all references
private function change_locale( $locale ) {
global $wp_locale;
$this->load_translations( $locale );
$wp_locale = new WP_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 );
}
Hooks
- do_action( 'change_locale',
string $locale ) -
Fires when the locale is switched to or restored.
Related
Uses
| Uses | Description |
|---|---|
| WP_Locale_Switcher::load_translations() wp-includes/class-wp-locale-switcher.php | Load translations for a given locale. |
| WP_Locale::__construct() wp-includes/class-wp-locale.php | Constructor which calls helper methods to set up object variables. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
Used By
| Used By | Description |
|---|---|
| WP_Locale_Switcher::switch_to_locale() wp-includes/class-wp-locale-switcher.php | Switches the translations according to the given locale. |
| WP_Locale_Switcher::restore_previous_locale() wp-includes/class-wp-locale-switcher.php | Restores the translations according to the previous 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/change_locale