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 Slovenian localisation #244

Closed
wants to merge 6 commits into from
Closed
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 release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###In Development
- [#236](https://github.com/Mehdik/Humanizer/pull/236): Added Turkish localisation
- [#239](https://github.com/Mehdik/Humanizer/pull/239): Added Serbian localisation
- [#244](https://github.com/MehdiK/Humanizer/pull/244): Added Slovenian localisation

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.24.1...master)

Expand Down
2 changes: 2 additions & 0 deletions src/Humanizer.Tests/Humanizer.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
<Compile Include="Localisation\pt-BR\DateHumanizeTests.cs" />
<Compile Include="Localisation\pt-BR\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\sk\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\sl\DateHumanizeTests.cs" />
<Compile Include="Localisation\sl\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\sr-Latn\DateHumanizeTests.cs" />
<Compile Include="Localisation\sr-Latn\TimeSpanHumanizeTests.cs" />
<Compile Include="Localisation\sr\DateHumanizeTests.cs" />
Expand Down
145 changes: 145 additions & 0 deletions src/Humanizer.Tests/Localisation/sl/DateHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using Humanizer.Localisation;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.sl
{
public class DateHumanizeTests : AmbientCulture
{
public DateHumanizeTests() : base("sl-SI") {}

[Theory]
[InlineData(-10, "pred 10 leti")]
[InlineData(-5, "pred 5 leti")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for years 5 is the same as 3 and 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slovenian is quite a strange language. For years ago 3,4,5,... are the same. For years from now 3 and 4 are the same and everything from 5 on is the same.

This difference for numbers 3 and 4 occurs only when counting. We don't have actual trial or quadral grammatical numbers (we do have dual tho). I implemented this by using a different postfix for dual and one combined one for 3 and 4. Which is why some test seems duplicate since in some cases 3 and 4 are the same a 5. Those tests check if the resource files does indeed have the (duplicate) value for number 3 and 4.

Well testing for 10 could probably be omitted, since it's always the same as for 5.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe, cool. Thanks for explaining. Just wanted to make sure :)

[InlineData(-4, "pred 4 leti")]
[InlineData(-3, "pred 3 leti")]
[InlineData(-2, "pred 2 letoma")]
[InlineData(-1, "pred enim letom")]
public void YearsAgo(int years, string expected) {
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Past);
}

[Theory]
[InlineData(5, "čez 5 let")]
[InlineData(4, "čez 4 leta")]
[InlineData(3, "čez 3 leta")]
[InlineData(2, "čez 2 leti")]
[InlineData(1, "čez eno leto")]
public void YearsFromNow(int years, string expected) {
DateHumanize.Verify(expected, years, TimeUnit.Year, Tense.Future);
}

[Theory]
[InlineData(-10, "pred 10 meseci")]
[InlineData(-5, "pred 5 meseci")]
[InlineData(-4, "pred 4 meseci")]
[InlineData(-3, "pred 3 meseci")]
[InlineData(-2, "pred 2 mesecema")]
[InlineData(-1, "pred enim mesecem")]
public void MonthsAgo(int months, string expected) {
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Past);
}

[Theory]
[InlineData(5, "čez 5 mesecev")]
[InlineData(4, "čez 4 mesece")]
[InlineData(3, "čez 3 mesece")]
[InlineData(2, "čez 2 meseca")]
[InlineData(1, "čez en mesec")]
public void MonthsFromNow(int months, string expected) {
DateHumanize.Verify(expected, months, TimeUnit.Month, Tense.Future);
}

[Theory]
[InlineData(-10, "pred 10 dnevi")]
[InlineData(-5, "pred 5 dnevi")]
[InlineData(-4, "pred 4 dnevi")]
[InlineData(-3, "pred 3 dnevi")]
[InlineData(-2, "pred 2 dnevoma")]
[InlineData(-1, "včeraj")]
public void DaysAgo(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Past);
}

[Theory]
[InlineData(5, "čez 5 dni")]
[InlineData(4, "čez 4 dni")]
[InlineData(3, "čez 3 dni")]
[InlineData(2, "čez 2 dni")]
[InlineData(1, "jutri")]
public void DaysFromNow(int days, string expected)
{
DateHumanize.Verify(expected, days, TimeUnit.Day, Tense.Future);
}

[Theory]
[InlineData(-10, "pred 10 urami")]
[InlineData(-5, "pred 5 urami")]
[InlineData(-4, "pred 4 urami")]
[InlineData(-3, "pred 3 urami")]
[InlineData(-2, "pred 2 urama")]
[InlineData(-1, "pred eno uro")]
public void HoursAgo(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Past);
}

[Theory]
[InlineData(5, "čez 5 ur")]
[InlineData(4, "čez 4 ure")]
[InlineData(3, "čez 3 ure")]
[InlineData(2, "čez 2 uri")]
[InlineData(1, "čez eno uro")]
public void HoursFromNow(int hours, string expected)
{
DateHumanize.Verify(expected, hours, TimeUnit.Hour, Tense.Future);
}

[Theory]
[InlineData(-10, "pred 10 minutami")]
[InlineData(-5, "pred 5 minutami")]
[InlineData(-4, "pred 4 minutami")]
[InlineData(-3, "pred 3 minutami")]
[InlineData(-2, "pred 2 minutama")]
[InlineData(-1, "pred eno minuto")]
public void MinutesAgo(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Past);
}

