VitaliiTsilnyk / NGettext

A cross-platform .NET implementation of the GNU/Gettext library.
MIT License
215 stars 45 forks source link

Allow to pass a IFormatProvider to the Get*String functions #33

Closed Hugal31 closed 4 years ago

Hugal31 commented 4 years ago

Currently, the only way to use a custom IFormatProvider with NGettext is to subclass CultureInfo, which is not very convenient.

The Get*String methods of ICatalog could take a IFormatProvider, so one can use custom formatters. The given IFormatProvider would be in charge of formatting numbers and date correctly.

Usage example: I am trying to do a simple "grammar macro" text, which looks like this:

String.Format("{0:They} {0:are} coding in C#", myPerson);

Which could give He is coding in C#, or retrieve a translation with other formatters from the catalog, like {0:Il} cod{0:ent} en C#

Hugal31 commented 4 years ago

Alternatively, we could add a IFormatProvider CustomFormatProvider property used instead of the CultureInfo if it is not null.

VitaliiTsilnyk commented 4 years ago

Implemented in version 0.6.6. Thank you for suggestion.