localefilter-hookWP 1.5.0

Allows you to change the site locale (ex: en_US), which retrieved by the get_locale() function.

Usage

add_filter( 'locale', 'wp_kama_locale_filter' );

/**
 * Function for `locale` filter-hook.
 * 
 * @param string $locale The locale ID.
 *
 * @return string
 */
function wp_kama_locale_filter( $locale ){

	// filter...
	return $locale;
}
$locale(string)
The locale ID. Example: en_US, ru_RU.

Examples

0

#1 Change the localization language

This example shows how to change the localization language in WordPress based on the language variable passed in $_GET query parameter:

add_filter( 'locale', 'set_my_locale' );
function set_my_locale( $lang ) {
	if( 'ru' == $_GET['language'] )
		return 'ru_RU';
	else
		return $lang;
}

Changelog

Since 1.5.0 Introduced.

Where the hook is called

get_locale()
locale
wp-includes/l10n.php 80
return apply_filters( 'locale', $locale );
wp-includes/l10n.php 35
return apply_filters( 'locale', $locale );

Where the hook is used in WordPress

wp-includes/class-wp-locale-switcher.php 62
add_filter( 'locale', array( $this, 'filter_locale' ) );