get_locale() - WordPress 函数参考中文文档

返回介绍

get_locale()

发布于 2017-09-10 字数4688 浏览 956 评论 0

get_locale()

Retrieves the current locale.


描述

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 );
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

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' );
    }
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!