-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TimeSpan as words for Russian and Ukrainian languages
- Loading branch information
Showing
12 changed files
with
176 additions
and
172 deletions.
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
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
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
39 changes: 9 additions & 30 deletions
39
src/Humanizer/Localisation/Formatters/IcelandicFormatter.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 |
---|---|---|
@@ -1,40 +1,19 @@ | ||
namespace Humanizer; | ||
|
||
class IcelandicFormatter() : | ||
DefaultFormatter(LocaleCode) | ||
DefaultFormatter("is") | ||
{ | ||
const string LocaleCode = "is"; | ||
readonly CultureInfo localCulture = new(LocaleCode); | ||
|
||
public override string DataUnitHumanize(DataUnit dataUnit, double count, bool toSymbol = true) => | ||
base.DataUnitHumanize(dataUnit, count, toSymbol).TrimEnd('s'); | ||
|
||
protected override string Format(string resourceKey, int number, bool toWords = false) | ||
{ | ||
var resourceString = Resources.GetResource(GetResourceKey(resourceKey, number), localCulture); | ||
|
||
if (toWords) | ||
{ | ||
var unitGender = GetGrammaticalGender(resourceString); | ||
return string.Format(resourceString, number.ToWords(unitGender, localCulture)); | ||
} | ||
|
||
return string.Format(resourceString, number); | ||
} | ||
protected override string NumberToWords(TimeUnit unit, int number, CultureInfo culture) => | ||
number.ToWords(GetUnitGender(unit), culture); | ||
|
||
static GrammaticalGender GetGrammaticalGender(string resource) | ||
{ | ||
if (resource.Contains(" mán") || | ||
resource.Contains(" dag")) | ||
static GrammaticalGender GetUnitGender(TimeUnit unit) => | ||
unit switch | ||
{ | ||
return GrammaticalGender.Masculine; | ||
} | ||
|
||
if (resource.Contains(" ár")) | ||
{ | ||
return GrammaticalGender.Neuter; | ||
} | ||
|
||
return GrammaticalGender.Feminine; | ||
} | ||
TimeUnit.Day or TimeUnit.Month => GrammaticalGender.Masculine, | ||
TimeUnit.Year => GrammaticalGender.Neuter, | ||
_ => GrammaticalGender.Feminine | ||
}; | ||
} |
Oops, something went wrong.