Skip to content

Improve the localization of your application with support of plural forms. Support all existing languages and decimal numbers. Available for UWP, WinRT, Windows Phone, Xamarin Android and iOS, ASP.Net, .Net apps

License

Notifications You must be signed in to change notification settings

rudyhuyn/PluralNet

Repository files navigation

Important

PluralNet is now deprecated, all features from PluralNet are now part of a more advanced toolset created/managed by the same team, named ReswPlus: https://github.com/dotnetplus/reswplus

PluralNet - Pluralization for Resx and Resw files

PluralNet adds support of pluralization and plural forms to your application. Very easy to use and compatible with RESW and RESX files.

#How to use it?

A Nuget package is available, you can install it from Visual Studio or using the following command line:

Install-Package PluralNet

#Support plural forms in your resource files

Instead of one entry in your resource files, you must create one entry for each plural forms used by the language (One, Other, Few?, Many?, Zero?, Two?), used the _ symbol to separate the resource name to the plural form id

Example:

English:

  • TimeStampDay_One {0} day
  • TimeStampDay_Other {0} days

Polish (4 plural forms)

  • TimestampMonth_One {0} miesiąc temu
  • TimestampMonth_Few {0} miesiące temu
  • TimestampMonth_Many {0} miesięcy temu
  • TimestampMonth_Other {0} miesiąca temu

Silverlight only:

In order to use the correct plural rules, the library needs to know the language used by the app and not by the system (for example a polish phone displaying an english application need to use the english rule instead of polish). To do that, you need to add an extra entry in your RESW file (if not already done by Visual Studio):

  • ResourceLanguage fr-FR

Manage plural forms code-behind

If you use RESW:

An extension is available to extend the ResourceLoader class, instead of

ResourceLoader.GetForCurrentView().GetString("TimeStampDay");

you must use:

ResourceLoader.GetForCurrentView().GetPlural("TimeStampDay", <NUMBER>);

And optionally use string.Format(...) if your string supports formatting.

If you use RESX:

Instead of

AppResources.TimeStampDay;

use:

AppResources.ResourceManager.GetPlural("TimeStampDay", <NUMBER>);

You can then use string.Format(...) if your string supports formatting.

XAML

To use pluralization XAML-side, you can use the converter PluralConverter:

<TextBlock Text="{x:Bind NumberDays, Converter={StaticResource PluralConverter}, ConverterParameter=TimeStampDay}" />

If your localized string uses formatting, {0} will be automatically replaced by the number.

Platforms

The library supports:

  • UWP
  • Silverlight 5
  • Windows Phone Silverlight 8.0
  • Windows 8 and 8.1 WinRT apps
  • Windows Phone 8.1 WinPRT apps
  • ASP.Net Core
  • .Net Desktop apps (winform, wpf, etc...)
  • Xamarin Android and iOS

Language supported

Afrikaans, Akan, Albanian, Amharic, Arabic, Armenian, Assamese, Asturian, Asu, Azerbaijani, Bambara, Basque, Belarusian, Bemba, Bena, Bengali, Bihari, Bodo, Bosnian, Breton, Bulgarian, Burmese, Catalan, Central Atlas Tamazight, Central Kurdish, Chechen, Cherokee, Chiga, Chinese, Colognian, Cornish, Croatian, Czech, Danish, Divehi, Dutch, Dzongkha, English, Esperanto, Estonian, European Portuguese, Ewe, Faroese, Filipino, Finnish, French, Friulian, Fulah, Galician, Ganda, Georgian, German, Greek, Gujarati, Gun, Hausa, Hawaiian, Hebrew, Hindi, Hungarian, Icelandic, Igbo, Inari Sami, Indonesian, Inuktitut, Irish, Italian, Japanese, Javanese, Jju, Kabuverdianu, Kabyle, Kako, Kalaallisut, Kannada, Kashmiri, Kazakh, Khmer, Korean, Koyraboro Senni, Kurdish, Kyrgyz, Lakota, Langi, Lao, Latvian, Lingala, Lithuanian, Lojban, Lower Sorbian, Lule Sami, Luxembourgish, Macedonian, Machame, Makonde, Malagasy, Malay, Malayalam, Maltese, Manx, Marathi, Masai, Metaʼ, Moldavian, Mongolian, Nahuatl, Nama, Nepali, Ngiemboon, Ngomba, North Ndebele, Northern Sami, Northern Sotho, Norwegian, Norwegian Bokmål, Norwegian Nynorsk, Nyanja, Nyankole, N’Ko, Oriya, Oromo, Ossetic, Papiamento, Pashto, Persian, Polish, Portuguese, Prussian, Punjabi, Romanian, Romansh, Rombo, Root, Russian, Rwa, Saho, Sakha, Samburu, Sami languages [Other], Sango, Scottish Gaelic, Sena, Serbian, Serbo-Croatian, Shambala, Shona, Sichuan Yi, Sinhala, Skolt Sami, Slovak, Slovenian, Soga, Somali, South Ndebele, Southern Kurdish, Southern Sami, Southern Sotho, Spanish, Swahili, Swati, Swedish, Swiss German, Syriac, Tachelhit, Tagalog, Tamil, Telugu, Teso, Thai, Tibetan, Tigre, Tigrinya, Tongan, Tsonga, Tswana, Turkish, Turkmen, Tyap, Ukrainian, Upper Sorbian, Urdu, Uyghur, Uzbek, Venda, Vietnamese, Volapük, Vunjo, Walloon, Walser, Welsh, Western Frisian, Wolof, Xhosa, Yiddish, Yoruba, Zulu

How to help?

If you detect an issue, want to add a language, don't hesitate to submit a pull request!

more info

http://www.rudyhuyn.com/blog/?p=5341

 

About

Improve the localization of your application with support of plural forms. Support all existing languages and decimal numbers. Available for UWP, WinRT, Windows Phone, Xamarin Android and iOS, ASP.Net, .Net apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages