Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add German translations for ByteSize #1105

Merged
merged 2 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Humanizer.Tests.Shared/Bytes/ToFullWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace Humanizer.Tests.Bytes
{
[UseCulture("en")]
hangy marked this conversation as resolved.
Show resolved Hide resolved
public class ToFullWordsTests
{
[Fact]
Expand Down
3 changes: 3 additions & 0 deletions src/Humanizer.Tests.Shared/Humanizer.Tests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de-CH\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de-LI\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\DefaultFormatterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\Bytes\ByteSizeExtensionsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\Bytes\ToFullWordsTest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\Bytes\ToStringTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\CollectionFormatterTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\DateHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\de\NumberToWordsTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Xunit;

namespace Humanizer.Tests.Localisation.de.Bytes
{
[UseCulture("de-DE")]
public class ByteSizeExtensionsTests
{
[Theory]
[InlineData(2, null, "2 TB")]
[InlineData(2, "GB", "2048 GB")]
[InlineData(2.123, "#.#", "2,1 TB")]
public void HumanizesTerabytes(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Terabytes().Humanize(format));
}

[Theory]
[InlineData(0, null, "0 bit")]
[InlineData(0, "GB", "0 GB")]
[InlineData(2, null, "2 GB")]
[InlineData(2, "MB", "2048 MB")]
[InlineData(2.123, "#.##", "2,12 GB")]
public void HumanizesGigabytes(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Gigabytes().Humanize(format));
}

[Theory]
[InlineData(0, null, "0 bit")]
[InlineData(0, "MB", "0 MB")]
[InlineData(2, null, "2 MB")]
[InlineData(2, "KB", "2048 kB")]
[InlineData(2.123, "#", "2 MB")]
public void HumanizesMegabytes(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Megabytes().Humanize(format));
}

[Theory]
[InlineData(0, null, "0 bit")]
[InlineData(0, "KB", "0 kB")]
[InlineData(2, null, "2 kB")]
[InlineData(2, "B", "2048 B")]
[InlineData(2.123, "#.####", "2,123 kB")]
public void HumanizesKilobytes(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Kilobytes().Humanize(format));
}

[Theory]
[InlineData(0, null, "0 bit")]
[InlineData(0, "#.##", "0 bit")]
[InlineData(0, "#.## B", "0 B")]
[InlineData(0, "B", "0 B")]
[InlineData(2, null, "2 B")]
[InlineData(2000, "KB", "1,95 kB")]
[InlineData(2123, "#.##", "2,07 kB")]
[InlineData(10000000, "KB", "9765,63 kB")]
[InlineData(10000000, "#,##0 KB", "9.766 kB")]
[InlineData(10000000, "#,##0.# KB", "9.765,6 kB")]
public void HumanizesBytes(double input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Bytes().Humanize(format));
}

[Theory]
[InlineData(0, null, "0 bit")]
[InlineData(0, "b", "0 bit")]
[InlineData(2, null, "2 bit")]
[InlineData(12, "B", "1,5 B")]
[InlineData(10000, "#.# KB", "1,2 kB")]
public void HumanizesBits(long input, string format, string expectedValue)
{
Assert.Equal(expectedValue, input.Bits().Humanize(format));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Humanizer.Bytes;

using Xunit;

namespace Humanizer.Tests.Localisation.de.Bytes
{
[UseCulture("de-DE")]
public class ToFullWordsTests
{
[Fact]
public void ReturnsSingularBit()
{
Assert.Equal("1 Bit", ByteSize.FromBits(1).ToFullWords());
}

[Fact]
public void ReturnsPluralBits()
{
Assert.Equal("2 Bit", ByteSize.FromBits(2).ToFullWords());
}

[Fact]
public void ReturnsSingularByte()
{
Assert.Equal("1 Byte", ByteSize.FromBytes(1).ToFullWords());
}

[Fact]
public void ReturnsPluralBytes()
{
Assert.Equal("10 Byte", ByteSize.FromBytes(10).ToFullWords());
}

[Fact]
public void ReturnsSingularKiloByte()
{
Assert.Equal("1 Kilobyte", ByteSize.FromKilobytes(1).ToFullWords());
}

[Fact]
public void ReturnsPluralKilobytes()
{
Assert.Equal("10 Kilobyte", ByteSize.FromKilobytes(10).ToFullWords());
}

[Fact]
public void ReturnsSingularMegabyte()
{
Assert.Equal("1 Megabyte", ByteSize.FromMegabytes(1).ToFullWords());
}

[Fact]
public void ReturnsPluralMegabytes()
{
Assert.Equal("10 Megabyte", ByteSize.FromMegabytes(10).ToFullWords());
}

[Fact]
public void ReturnsSingularGigabyte()
{
Assert.Equal("1 Gigabyte", ByteSize.FromGigabytes(1).ToFullWords());
}

[Fact]
public void ReturnsPluralGigabytes()
{
Assert.Equal("10 Gigabyte", ByteSize.FromGigabytes(10).ToFullWords());
}

[Fact]
public void ReturnsSingularTerabyte()
{
Assert.Equal("1 Terabyte", ByteSize.FromTerabytes(1).ToFullWords());
}

[Fact]
public void ReturnsPluralTerabytes()
{
Assert.Equal("10 Terabyte", ByteSize.FromTerabytes(10).ToFullWords());
}

[Theory]
[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));
}
}
}
88 changes: 88 additions & 0 deletions src/Humanizer.Tests.Shared/Localisation/de/Bytes/ToStringTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Humanizer.Bytes;

