I want to translate a script that lists the content of a folder. There's a summary of included files, folders and the total size displayed. So far I translated all strings using gettext
, but I'm stuck here and look for an elegant way to solve translating a string that might contain multiple plurals. Probably needless to mention, but since each language is different, I want to avoid concatenate strings.
$summary = sprintf(_('%1$s folders and %2$s files, %3$s %4$s in total'), $total_folders, $total_files, $total_size, $unit);
Possible states (0-cases are left out intentionally):
- 1 folder and 1 file, 100 kilobytes in total
- 1 folder and 2 files, 200 kilobytes in total
- 2 folders and 1 file, 100 kilobytes in total
- 2 folders and 2 files, 200 kilobytes in total
I think ngettext()
would be the appropriate replacement for _()
, but combining that with my example is getting over my head.
The pluralization is a basical problem with translations. Here is an example of implementations that can probably help you: http://symfony.com/doc/current/components/translation/usage.html#pluralization
Maybe you should consider to take the translation component they did for symfony.