检索当前区域设置。

原型

get_locale()

描述

如果设置了语言环境,那么它将过滤“locale”过滤器挂钩中的语言环境并返回该值。

返回值

(string)  博客的区域设置或来自

源文件

路径:wp-includes/l10n.php

<?php
...
function get_locale() {
	global $locale, $wp_local_package;
	if ( isset( $locale ) ) {
		/**
		 * Filters the locale ID of the WordPress installation.
		 *
		 * @since 1.5.0
		 *
		 * @param string $locale The locale ID.
		 */
		return apply_filters( 'locale', $locale );
	}
	if ( isset( $wp_local_package ) ) {
		$locale = $wp_local_package;
	}
	// WPLANG was defined in wp-config.
	if ( defined( 'WPLANG' ) ) {
		$locale = WPLANG;
	}
	// If multisite, check options.
	if ( is_multisite() ) {
		// Don't check blog option when installing.
		if ( wp_installing() || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) {
			$ms_locale = get_site_option( 'WPLANG' );
		}
		if ( $ms_locale !== false ) {
			$locale = $ms_locale;
		}
	} else {
		$db_locale = get_option( 'WPLANG' );
		if ( $db_locale !== false ) {
			$locale = $db_locale;
		}
	}
	if ( empty( $locale ) ) {
		$locale = 'en_US';
	}
	/** This filter is documented in wp-includes/l10n.php */
	return apply_filters( 'locale', $locale );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_locale/