-
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.
- Loading branch information
Showing
1 changed file
with
22 additions
and
23 deletions.
There are no files selected for viewing
45 changes: 22 additions & 23 deletions
45
src/Humanizer/Localisation/Formatters/RomanianFormatter.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,29 +1,28 @@ | ||
namespace Humanizer | ||
namespace Humanizer; | ||
|
||
class RomanianFormatter() : | ||
DefaultFormatter("ro") | ||
{ | ||
class RomanianFormatter() : | ||
DefaultFormatter("ro") | ||
{ | ||
const int PrepositionIndicatingDecimals = 2; | ||
const int MaxNumeralWithNoPreposition = 19; | ||
const int MinNumeralWithNoPreposition = 1; | ||
const string UnitPreposition = " de"; | ||
const int PrepositionIndicatingDecimals = 2; | ||
const int MaxNumeralWithNoPreposition = 19; | ||
const int MinNumeralWithNoPreposition = 1; | ||
const string UnitPreposition = " de"; | ||
|
||
static readonly double Divider = Math.Pow(10, PrepositionIndicatingDecimals); | ||
static readonly double Divider = Math.Pow(10, PrepositionIndicatingDecimals); | ||
|
||
protected override string Format(TimeUnit unit, string resourceKey, int number, bool toWords = false) | ||
{ | ||
var format = Resources.GetResource(GetResourceKey(resourceKey, number), Culture); | ||
var preposition = ShouldUsePreposition(number) | ||
? UnitPreposition | ||
: string.Empty; | ||
protected override string Format(TimeUnit unit, string resourceKey, int number, bool toWords = false) | ||
{ | ||
var format = Resources.GetResource(GetResourceKey(resourceKey, number), Culture); | ||
var preposition = ShouldUsePreposition(number) | ||
? UnitPreposition | ||
: string.Empty; | ||
|
||
return string.Format(format, number, preposition); | ||
} | ||
return string.Format(format, number, preposition); | ||
} | ||
|
||
static bool ShouldUsePreposition(int number) | ||
{ | ||
var prepositionIndicatingNumeral = Math.Abs(number % Divider); | ||
return prepositionIndicatingNumeral is < MinNumeralWithNoPreposition or > MaxNumeralWithNoPreposition; | ||
} | ||
static bool ShouldUsePreposition(int number) | ||
{ | ||
var prepositionIndicatingNumeral = Math.Abs(number % Divider); | ||
return prepositionIndicatingNumeral is < MinNumeralWithNoPreposition or > MaxNumeralWithNoPreposition; | ||
} | ||
} | ||
} |