^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_locale()用法示例

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

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


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


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

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