[Theory]
[InlineData(5, "čez 5 minut")]
[InlineData(4, "čez 4 minute")]
[InlineData(3, "čez 3 minute")]
[InlineData(2, "čez 2 minuti")]
[InlineData(1, "čez eno minuto")]
public void MinutesFromNow(int minutes, string expected)
{
DateHumanize.Verify(expected, minutes, TimeUnit.Minute, Tense.Future);
}

[Theory]
[InlineData(-10, "pred 10 sekundami")]
[InlineData(-5, "pred 5 sekundami")]
[InlineData(-4, "pred 4 sekundami")]
[InlineData(-3, "pred 3 sekundami")]
[InlineData(-2, "pred 2 sekundama")]
[InlineData(-1, "pred eno sekundo")]
public void SecondsAgo(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Past);
}

[Theory]
[InlineData(10, "čez 10 sekund")]
[InlineData(5, "čez 5 sekund")]
[InlineData(4, "čez 4 sekunde")]
[InlineData(3, "čez 3 sekunde")]
[InlineData(2, "čez 2 sekundi")]
[InlineData(1, "čez eno sekundo")]
public void SecondsFromNow(int seconds, string expected)
{
DateHumanize.Verify(expected, seconds, TimeUnit.Second, Tense.Future);
}
}
}
85 changes: 85 additions & 0 deletions src/Humanizer.Tests/Localisation/sl/TimeSpanHumanizeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using Xunit;
using Xunit.Extensions;

namespace Humanizer.Tests.Localisation.sl
{
public class TimeSpanHumanizeTests : AmbientCulture
{
public TimeSpanHumanizeTests() : base("sl-SI") {}

[Theory]
[InlineData(7, "1 teden")]
[InlineData(14, "2 tedna")]
[InlineData(21, "3 tedne")]
[InlineData(28, "4 tedne")]
[InlineData(35, "5 tednov")]
[InlineData(77, "11 tednov")]
public void Weeks(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[InlineData(1, "1 dan")]
[InlineData(2, "2 dneva")]
[InlineData(3, "3 dni")]
[InlineData(4, "4 dni")]
[InlineData(5, "5 dni")]
public void Days(int days, string expected)
{
Assert.Equal(expected, TimeSpan.FromDays(days).Humanize());
}

[Theory]
[InlineData(1, "1 ura")]
[InlineData(2, "2 uri")]
[InlineData(3, "3 ure")]
[InlineData(4, "4 ure")]
[InlineData(5, "5 ur")]
public void Hours(int hours, string expected)
{
Assert.Equal(expected, TimeSpan.FromHours(hours).Humanize());
}

[Theory]
[InlineData(1, "1 minuta")]
[InlineData(2, "2 minuti")]
[InlineData(3, "3 minute")]
[InlineData(4, "4 minute")]
[InlineData(5, "5 minut")]
public void Minutes(int minutes, string expected)
{
Assert.Equal(expected, TimeSpan.FromMinutes(minutes).Humanize());
}


[Theory]
[InlineData(1, "1 sekunda")]
[InlineData(2, "2 sekundi")]
[InlineData(3, "3 sekunde")]
[InlineData(4, "4 sekunde")]
[InlineData(5, "5 sekund")]
public void Seconds(int seconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromSeconds(seconds).Humanize());
}

[Theory]
[InlineData(1, "1 milisekunda")]
[InlineData(2, "2 milisekundi")]
[InlineData(3, "3 milisekunde")]
[InlineData(4, "4 milisekunde")]
[InlineData(5, "5 milisekund")]
public void Milliseconds(int milliseconds, string expected)
{
Assert.Equal(expected, TimeSpan.FromMilliseconds(milliseconds).Humanize());
}

[Fact]
public void NoTime()
{
Assert.Equal("nič časa", TimeSpan.Zero.Humanize());
}
}
}
3 changes: 2 additions & 1 deletion src/Humanizer/Configuration/Configurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static class Configurator
{ "sk", () => new CzechSlovakPolishFormatter() },
{ "cs", () => new CzechSlovakPolishFormatter() },
{ "pl", () => new CzechSlovakPolishFormatter() },
{ "sr", () => new SerbianFormatter() }
{ "sr", () => new SerbianFormatter() },
{ "sl", () => new SlovenianFormatter() }
};

private static IDateTimeHumanizeStrategy _dateTimeHumanizeStrategy = new DefaultDateTimeHumanizeStrategy();
Expand Down
2 changes: 2 additions & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Localisation\Formatters\SerbianFormatter.cs" />
<Compile Include="Localisation\Formatters\SlovenianFormatter.cs" />
<Compile Include="Localisation\NumberToWords\BrazilianPortugueseNumberToWordsConverter.cs" />
<Compile Include="GrammaticalCase.cs" />
<Compile Include="GrammaticalGender.cs" />
Expand Down Expand Up @@ -163,6 +164,7 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.sl.resx" />
<EmbeddedResource Include="Properties\Resources.tr.resx" />
<EmbeddedResource Include="Properties\Resources.ja.resx" />
<EmbeddedResource Include="Properties\Resources.bg.resx" />
Expand Down
15 changes: 15 additions & 0 deletions src/Humanizer/Localisation/Formatters/SlovenianFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Humanizer.Localisation.Formatters{
internal class SlovenianFormatter : DefaultFormatter{
private const string DualPostfix = "_Dual";
private const string TrialQuadralPostfix = "_TrialQuadral";

protected override string GetResourceKey(string resourceKey, int number){
if (number == 2)
return resourceKey + DualPostfix;
// When the count is three or four some some words have a different form when counting in Slovenian language
else if (number == 3 || number == 4)
return resourceKey + TrialQuadralPostfix;
return resourceKey;
}
}
}
Loading