This post is part of the sub-series on Internationalizing a ClassicPress plugin which is part of the Internationalizing a ClassicPress plugin series.
As well as translating strings, and strings with parameters, you can also translate strings which include plurals. For example, you might have a counts of comments which would vary between 1 comment
and 2 comments
. This can be handled using the _n
function.
There is no equivalent of esc_html__
for the plurals function, so you will need to wrap the _n
function call with esc_html__
or esc_html_e
:
esc_html_e(sprintf(
_n(
'%s comment',
'%s comments',
get_comments_number(),
'plugin-text-domain'
),
number_format_i18n(get_comments_number())
)
);
The _n()
function accepts four arguments:
- single — the text to be used if the number is singular..
- plural — the text to be used if the number is plural.
- count — number to compare against to use either the singular or plural form.
- text domain — the plugin text domain.
The function returns the correct translated string for the supplied count.