返回介绍

wp_sprintf_l()

发布于 2017-09-11 12:57:29 字数 2812 浏览 1017 评论 0 收藏 0

wp_sprintf_l( string $pattern,  array $args )

Localize list items before the rest of the content.


description

The ‘%l’ must be at the first characters can then contain the rest of the content. The list items will have ‘, ‘, ‘, and’, and ‘ and ‘ added depending on the amount of list items in the $args parameter.


参数

$pattern

(string) (Required) Content containing '%l' at the beginning.

$args

(array) (Required) List items to prepend to the content and replace '%l'.


返回值

(string) Localized list items and rest of the content.


源代码

File: wp-includes/formatting.php

function wp_sprintf_l( $pattern, $args ) {
	// Not a match
	if ( substr($pattern, 0, 2) != '%l' )
		return $pattern;

	// Nothing to work with
	if ( empty($args) )
		return '';

	/**
	 * Filters the translated delimiters used by wp_sprintf_l().
	 * Placeholders (%s) are included to assist translators and then
	 * removed before the array of strings reaches the filter.
	 *
	 * Please note: Ampersands and entities should be avoided here.
	 *
	 * @since 2.5.0
	 *
	 * @param array $delimiters An array of translated delimiters.
	 */
	$l = apply_filters( 'wp_sprintf_l', array(
		/* translators: used to join items in a list with more than 2 items */
		'between'          => sprintf( __('%s, %s'), '', '' ),
		/* translators: used to join last two items in a list with more than 2 times */
		'between_last_two' => sprintf( __('%s, and %s'), '', '' ),
		/* translators: used to join items in a list with only 2 items */
		'between_only_two' => sprintf( __('%s and %s'), '', '' ),
	) );

	$args = (array) $args;
	$result = array_shift($args);
	if ( count($args) == 1 )
		$result .= $l['between_only_two'] . array_shift($args);
	// Loop when more than two args
	$i = count($args);
	while ( $i ) {
		$arg = array_shift($args);
		$i--;
		if ( 0 == $i )
			$result .= $l['between_last_two'] . $arg;
		else
			$result .= $l['between'] . $arg;
	}
	return $result . substr($pattern, 2);
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: wp_sprintf_l
  • wp-includes/plugin.php: apply_filters()

User Contributed Notes

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

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

发布评论

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