Skip to content

Commit

Permalink
Lithuanian localization (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogix authored Feb 14, 2024
1 parent 4617faf commit 7eaffe1
Show file tree
Hide file tree
Showing 17 changed files with 1,362 additions and 2 deletions.
26 changes: 26 additions & 0 deletions NuSpecs/Humanizer.Core.lt.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata minClientVersion="2.12">
<id>Humanizer.Core.lt</id>
<version>$version$</version>
<title>Humanizer Locale (lt)</title>
<authors>Mehdi Khalili, Claire Novotny</authors>
<projectUrl>https://github.com/Humanizr/Humanizer</projectUrl>
<icon>logo.png</icon>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Humanizer Locale Lithuanian (lt)</description>
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
<license type="expression">MIT</license>
<repository type="$RepositoryType$" url="$RepositoryUrl$" commit="$RepositoryCommit$" />
<language>lv</language>

This comment has been minimized.

Copy link
@JustinasKilas

JustinasKilas Sep 25, 2024

Shouldn't this be lt rather than lv?

<dependencies>
<dependency id="Humanizer.Core" version="[$version$]" />
</dependencies>
</metadata>
<files>
<file src="Humanizer\bin\Release\netstandard1.0\lt\*.*" target="lib\netstandard1.0\lt" />
<file src="Humanizer\bin\Release\netstandard2.0\lt\*.*" target="lib\netstandard2.0\lt" />
<file src="Humanizer\bin\Release\net6.0\lt\*.*" target="lib\net6.0\lt" />
<file src="..\logo.png" target="logo.png" />
</files>
</package>
3 changes: 2 additions & 1 deletion NuSpecs/Humanizer.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<dependency id="Humanizer.Core.ko-KR" version="$version$" />
<dependency id="Humanizer.Core.ku" version="$version$" />
<dependency id="Humanizer.Core.lv" version="$version$" />
<dependency id="Humanizer.Core.lt" version="$version$" />
<dependency id="Humanizer.Core.ms-MY" version="$version$" />
<dependency id="Humanizer.Core.mt" version="$version$" />
<dependency id="Humanizer.Core.nb" version="$version$" />
Expand Down Expand Up @@ -66,7 +67,7 @@
<dependency id="Humanizer.Core.ku" version="$version$" />
</dependencies>
</metadata>
<files>
<files>
<file src="..\logo.png" target="logo.png" />
</files>
</package>
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 @@ -40,6 +40,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Localisation\is\ResourcesTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\is\TimeOnlyHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\is\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\lt\DateToOrdinalWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\lt\NumberToWordsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\lt\TimeSpanHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Localisation\pt-BR\TimeToClockNotationTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TimeOnlyHumanizeTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DateTimeHumanizePrecisionStrategyTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Xunit;

namespace Humanizer.Tests.Localisation.lt
{
[UseCulture("lt")]
public class DateToOrdinalWordsTests
{
[Fact]
public void OrdinalizeString()
{
Assert.Equal("2015 m. sausio 1 d.", new DateTime(2015, 1, 1).ToOrdinalWords());
}

#if NET6_0_OR_GREATER
[Fact]
public void OrdinalizeDateOnlyString()
{
Assert.Equal("2015 m. sausio 1 d.", new DateOnly(2015, 1, 1).ToOrdinalWords());
}
#endif
}
}
556 changes: 556 additions & 0 deletions src/Humanizer.Tests.Shared/Localisation/lt/NumberToWordsTests.cs

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions src/Humanizer.Tests.Shared/Localisation/lt/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using Humanizer.Localisation;
using Xunit;

namespace Humanizer.Tests.Localisation.lt
{
[UseCulture("lt")]
public class TimeSpanHumanizeTests
{
[Theory]
[Trait("Translation", "Native speaker")]
[InlineData(366, "1 metai")]
[InlineData(731, "2 metai")]
[InlineData(1096, "3 metai")]
[InlineData(4018, "11 metų")]
public void Years(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
[Trait("Translation", "Native speaker")]
[InlineData(31, "1 mėnuo")]
[InlineData(61, "2 mėnesiai")]
[InlineData(280, "9 mėnesiai")]
[InlineData(330, "10 mėnesių")]
public void Months(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Year));
}

[Theory]
[InlineData(7, "1 savaitė")]
[InlineData(14, "2 savaitės")]
[InlineData(21, "3 savaitės")]
[InlineData(77, "11 savaičių")]
[InlineData(147, "21 savaitė")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[InlineData(1, "1 diena")]
[InlineData(2, "2 dienos")]
[InlineData(9, "9 dienos")]
[InlineData(10, "10 dienų")]
[InlineData(17, "17 dienų")]
[InlineData(21, "21 diena")]
public void Days(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize(maxUnit: TimeUnit.Day));
}

[Theory]
[InlineData(1, "1 valanda")]
[InlineData(2, "2 valandos")]
[InlineData(3, "3 valandos")]
[InlineData(9, "9 valandos")]
[InlineData(10, "10 valandų")]
[InlineData(19, "19 valandų")]
[InlineData(21, "21 valanda")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

[Theory]
[InlineData(1, "1 minutė")]
[InlineData(2, "2 minutės")]
[InlineData(3, "3 minutės")]
[InlineData(9, "9 minutės")]
[InlineData(10, "10 minučių")]
[InlineData(19, "19 minučių")]
[InlineData(21, "21 minutė")]
public void Minutes(int minutes, string expected)
{
Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize());
}

[Theory]
[InlineData(1, "1 sekundė")]
[InlineData(2, "2 sekundės")]
[InlineData(3, "3 sekundės")]
[InlineData(9, "9 sekundės")]
[InlineData(10, "10 sekundžių")]
[InlineData(19, "19 sekundžių")]
[InlineData(21, "21 sekundė")]
public void Seconds(int seconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize());
}

[Theory]
[InlineData(1, "1 milisekundė")]
[InlineData(2, "2 milisekundės")]
[InlineData(3, "3 milisekundės")]
[InlineData(9, "9 milisekundės")]
[InlineData(10, "10 milisekundžių")]
[InlineData(19, "19 milisekundžių")]
[InlineData(21, "21 milisekundė")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
public void NoTime()
{
Assert.Equal("0 milisekundžių", TimeSpan.Zero.Humanize());
}

[Fact]
public void NoTimeToWords()
{
Assert.Equal("nėra laiko", TimeSpan.Zero.Humanize(toWords: true));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public DateOnlyToOrdinalWordsConverterRegistry() : base(new DefaultDateOnlyToOrd
Register("en-US", new UsDateOnlyToOrdinalWordsConverter());
Register("fr", new FrDateOnlyToOrdinalWordsConverter());
Register("es", new EsDateOnlyToOrdinalWordsConverter());
Register("lt", new LtDateOnlyToOrdinalWordsConverter());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public DateToOrdinalWordsConverterRegistry() : base(new DefaultDateToOrdinalWord
Register("en-US", new UsDateToOrdinalWordsConverter());
Register("fr", new FrDateToOrdinalWordsConverter());
Register("es", new EsDateToOrdinalWordsConverter());
Register("lt", new LtDateToOrdinalWordsConverter());
}
}
}
1 change: 1 addition & 0 deletions src/Humanizer/Configuration/FormatterRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public FormatterRegistry() : base(new DefaultFormatter("en-US"))
RegisterDefaultFormatter("zh-Hant");
RegisterDefaultFormatter("th-TH");
RegisterDefaultFormatter("en-IN");
Register("lt", new LithuanianFormatter());
}

private void RegisterDefaultFormatter(string localeCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public NumberToWordsConverterRegistry()
Register("lv", new LatvianNumberToWordsConverter());
Register("ko-KR", new KoreanNumberToWordsConverter());
Register("en-IN", new IndianNumberToWordsConverter());

Register("lt", new LithuanianNumberToWordsConverter());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if NET6_0_OR_GREATER
using System;

namespace Humanizer.Localisation.DateToOrdinalWords
{
internal class LtDateOnlyToOrdinalWordsConverter : IDateOnlyToOrdinalWordConverter
{
public string Convert(DateOnly date)
{
return date.ToString("yyyy 'm.' MMMM d 'd.'");
}

public string Convert(DateOnly date, GrammaticalCase grammaticalCase)
{
return Convert(date);
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Humanizer.Localisation.DateToOrdinalWords
{
internal class LtDateToOrdinalWordsConverter : IDateToOrdinalWordConverter
{
public string Convert(DateTime date)
{
return date.ToString("yyyy 'm.' MMMM d 'd.'");
}

public string Convert(DateTime date, GrammaticalCase grammaticalCase)
{
return Convert(date);
}
}
}
39 changes: 39 additions & 0 deletions src/Humanizer/Localisation/Formatters/LithuanianFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Humanizer.Localisation.GrammaticalNumber;

namespace Humanizer.Localisation.Formatters
{
internal class LithuanianFormatter : DefaultFormatter
{
public LithuanianFormatter()
: base("lt")
{
}

protected override string GetResourceKey(string resourceKey, int number)
{
if (resourceKey == "TimeSpanHumanize_Zero")
{
return resourceKey;
}

var grammaticalNumber = LithuanianNumberFormDetector.Detect(number);
var suffix = GetSuffix(grammaticalNumber);
return resourceKey + suffix;
}

private static string GetSuffix(LithuanianNumberForm form)
{
if (form == LithuanianNumberForm.Singular)
{
return "_Singular";
}

if (form == LithuanianNumberForm.GenitivePlural)
{
return "_Plural";
}

return "";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Humanizer.Localisation.GrammaticalNumber
{
internal enum LithuanianNumberForm
{
Singular,
Plural,
GenitivePlural
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Humanizer.Localisation.GrammaticalNumber
{
internal static class LithuanianNumberFormDetector
{
public static LithuanianNumberForm Detect(long number)
{
var tens = number % 100 / 10;
var units = number % 10;

if (tens == 1 || units == 0) // 10-19, 20, 30, 40 ... 100, 110 ..
{
return LithuanianNumberForm.GenitivePlural;
}

if (units == 1) // 1, 21, 31, 41 ... 91, 101, 121 ...
{
return LithuanianNumberForm.Singular;
}

// 2-9, 22-29, 32 ...
return LithuanianNumberForm.Plural;
}
}
}
Loading

0 comments on commit 7eaffe1

Please sign in to comment.