views:

314

answers:

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
+6  A: 

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
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
+3  A: 

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
+1 Interesting approach
Chuck Conway
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
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
+1  A: 

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.

Tim Schiller
For the first paragraph I was thinking of languages like Hungarian http://en.wiktionary.org/wiki/Category:Hungarian_nouns_with_multiple_plural_forms.
Tim Schiller
+1  A: 

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