Ticket #512 (fixed enhancement)
Pluralization support for language strings
- Created: 2011-10-17 15:15:59
- Reported by: Franz
- Assigned to: None
- Milestone: 2.0-alpha2
- Component: localization
- Priority: normal
Gettext supports pluralization, so should we.
Simply in an extra function, maybe t_n().
History
Franz 2011-10-18 23:25:16

Loosely based on the sprintf() functionality of Flux_Lang::t() and the implementation of ngettext() in the old Gettext layer, I have this:
public function t_n($str, $n)
{
if (isset($this->translationTable[$str]))
{
$translation = $this->translationTable[$str];
$count = count($translation);
if ($n <= 0 || $count < $n)
{
$n = $count;
}
$args = func_get_args();
$args[0] = $this->translationTable[$args[0]][$n - 1];
return call_user_func_array('sprintf', $args);
}
return $str;
}
However, that does not work at all with languages that have different ways to construct plurals (Russian, for example, if I understood everything correctly). Also not sure whether that implementation would work correctly with how PO files are generated.
Franz 2012-01-08 22:30:23

This one is tricky. I might have completely misunderstood the whole Gettext concept.
Looking forward to your ideas.
Franz 2012-11-27 22:54:50

- Owner FSX removed.
- Status changed from open to fixed.
Somebody got lucky. This is already possible thanks to using illuminate/translation.