-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PluralRule for DualFromZeroToTwo: Does not cover value of 2 The `Dictionary<string, PluralRuleDelegate> IsoLangToDelegate` is backed by a default dictionary. It can be restored with `PluralRules.RestoreDefault()` if one of the delegates was changed. Both has global effect. Extract class `CustomPluralRuleProvider` to its own file `PluralRuleDelegate DualFromZeroToTwo`: * with 3 words, the index is for counts of 0, > 0 and < 2, more than 2 * with 4 words, the index is for counts of 0, > 0 and < 2, >= 2 and < 3, more than 3 Add unit tests
- Loading branch information
Showing
4 changed files
with
235 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright SmartFormat Project maintainers and contributors. | ||
// Licensed under the MIT license. | ||
// | ||
|
||
using System; | ||
using SmartFormat.Utilities; | ||
|
||
namespace SmartFormat.Extensions; | ||
/// <summary> | ||
/// Use this class to provide custom plural rules to Smart.Format | ||
/// </summary> | ||
public class CustomPluralRuleProvider : IFormatProvider | ||
{ | ||
private readonly PluralRules.PluralRuleDelegate _pluralRule; | ||
|
||
/// <summary> | ||
/// Creates a new instance of a <see cref="CustomPluralRuleProvider"/>. | ||
/// </summary> | ||
/// <param name="pluralRule">The delegate for plural rules.</param> | ||
public CustomPluralRuleProvider(PluralRules.PluralRuleDelegate pluralRule) | ||
{ | ||
_pluralRule = pluralRule; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the format <see cref="object"/> for a <see cref="CustomPluralRuleProvider"/>. | ||
/// </summary> | ||
/// <param name="formatType"></param> | ||
/// <returns>The format <see cref="object"/> for a <see cref="CustomPluralRuleProvider"/> or <see langword="null"/>.</returns> | ||
public object? GetFormat(Type? formatType) | ||
{ | ||
return formatType == typeof(CustomPluralRuleProvider) ? this : default; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the <see cref="PluralRules.PluralRuleDelegate"/> of the current <see cref="CustomPluralRuleProvider"/> instance. | ||
/// </summary> | ||
/// <returns></returns> | ||
public PluralRules.PluralRuleDelegate GetPluralRule() | ||
{ | ||
return _pluralRule; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.