.NET 是否具有内置的多元化机制?

Does .NET have a built-in pluralisation mechanism?

为了正确处理复数,Qt 有QObject::tr(), gettext has ngettext, Rails has a good i18n API, Cocoa has .stringsdict files。所有这些系统都会考虑实际数字(数量)来确定给定语言的适当复数形式。

我知道 Humanizer, NGettext and PluralNet,但我正在寻找 .NET 中的 内置 等价物。它存在还是我运气不好?

这不完全是 built-in 解决方案,但有一个 Visual Studio 扩展,ReswPlus (on Visual Studio Marketplace), that leverages PluralNet 并生成以数字作为参数的方法,以自动为给定的选择正确的复数形式本地化。

以下是关于 pluralization 的自述文件的摘录:

资源:

| Key               | Value            | Comment           |
|-------------------|------------------|-------------------|
| MinutesLeft_One   | {0} minute left  | #ReswPlusTyped[Q] |
| MinutesLeft_Other | {0} minutes left |                   |

会自动生成如下代码:

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