3 ms·
Indeed, this is a solved problem. Use ngettext, see its page for all different language variations (even the Slovenian four different forms) https://www.gnu.or
by gulpahum 12y ago
Indeed, this is a solved problem. Use ngettext, see its page for all different language variations (even the Slovenian four different forms) https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html https://www.gnu.org/software/gettext/manual/html_node/Plural...
- philh 12y agoHow does ngettext handle "Your query matched %g files in %g directories"?
- bmn_ 12y agoWith reordering syntax. https://www.gnu.org/software/gettext/manual/html_node/c_002dformat.html#c_002dformat https://www.gnu.org/software/gettext/manual/html_node/c_002d...
- yoha 12y agoThis only addresses the ordering of parameters, not the fact that you need two different counters.
- annnnd 12y agoLet's face it - sometimes it is better to just avoid the problem than to (try to) solve it. Just use some other form of sentence, people will not even notice and you will save yourself tons of problems.
- MatthewWilkes 12y agoThere's always an exception. You have two choices. First: you might split it into three strings and trust the translator to handle it. For example, you might pick: "Your query matched %(filecount)s in %(directorycount)s"? "%g files" "%g directories" with appropriate plurals for the %g ones. Another translator might pick: "Your query %(filecount)s %(directorycount)s"? "matched %g files" "in %g directories" to get the flexibility they need. You only hit a problem there when you get one word that is requires declination dependent on both numbers in a way that you can't fit to be contiguous with the numbers. It's not foolproof, but it's certainly enough flexibility if you're willing to re-word things slightly. Alternatively, and this is my favoured way, you can have the result of a plural lookup be a second msgid, for example: msgid "files_found_by_n_directories" msgstr[0] "files_found_directory_0" msgstr[1] "files_found_directory_1" msgstr[2] "files_found_directory_2" msgid "files_found_directory_0" msgstr[0] "Your query didn't match any files" msgstr[1] "Your query matched a file in no directories" msgstr[2] "Your query matched %(file)g files in no directories" msgid "files_found_directory_1" msgstr[0] "Your query didn't match any files in a directory" msgstr[1] "Your query matched %(file)g file in a directory" msgstr[2] "Your query matched %(file)g files in a directory" msgid "files_found_directory_2" msgstr[0] "Your query didn't match any files in %(directories)g directories" msgstr[1] "Your query matched %(file)g file in %(directories)g directories" msgstr[2] "Your query matched %(file)g files in %(directories)g directories"
- tinganho 12y agongettext can't handle two plural words well.