WordPress at a glance

determine_locale() WP 1.0

Determine the current locale desired for the request.

  • Global. String. $pagenow
✈ 1 time = 0.000001s = speed of light | 50000 times = 0.09s = speed of light | PHP 7.2.5, WP 5.0
Return

String. The determined locale.

Usage

determine_locale();

Code of determine locale: wp-includes/l10n.php WP 5.2.2

<?php
function determine_locale() {
	/**
	 * Filters the locale for the current request prior to the default determination process.
	 *
	 * Using this filter allows to override the default logic, effectively short-circuiting the function.
	 *
	 * @since 5.0.0
	 *
	 * @param string|null The locale to return and short-circuit, or null as default.
	 */
	$determined_locale = apply_filters( 'pre_determine_locale', null );
	if ( ! empty( $determined_locale ) && is_string( $determined_locale ) ) {
		return $determined_locale;
	}

	$determined_locale = get_locale();

	if ( is_admin() ) {
		$determined_locale = get_user_locale();
	}

	if ( isset( $_GET['_locale'] ) && 'user' === $_GET['_locale'] && wp_is_json_request() ) {
		$determined_locale = get_user_locale();
	}

	if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
		$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
	}

	/**
	 * Filters the locale for the current request.
	 *
	 * @since 5.0.0
	 *
	 * @param string $locale The locale.
	 */
	return apply_filters( 'determine_locale', $determined_locale );
}

Related Functions

From tag: locale (site language)

More from tag: localize (l10n i18n Internationalization localization)

More from category: Localization

No comments
    Hello, !     Log In . Register