_n()对单复数进行翻译

目录

描述

Retrieve the plural or single form based on the amount.

If the domain is not set in the $l10n list, then a comparison will be made and either $plural or $single parameters returned.

If the domain does exist, then the parameters $single, $plural, and $number will first be passed to the domain's ngettext() method. Then it will be passed to the 'ngettext' filter hook along with the same parameters. The expected type will be a string.

_n() 描述

用法

<?php _n$single$plural$number$domain ?>

_n() 用法

参数

$single

(string) (必填) The text that will be used if $number is 1 (or if the locale uses the singular form for non-1 numbers)

默认值: None

$plural

(string) (必填) The text that will be used if $number is plural

默认值: None

$number

(int) (必填) The number to compare against to use either $single or $plural

默认值: None

$domain

(string) (可选) Domain to retrieve the translated text

默认值: 'default'

_n() 参数

返回值

(string) 

Either $single or $plural translated text.

_n() 返回值

示例

Display either "1 star" or "x stars" for a star rating plugin.

Important: Never do a calculation inside the sprintf() function! The following won't work:

Example from /wp-admin/edit-comments.php without the use of a text domain for translation.

_n() 示例

注意

  • 使用到 the 'ngettext' 过滤器.
  • l10n is an abbreviation for localization.

_n() 注意

历史

  • 添加于 版本: 2.8.0

_n() 历史

源文件

_n() 函数的代码位于 wp-includes/l10n.php.

_n() 源文件

相关