determine_locale()

最后更新于:2021-11-26 01:41:19

determine_locale()

Determine the current locale desired for the request.

响应

(string) The determined locale.

源文件

文件: gc-includes/l10n.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 $locale The locale to return and short-circuit. Default null.
	 */
	$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'] && gc_is_json_request() ) {
		$determined_locale = get_user_locale();
	}

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

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