switch_to_locale

The timeline below displays how wordpress function switch_to_locale has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Switches the translations according to the given locale.
 *
 * @since 4.7.0
 *
 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
 *
 * @param string $locale The locale.
 * @return bool True on success, false on failure.
 */
function switch_to_locale($locale)
{
    /* @var WP_Locale_Switcher $wp_locale_switcher */
    global $wp_locale_switcher;
    if (!$wp_locale_switcher) {
        return false;
    }
    return $wp_locale_switcher->switch_to_locale($locale);
}

WordPress Version: 5.3

/**
 * Switches the translations according to the given locale.
 *
 * @since 4.7.0
 *
 * @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
 *
 * @param string $locale The locale.
 * @return bool True on success, false on failure.
 */
function switch_to_locale($locale)
{
    /* @var WP_Locale_Switcher $wp_locale_switcher */
    global $wp_locale_switcher;
    return $wp_locale_switcher->switch_to_locale($locale);
}

WordPress Version: 4.7

/**
 * Switches the translations according to the given locale.
 *
 * @since 4.7.0
 *
 * @global WP_Locale_Switcher $wp_locale_switcher
 *
 * @param string $locale The locale.
 * @return bool True on success, false on failure.
 */
function switch_to_locale($locale)
{
    /* @var WP_Locale_Switcher $wp_locale_switcher */
    global $wp_locale_switcher;
    return $wp_locale_switcher->switch_to_locale($locale);
}