Reply to post: @Voyna I Mor Re: "The Go language does this very nicely." ?

Seven pet h8s: Verity is sorely vexed

Kristian Walsh Silver badge

@Voyna I Mor Re: "The Go language does this very nicely." ?

Yes, I mentioned Slavic languages in a follow-up post, as one reason why building strings in code is a really bad idea.

Welsh is the only living language that can beat the Slavic family on complexity of pluralisation rules, but these are actually quite rigid rules, and can be expressed simply by code. Here is the list of pluralisation rules for most of the world's languages:

http://www.unicode.org/cldr/charts/27/supplemental/language_plural_rules.html

Localisation toolkits like GNU Gettext have a pluralisation mechanism built in, which lets you selects the correct string for the value you're inserting ("%d day" or "%d days"), before inserting the value. It's also not limited to just two options, and the logic to select between the options is general enough to support any pluralisation scheme. If you want to know more, it's documented here: https://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms

If you're not on Linux (or a framework that relies on Gettext for its localisation), you can still use the same procedure, with only a small amount of additional code. The trick is knowing that you might have to do this; once you know you need to do it, implementing it is trivial. (I use a small C# class called PluralStringFormatter that implements this logic; with a "string selector" object that's implements the string selection according to the current locale )

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon