8

Using gettext how should a sentence with multiple numeric variables be made translatable? ngettext only takes one number as the plural parameter.

The permutations that should be allowed in the below sentence are "adult and child", "adults and child", "adult and children" and "adults and children".

"from #AVAILABILITYFROM to #AVAILABILITYTO for #NUMADULTS adult and #NUMCHILDREN child"

dsas
  • 1,650
  • 18
  • 30

1 Answers1

10

Grammar can be very complex in some other languages than English and you should be aware that is practical impossible to generate correct complex sentences using your approach.

Remember that multiple variables and genre (male/female) also adds lots of complexity.

The solution is to generate only simple sentences where you have only one variable. This is the case that is supported by ngettext.

Understand that ngettext is something great and that is something that most commercial i18n frameworks from bug software companies don't even support. Even so it has his limitations, so shortly the solution for your question is do split your complex sentence in several simple ones that can be translated using only one variable.

sorin
  • 161,544
  • 178
  • 535
  • 806
  • I just want add that even if there is just one plural form, then this way of doing it would require 4 strings. One for both parts singular, one for both parts plural, one for first singular and second plural, and one for the other way around. Gettext doesn't even support that, and making something that does would be too complex to use. – Tor Valamo Dec 12 '09 at 16:42
  • I was hoping that that wouldn't be the answer but thought that it may :) – dsas Dec 13 '09 at 12:47
  • 1
    It's not impossible, it can be easily done using multiple levels of nesting in the messages, that's the approach ICU uses. ngettext is not great, it's deficient because it only allows one level nesting so it can only handle selection on one variable. The advice to split the sentence into several ones is a bad one but it's the only one possible with gettext. You join the parts as A+B+C in your code, but in a target language it's incorrect and has to be C+A+B or part of C shoud go first and so on. – Basel Shishani Jan 07 '12 at 23:00
  • Does anyone have suggestions for http://stackoverflow.com/questions/13919080? I like how Zend_Translate lets me use ordered variables (which matter a lot since languages' orders differ, as Basel indicated). I'm converting my site from "array" to "gettext" and don't want to go through the entire site adding quadruple nesting. I just want to figure out how to make gettext honor ordered variables. Thoughts? – Ryan Dec 17 '12 at 22:05