#7945 closed defect (bug) (invalid)
Translation Form Throws Error Despite Valid Input in Singular Field
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Component: | General | Keywords: | |
Cc: |
Description
While contributing translations to WordPress.org (GlotPress), I encountered a validation error even after filling the required Singular translation field correctly. The system is incorrectly flagging the second textarea as empty.
Issue Details:
I entered a valid Gujarati translation for the singular form:
%d મીડિયા અટેચમેન્ટ ટ્રેશમાંથી પુનઃસ્થાપિત થય છે.
The Plural form was not applicable in this case and was intentionally left blank.
On clicking "Suggest", I received the following error:
The textarea Translation 2 is invalid and should not be empty string!
Expected Behavior:
If only the Singular form is present in the original string, providing its translation should be enough.
The form should not require the Plural field when the original doesn't have distinct plural content.
Actual Behavior:
The system erroneously expects input in the second translation textarea, which should be optional (or disabled) when not applicable.
Screenshot for Reference:
https://prnt.sc/CPikebKVpxyk
Attachments (1)
Change History (3)
#2
@
6 weeks ago
The purpose of the command _n() is to make it possible to get a translation correct even if something is counted in a phrase.
Whenever this command is used in the code, the author needs to specify both a "Singular" and a "Plural" version of the string.
Depending on how numbers are handled in the specific target language, each such pair needs to be translated with between one and six(!) versions.
The locale definitions in https://meta.svn.wordpress.org/sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/locales/locales.php steer how many versions of such a string pair is needed for a specific target language, and also contains (where needed) the formulas used to select the correct version in every case.
One interesting outlier in this regard is Japanese. Regardless of what number you may insert into a text, there won't be any changes to the surrounding verbs, nouns, or other words. 0 bananas, 1 banana, 2 bananas or 145 bananas will always translate exactly the same way, except for the number itself.
On the opposite far end, we've got Arabic, with the following definitions:
$ar->nplurals = 6; $ar->plural_expression = '(n == 0) ? 0 : ((n == 1) ? 1 : ((n == 2) ? 2 : ((n % 100 >= 3 && n % 100 <= 10) ? 3 : ((n % 100 >= 11 && n % 100 <= 99) ? 4 : 5))))';
For Arabic translations, each singular/plural pair needs to be translated six times. Depending on the number in the phrase, WordPress will select the correct version of the string. The first three versions are used for 0, 1, and 2 respectively. The next version applies if the steering number ends in any number between 3 and 10, and so on.
If any of these strings is missing, you may get a runtime error, that's why the platform double-checks that you did provide all variants.
And a quick note to developers: You should only use _n() when the steering number is also included directly in the string. Never use this command as a shortcut to just split between generic singular and plural. (For instance, in Russian, you use "Singular" also for 21, but only if the number itself is present in the string.)
That isn't the way that plural translation works. At least two fields must be present. If they're the same, then copy the one to the other.