钩子文档

wp_sprintf_l

💡 云策文档标注

概述

wp_sprintf_l 是一个 WordPress 过滤器,用于修改 wp_sprintf_l() 函数中使用的本地化分隔符数组。它允许开发者自定义列表项连接时的翻译分隔符,以适配不同语言或特定需求。

关键要点

  • 过滤器名称:wp_sprintf_l
  • 作用:过滤 wp_sprintf_l() 使用的翻译分隔符数组
  • 参数:$delimiters,一个包含翻译分隔符的数组
  • 注意事项:占位符(如 %s)用于辅助翻译,但在数组传递给过滤器前会被移除;应避免使用 & 符号和 HTML 实体

代码示例

$l = apply_filters(
    'wp_sprintf_l',
    array(
        /* translators: Used to join items in a list with more than 2 items. */
        'between'          => sprintf( __( '%1$s, %2$s' ), '', '' ),
        /* translators: Used to join last two items in a list with more than 2 times. */
        'between_last_two' => sprintf( __( '%1$s, and %2$s' ), '', '' ),
        /* translators: Used to join items in a list with only 2 items. */
        'between_only_two' => sprintf( __( '%1$s and %2$s' ), '', '' ),
    )
);

📄 原文内容

Filters the translated delimiters used by wp_sprintf_l() .

Description

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.

Parameters

$delimitersarray
An array of translated delimiters.

Source

$l = apply_filters(
	'wp_sprintf_l',
	array(
		/* translators: Used to join items in a list with more than 2 items. */
		'between'          => sprintf( __( '%1$s, %2$s' ), '', '' ),
		/* translators: Used to join last two items in a list with more than 2 times. */
		'between_last_two' => sprintf( __( '%1$s, and %2$s' ), '', '' ),
		/* translators: Used to join items in a list with only 2 items. */
		'between_only_two' => sprintf( __( '%1$s and %2$s' ), '', '' ),
	)
);

Changelog

Version Description
2.5.0 Introduced.