what is the last $count in this example?

printf( _n(
    'You have published %s post.', 'You have published %s posts.',
    'myplugin' ),
$count );

i guess the first one is to fill each %s, so what is the second $count?



The _n (see Codex) function accepts four arguments. The first two are texts to be translated (the first is singular, the second plural), the third argument is a number (in this case $count). When $count is 1 the first string is used, otherwise the second string is used.

So in fact the first instance of $count is only used to determine whether the single / plural text should be used. _n then translates that string, using the plug-in/theme domain - i.e. the fourth argument) and the language set in the wp-config. This then returns a translated string such as:

Se han publicado %s artículos

The printf then echos this string with the %s replaced by the second argument, $count (which is the second instance of $count`) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.