using Xunit;

namespace Humanizer.Tests.Localisation.de.Bytes
{
[UseCulture("de-DE")]
public class ToStringTests
{
[Fact]
public void ReturnsLargestMetricSuffix()
{
Assert.Equal("10,5 kB", ByteSize.FromKilobytes(10.5).ToString());
}

[Fact]
public void ReturnsDefaultNumberFormat()
{
Assert.Equal("10,5 kB", ByteSize.FromKilobytes(10.5).ToString("KB"));
}

[Fact]
public void ReturnsProvidedNumberFormat()
{
Assert.Equal("10,1234 kB", ByteSize.FromKilobytes(10.1234).ToString("#.#### KB"));
}

[Fact]
public void ReturnsBits()
{
Assert.Equal("10 bit", ByteSize.FromBits(10).ToString("##.#### b"));
}

[Fact]
public void ReturnsBytes()
{
Assert.Equal("10 B", ByteSize.FromBytes(10).ToString("##.#### B"));
}

[Fact]
public void ReturnsKilobytes()
{
Assert.Equal("10 kB", ByteSize.FromKilobytes(10).ToString("##.#### KB"));
}

[Fact]
public void ReturnsMegabytes()
{
Assert.Equal("10 MB", ByteSize.FromMegabytes(10).ToString("##.#### MB"));
}

[Fact]
public void ReturnsGigabytes()
{
Assert.Equal("10 GB", ByteSize.FromGigabytes(10).ToString("##.#### GB"));
}

[Fact]
public void ReturnsTerabytes()
{
Assert.Equal("10 TB", ByteSize.FromTerabytes(10).ToString("##.#### TB"));
}

[Fact]
public void ReturnsSelectedFormat()
{
Assert.Equal("10,0 TB", ByteSize.FromTerabytes(10).ToString("0.0 TB"));
}

[Fact]
public void ReturnsLargestMetricPrefixLargerThanZero()
{
Assert.Equal("512 kB", ByteSize.FromMegabytes(.5).ToString("#.#"));
}

[Fact]
public void ReturnsLargestMetricPrefixLargerThanZeroForNegativeValues()
{
Assert.Equal("-512 kB", ByteSize.FromMegabytes(-.5).ToString("#.#"));
}

[Fact]
public void ReturnsBytesViaGeneralFormat()
{
Assert.Equal("10 B", $"{ByteSize.FromBytes(10)}");
}
}
}
2 changes: 1 addition & 1 deletion src/Humanizer/Configuration/FormatterRegistry.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
36 changes: 36 additions & 0 deletions src/Humanizer/Properties/Resources.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,40 @@
<data name="NNW_Short" xml:space="preserve">
<value>NNW</value>
</data>
<data name="DataUnit_Bit" xml:space="preserve">
<value>Bit</value>
</data>
<data name="DataUnit_BitSymbol" xml:space="preserve">
<value>bit</value>
</data>
<data name="DataUnit_Byte" xml:space="preserve">
<value>Byte</value>
</data>
<data name="DataUnit_ByteSymbol" xml:space="preserve">
<value>B</value>
</data>
<data name="DataUnit_Kilobyte" xml:space="preserve">
<value>Kilobyte</value>
</data>
<data name="DataUnit_KilobyteSymbol" xml:space="preserve">
<value>kB</value>
</data>
<data name="DataUnit_Megabyte" xml:space="preserve">
<value>Megabyte</value>
</data>
<data name="DataUnit_MegabyteSymbol" xml:space="preserve">
<value>MB</value>
</data>
<data name="DataUnit_Gigabyte" xml:space="preserve">
<value>Gigabyte</value>
</data>
<data name="DataUnit_GigabyteSymbol" xml:space="preserve">
<value>GB</value>
</data>
<data name="DataUnit_Terabyte" xml:space="preserve">
<value>Terabyte</value>
</data>
<data name="DataUnit_TerabyteSymbol" xml:space="preserve">
<value>TB</value>
</data>
</root>