Title: WP_Locale_Switcher::change_locale
Published: December 6, 2016
Last modified: August 20, 2026

---

# WP_Locale_Switcher::change_locale( string $locale )

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Changes the site’s locale to the given one.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#description)󠁿

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#parameters)󠁿

 `$locale`stringrequired

The locale to change to.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#source)󠁿

    ```php
    private function change_locale( $locale ) {
    	global $wp_locale, $phpmailer;

    	$this->load_translations( $locale );

    	$wp_locale = new WP_Locale();

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

    	if ( $phpmailer instanceof WP_PHPMailer ) {
    		$phpmailer->setLanguage();
    	}

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-locale-switcher.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-locale-switcher.php#L280)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-locale-switcher.php#L280-L301)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#hooks)󠁿

 [do_action( ‘change_locale’, string $locale )](https://developer.wordpress.org/reference/hooks/change_locale/)

Fires when the locale is switched to or restored.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Translation_Controller::get_instance()](https://developer.wordpress.org/reference/classes/wp_translation_controller/get_instance/)`wp-includes/l10n/class-wp-translation-controller.php` |

Utility method to retrieve the main instance of the class.

  | 
| [WP_Locale_Switcher::load_translations()](https://developer.wordpress.org/reference/classes/wp_locale_switcher/load_translations/)`wp-includes/class-wp-locale-switcher.php` |

Load translations for a given locale.

  | 
| [WP_Locale::__construct()](https://developer.wordpress.org/reference/classes/wp_locale/__construct/)`wp-includes/class-wp-locale.php` |

Constructor which calls helper methods to set up object variables.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#)

| Used by | Description | 
| [WP_Locale_Switcher::switch_to_locale()](https://developer.wordpress.org/reference/classes/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()](https://developer.wordpress.org/reference/classes/wp_locale_switcher/restore_previous_locale/)`wp-includes/class-wp-locale-switcher.php` |

Restores the translations according to the previous locale.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_locale_switcher/change_locale/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_locale_switcher%2Fchange_locale%2F)
before being able to contribute a note or feedback.