chip-gameV3/Assets/Scripts/Common/PluralizeUtil.cs

44 lines
1.0 KiB
C#

public static class PluralizeUtil
{
public static string GetValutaPluralized(string valuta, int amount)
{
switch (valuta)
{
case "рубли": return Rubles(amount);
case "жетоны": return Tokens(amount);
default: return "Valuta_Error";
}
}
private static string Rubles(int n)
{
int lastDigit = n % 10;
int lastTwoDigits = n % 100;
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
return "рублей";
return lastDigit switch
{
1 => "рубль",
2 or 3 or 4 => "рубля",
_ => "рублей"
};
}
private static string Tokens(int n)
{
int lastDigit = n % 10;
int lastTwoDigits = n % 100;
if (lastTwoDigits >= 11 && lastTwoDigits <= 14)
return "жетонов";
return lastDigit switch
{
1 => "жетон",
2 or 3 or 4 => "жетона",
_ => "жетонов"
};
}
}