Translation bug. Unable to translate “Answer” (Plural: Answers)

Solved4.84K viewsIssues
0

Hi.

You are unable to translate the “Answer”, with plural “Answers”

This is located in
The anspress-question-answer / theme / default / answers.php line 18

<?php echo '<span data-view="answer_count">'.ap_answer_get_the_count().'</span> ' .sprintf(_n('answer', 'answers', ap_answer_get_the_count(), 'anspress-question-answer')); ?>

I have contacted the developer of PoEdit, because it was unable to locate this string, with a sourcecode scan

This is the Answer I got from Vaclav

The problem is that you use the translatable string “answer” elsewhere, as non-plural-forms one. Because msgids, i.e. strings, must be unique (they are IDs!), xgettext won’t see the other conflicting definition of the same string that you have using _n(). This is a limitation of gettext tools, not Poedit, and I can’t do anything about it.

There are two solutions

(1) Use message contexts for disambiguation (i.e. WP’s _nx() function instead of _n(), this is exactly what they are for.

(2) Better yet, don’t do thinks like this at all. The underlying cause is that you use _n() incorrectly: you don’t actually pass the number in there! _n(), _nx() etc. are intended for uses where the string contains the number (via %d, %i or such). Then it makes sense to use plural forms support for different pluralization in different languages. But if you phrase the strings as one and more-than-one, without any numbers in them, you shouldn’t use _n() in the first place.

You will also not be able to create a POT file update because of this.

selected answer
0

For now please try to replace whole line with this one:

<?php 
	printf(
		_n('%s%d%s answer', '%s%d%s answers', ap_answer_get_the_count(), 'anspress-question-answer'),
		'<span data-view="answer_count">',
		ap_answer_get_the_count(),
		'</span>'
	);
?>

Let me know if this solve your issue.

selected as best answer

Will this be official in the next update? Or is it just a quick fix.

1

Hello, this word “answer” in the answers.php file works when you have 2 or more answers: