2

I'm using following code to display the number of comments:

printf(_n('1 comment', '%1$s comments', get_comments_number()), number_format_i18n( get_comments_number() ), 'text-domain' );

Is there something wrong with it?

The theme check plugin is giving the warning :

WARNING: Found a translation function that is missing a text-domain. Function _n, with the arguments '1 comment','%1$s comments'

I do not understand what it is suggesting, neither it tells in which file is the error, so I am assuming its the above code.

How I can fix that?

2

Let us look at the relevant line. I am reformatting it to easier understand what is going on:

printf(
    _n('1 comment', '%1$s comments', get_comments_number() ),
    number_format_i18n( get_comments_number() ),
    'text-domain'
);

So what you are doing is calling printf with three parameters, each one now being on a separate line now as I formatted it.

But this doesn't really make sense, especially the third parameter text-domain doesn't make any sense there.

What you probably want is using _n to translate using a number that you put through number_format_i18n.

So I guess this is what you're looking for actually:

printf(
    _n( '1 comment',
        '%1$s comments',
        number_format_i18n( get_comments_number() ),
        'text-domain'
      )
);

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.