4

I've got a C# WPF application I'm attempting to globalize with resx files. It works splendidly. I've run into a hitch, however. I've got a relatively simple solution for pluralisation where I have a singular and plural form of the string I'm displaying and I pick one based on the number of whatever things I'm talking about.

However, I've recently come to terms with the fact that some cultures have multiple plural forms. Has anyone come across a good solution to this problem in C#, let alone WPF?

The canonical example that I've seen for this problem comes from the Polish language. Polish has a singular, paucal, and plural form. This example is for the translation of the word "file":

  • 1 plik
  • 2,3,4 pliki
  • 5-21 pliko'w
  • 22-24 pliki
  • 25-31 pliko'w
dustyburwell
  • 5,755
  • 2
  • 27
  • 34
  • 1
    Example: in Polish, there are singular, paucal and plural terms, such as house which can be dom in singular, domy in paucal and domów in plural. Singular is 1, paucal is ranges 2-4, 22-24, 32-34, ... and plural is everything else. Rather more involved than English... – Sam Sep 16 '09 at 06:03
  • @Sam - Thank you for adding an example for me, I was on an iPod Touch when I asked this, so I needed to keep it short. – dustyburwell Sep 16 '09 at 13:08

4 Answers4

9

Mozilla has implemented this in Firefox 3, and they have a guide describing how to use their implementation here. Most notably, in the Developing with PluralForm section, they have a link

resource://gre/modules/PluralForm.jsm

to the source of their implementation. Must be opened from within Firefox 3 and higher.

I have not read through the whole thing, but this seems to be like a good place to at least get some ideas.

HTH.

AASoft
  • 1,346
  • 8
  • 13
  • Thanks for pointing this out to me! Even though it's not a C# solution, at least they have a listing of plural form rules that will definitely be helpful! – dustyburwell Sep 16 '09 at 13:14
4

Consider trying to just avoid the problem altogether. Instead of building sentences, try and build your UI to avoid the problem. Instead of saying "5 pages" try saying: "Pages: 5".

Yuliy
  • 17,381
  • 6
  • 41
  • 47
  • 1
    Absolutely! A problem avoided is a solution less to maintain. Even with a good code solution, the translator needs to enter the respective phrases in all forms. With all the variety and irregularities in plural forms, it's a lot of work and easy to make a mistake. – peterchen Sep 16 '09 at 06:15
  • 10
    Not trying to offend, but this just seems like a lazy way out. This seems like it would tend to dehumanize a product and would certainly decrease usability. – dustyburwell Sep 16 '09 at 13:10
  • There are languages where rephrasing like this is not possible or looks ugly. – kza May 21 '13 at 10:58
2

Localization like this takes consideration of the languages you want to translate to. Multiple plurals are fairly rare and I would imagine in most cases are interchangeable or context sensitive. Which unless it is being used in multiple places in your application you will not need to worry about. If you are doing this and a particular usage does create a grammatical error in plural usage then you need to add a new key across the board (all languages) for that one instance. Or, since you are detecting culture anyway, add an additional conditional for the affected language and use the single alternate plural form.

I would not suggest avoiding it as you can quickly lose the flow of natural language "Mins answered ago: 6".

Maybe you meant this in the first place but the far more common scenario is variations in syntactical placement across different cultures. For example, the string wanting to be localized "This page is viewed X times". You may want to make 3 localizable strings for this:

PageViewStart = "This page is viewed" PageViewEnd = "time" PageViewEndPlural = "times"

Then a simple pseudo-implementation would be

PageViewStart + pageCount.ToString() + pageCount == 1 ? PageViewEnd : PageViewEndPlural;

However in Dutch "Deze pagina is {0} keer bekeken" and in Korean "조회수 {0}". So you see you will immediatley run into problems with implementations on the multiple ways to format plural sentence structure across languages.

I purposely left a {0} in the examples as it alludes to my solution. Use a localization for the whole sentence in plural and non-plural.

PageView = "This page viewed 1 time." PageViewPlural = "This page viewed {0} times."

This way you can write the conditional (pseudo again depending on your implementation):

pageCount > 1 ? PageView : String.Format(PageViewPlural, pageCount.ToString());

The only thing is that your translators will need to be instructed as to the meaning and placement of the {0} token in the resx file.

  • For the first paragraph I was thinking of languages like Hungarian http://en.wiktionary.org/wiki/Category:Hungarian_nouns_with_multiple_plural_forms. –  Sep 16 '09 at 05:54
  • 6
    "Multiple plurals are fairly rare and I would imagine in most cases are interchangeable or context sensitive." ... yep, fairly rare. Like at least all Slavic languages rare. – Jenda Mar 07 '11 at 16:11
  • And the plural rulse applied here also assumes only English rules (one: n==1; other: n!= 1); this does not work for MANY languages (even for those that have only two forms, see CLDR data about this bad assumption; notably how to treat "zero", or the exact bound or condition between singular and plural, which also depends on the precision displayed!). Add also Celtic, Slavic, Arabic, Hebrew languages... that need more than 2 forms. The English rules are in fact rare in the world languages. – verdy_p Nov 25 '22 at 12:57
1

I guess yo uare aware of gettext's plural form handling. But generally, I'd try to avoid it (as Yuliy said).

It's not only the nouns - phrases can change (e.g. in German "1 Datei konnte nicht gelöscht werden" / "2 Dateien konnten nicht gelöscht werden").

It is much more friendly and elegant than the problem-evasive "Dateien, die nicht gelöscht werden konnten: 2", but there's a tradeoff in how many ressources you have for localization.

peterchen
  • 40,917
  • 20
  • 104
  • 186