-
Notifications
You must be signed in to change notification settings - Fork 966
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
060fee1
Add Slovenian localization. Dual grammatical number included.
094ca5b
Add additional formatting rules for numbers three and four.
e21c412
added #244 to release notes
4494efb
Fixed a typo in SlovenianFormatter.
MitjaBezensek 6a352e5
Fixed the typo in SlovenianFormatter.
MitjaBezensek 8a6ed41
Fixed a problem with zero time resource value.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
145 changes: 145 additions & 0 deletions
145
src/Humanizer.Tests/Localisation/sl/DateHumanizeTests.cs
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,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")] | ||
[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
85
src/Humanizer.Tests/Localisation/sl/TimeSpanHumanizeTests.cs
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,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()); | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Humanizer/Localisation/Formatters/SlovenianFormatter.cs
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,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; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)