Skip to content

Features: Pluralization support

Rudy Huyn edited this page Aug 1, 2019 · 2 revisions

ReswPlus can generate methods to easily access your pluralized strings. Simply right-click on your resw file, select ReswPlus > Generate strongly typed class with pluralization, the nuget package ReswPlusLib will be automatically added to your project and generate all the functions necessary to manage your localization.

Example:

The resources:

Key Value Comment
MinutesLeft_One {0} minute left
MinutesLeft_Other {0} minutes left

Will automatically generate the following code:

#region MinutesLeft
/// <summary>
///   Get the pluralized version of the string similar to: {0} minute left
/// </summary>
public static string MinutesLeft(double number)
{
	return ReswPlusLib.ResourceLoaderExtension.GetPlural(_resourceLoader, "MinutesLeft", number);
}

ReswPlus will then automatically select one of the string based on the number passed as a parameter. While English has only 2 plural forms, some languages have up to 5 different forms, 196 different languages are supported by this library.

When used with string formatting (like the previous example), you can specify the parameter you want ReswPlus to use to select the correct plural form. Use the type Plural/Plural Double if you want to pass a double, Plural Int if you want to use an integer...

Pluralization can be used in combination with string formatting.

Example:

Key Value Comment
FileShared_One {0} shared {1} photo from {2} #Format[String username, Plural, String city]
FileShared_Other {0} shared {1} photos from {2}

Will generate:

#region FileShared
/// <summary>
///   Format the string similar to: {0} shared {1} photos from {2}
/// </summary>
public static string FileShared_Format(string username, double paramDouble2, string city)
{
    return string.Format(ReswPlusLib.ResourceLoaderExtension.GetPlural(_resourceLoader, "FileShared", paramDouble2), username, paramDouble2, city);
}
#endregion