[wp-meta] [Making WordPress.org] #7945: Translation Form Throws Error Despite Valid Input in Singular Field

Making WordPress.org noreply at wordpress.org
Sun Apr 6 20:43:17 UTC 2025


#7945: Translation Form Throws Error Despite Valid Input in Singular Field
--------------------------+----------------------
 Reporter:  jagdishkori   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  General       |  Resolution:  invalid
 Keywords:                |
--------------------------+----------------------

Comment (by tobifjellner):

 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.)

-- 
Ticket URL: <https://meta.trac.wordpress.org/ticket/7945#comment:2>
Making WordPress.org <https://meta.trac.wordpress.org/>
Making WordPress.org


More information about the wp-meta mailing list