返回介绍

get_locale()

发布于 2017-09-10 23:31:33 字数 4688 浏览 1320 评论 0 收藏 0

get_locale()

Retrieves the current locale.


description

If the locale is set, then it will filter the locale in the ‘locale’ filter hook and return the value.

If the locale is not set already, then the WPLANG constant is used if it is defined. Then it is filtered through the ‘locale’ filter hook and the value for the locale global set and the locale is returned.

The process to get the locale should only be done once, but the locale will always be filtered using the ‘locale’ hook.


返回值

(string) The locale of the blog or from the 'locale' hook.


源代码

File: wp-includes/l10n.php

function get_locale() {
	global $locale, $wp_local_package;

	if ( isset( $locale ) ) {
		/**
		 * Filters WordPress install's locale ID.
		 *
		 * @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 );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_installing()
  • wp-includes/l10n.php: locale
  • wp-includes/load.php: is_multisite()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_site_option()
  • wp-includes/option.php: get_option()
  • Show 1 more use Hide more uses

Used By

  • wp-includes/l10n.php: _get_path_to_translation_from_lang_dir()
  • wp-includes/l10n.php: get_user_locale()
  • wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::switch_to_locale()
  • wp-includes/class-wp-locale-switcher.php: WP_Locale_Switcher::__construct()
  • wp-includes/functions.php: wp_maybe_decline_date()
  • wp-admin/includes/translation-install.php: translations_api()
  • wp-login.php: login_header()
  • wp-admin/includes/schema.php: populate_network()
  • wp-admin/update-core.php: list_core_update()
  • wp-admin/update-core.php: list_translation_updates()
  • wp-includes/theme.php: get_locale_stylesheet_uri()
  • wp-includes/l10n.php: load_default_textdomain()
  • wp-includes/l10n.php: load_plugin_textdomain()
  • wp-includes/l10n.php: load_muplugin_textdomain()
  • wp-includes/l10n.php: load_theme_textdomain()
  • wp-includes/formatting.php: remove_accents()
  • wp-includes/pluggable.php: wp_new_user_notification()
  • wp-includes/pluggable.php: wp_notify_postauthor()
  • wp-includes/pluggable.php: wp_notify_moderator()
  • wp-includes/general-template.php: get_bloginfo()
  • wp-includes/functions.php: wp_timezone_choice()
  • wp-includes/update.php: wp_version_check()
  • Show 17 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    This sets the monetary locale and if empty, sets as en_US

    
    setlocale( LC_MONETARY, get_locale() );
    $my_local_settings = localeconv();
    if ( $my_local_settings['int_curr_symbol'] == "" ) {
    	setlocale( LC_MONETARY, 'en_US' );
    }
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文