Theme check: Missing a text-domain

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?

1 Answer
1

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'
      )
);

Leave a Comment