Giter VIP home page Giter VIP logo

pluralnet's Introduction

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

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 push request!

more info

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

 

pluralnet's People

Contributors

madd0 avatar rudyhuyn avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.