Skip to content

Commit

Permalink
Use more common Megabyte etc. plural form without plural 's'
Browse files Browse the repository at this point in the history
  • Loading branch information
hangy committed Jul 3, 2021
1 parent cee0272 commit c3732ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Expand Up @@ -16,7 +16,7 @@ public void ReturnsSingularBit()
[Fact]
public void ReturnsPluralBits()
{
Assert.Equal("2 Bits", ByteSize.FromBits(2).ToFullWords());
Assert.Equal("2 Bit", ByteSize.FromBits(2).ToFullWords());
}

[Fact]
Expand All @@ -28,7 +28,7 @@ public void ReturnsSingularByte()
[Fact]
public void ReturnsPluralBytes()
{
Assert.Equal("10 Bytes", ByteSize.FromBytes(10).ToFullWords());
Assert.Equal("10 Byte", ByteSize.FromBytes(10).ToFullWords());
}

[Fact]
Expand All @@ -40,7 +40,7 @@ public void ReturnsSingularKiloByte()
[Fact]
public void ReturnsPluralKilobytes()
{
Assert.Equal("10 Kilobytes", ByteSize.FromKilobytes(10).ToFullWords());
Assert.Equal("10 Kilobyte", ByteSize.FromKilobytes(10).ToFullWords());
}

[Fact]
Expand All @@ -52,7 +52,7 @@ public void ReturnsSingularMegabyte()
[Fact]
public void ReturnsPluralMegabytes()
{
Assert.Equal("10 Megabytes", ByteSize.FromMegabytes(10).ToFullWords());
Assert.Equal("10 Megabyte", ByteSize.FromMegabytes(10).ToFullWords());
}

[Fact]
Expand All @@ -64,7 +64,7 @@ public void ReturnsSingularGigabyte()
[Fact]
public void ReturnsPluralGigabytes()
{
Assert.Equal("10 Gigabytes", ByteSize.FromGigabytes(10).ToFullWords());
Assert.Equal("10 Gigabyte", ByteSize.FromGigabytes(10).ToFullWords());
}

[Fact]
Expand All @@ -76,12 +76,12 @@ public void ReturnsSingularTerabyte()
[Fact]
public void ReturnsPluralTerabytes()
{
Assert.Equal("10 Terabytes", ByteSize.FromTerabytes(10).ToFullWords());
Assert.Equal("10 Terabyte", ByteSize.FromTerabytes(10).ToFullWords());
}

[Theory]
[InlineData(229376, "B", "229376 Bytes")]
[InlineData(229376, "# KB", "224 Kilobytes")]
[InlineData(229376, "B", "229376 Byte")]
[InlineData(229376, "# KB", "224 Kilobyte")]
public void ToFullWordsFormatted(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, ByteSize.FromBytes(input).ToFullWords(format));
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/Configuration/FormatterRegistry.cs
Expand Up @@ -9,6 +9,7 @@ internal class FormatterRegistry : LocaliserRegistry<IFormatter>
public FormatterRegistry() : base(new DefaultFormatter("en-US"))
{
Register("ar", new ArabicFormatter());
Register("de", new GermanFormatter());
Register("he", new HebrewFormatter());
Register("ro", new RomanianFormatter());
Register("ru", new RussianFormatter());
Expand All @@ -32,7 +33,6 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US"))
RegisterDefaultFormatter("af");
RegisterDefaultFormatter("az");
RegisterDefaultFormatter("da");
RegisterDefaultFormatter("de");
RegisterDefaultFormatter("el");
RegisterDefaultFormatter("es");
RegisterDefaultFormatter("fa");
Expand Down
16 changes: 16 additions & 0 deletions src/Humanizer/Localisation/Formatters/GermanFormatter.cs
@@ -0,0 +1,16 @@
namespace Humanizer.Localisation.Formatters
{
internal class GermanFormatter : DefaultFormatter
{
public GermanFormatter()
: base("de")
{
}

/// <inheritdoc />
public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true)
{
return base.DataUnitHumanize(dataUnit, count, toSymbol)?.TrimEnd('s');
}
}
}

0 comments on commit c3732ca

Please sign in to comment.