Git Product home page Git Product logo

pluralnet's Introduction

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

 

pluralnet's People

Contributors

dalexsoto avatar madd0 avatar rudyhuyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pluralnet's Issues

Use CultureInfo.CurrentUICulture instead of ResourceLanguage resource?

In the README file, it says that the resource files need to have a ResourceLanguage key in order to identify the language that is being used. It gives as an example fr_FR. The ResourceLoaderExtension class then takes that value and creates a CultureInfo instance.

It appears, however, that the CultureInfo class is unable to parse cultures that use the underscore as a language/locale separator. I guess that the README file should be updated to use a hyphen and/or the class could make the replacement at runtime to support both syntaxes.

Then again, is using the ResourceLanguage key really necessary? I ran a test on a UWP app on Windows 10 (didn't run any other combinations) and CultureInfo.CurrentUICulture is consistently providing the expected value. This makes sense, given that this is supposed to be the CultureInfo instance used by the resource manager to look up culture-specific resources.

If anyone's interested in testing on other platforms, I can create a PR.

Looks like an issue in FilipinoProvider

if (imod10 != 4 && imod10 != 6 || imod10 != 9)
return PluralType.ONE;

this if statement always evaluates to true.. should it be

if (imod10 != 4 && imod10 != 6 && imod10 != 9)
return PluralType.ONE;

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.