Skip to main content
Version: 2.10.1

Humanizer.Localisation.Formatters.DefaultFormatter

DefaultFormatter Class​

Default implementation of IFormatter interface.

public class DefaultFormatter : Humanizer.Localisation.Formatters.IFormatter

Inheritance System.Object → DefaultFormatter

Implements IFormatter

Constructors​

DefaultFormatter(string) Constructor​

Constructor.

public DefaultFormatter(string localeCode);

Parameters​

localeCode System.String

Name of the culture to use.

Methods​

DefaultFormatter.DataUnitHumanize(DataUnit, double, bool) Method​

Returns the string representation of the provided DataUnit, either as a symbol or full word

public virtual string DataUnitHumanize(Humanizer.Localisation.DataUnit dataUnit, double count, bool toSymbol=true);

Parameters​

dataUnit DataUnit

Data unit

count System.Double

Number of said units, to adjust for singular/plural forms

toSymbol System.Boolean

Indicates whether the data unit should be expressed as symbol or full word

Implements DataUnitHumanize(DataUnit, double, bool)

Returns​

System.String
String representation of the provided DataUnit

DefaultFormatter.DateHumanize(TimeUnit, Tense, int) Method​

Returns the string representation of the provided DateTime

public virtual string DateHumanize(Humanizer.Localisation.TimeUnit timeUnit, Humanizer.Localisation.Tense timeUnitTense, int unit);

Parameters​

timeUnit TimeUnit

timeUnitTense Tense

unit System.Int32

Implements DateHumanize(TimeUnit, Tense, int)

Returns​

System.String

DefaultFormatter.DateHumanize_Never() Method​

Never

public virtual string DateHumanize_Never();

Implements DateHumanize_Never()

Returns​

System.String
Returns Never

DefaultFormatter.DateHumanize_Now() Method​

Now

public virtual string DateHumanize_Now();

Implements DateHumanize_Now()

Returns​

System.String
Returns Now

DefaultFormatter.Format(string) Method​

Formats the specified resource key.

protected virtual string Format(string resourceKey);

Parameters​

resourceKey System.String

The resource key.

Returns​

System.String

Exceptions​

System.ArgumentException
If the resource not exists on the specified culture.

DefaultFormatter.Format(string, int, bool) Method​

Formats the specified resource key.

protected virtual string Format(string resourceKey, int number, bool toWords=false);

Parameters​

resourceKey System.String

The resource key.

number System.Int32

The number.

toWords System.Boolean

Returns​

System.String

Exceptions​

System.ArgumentException
If the resource not exists on the specified culture.

DefaultFormatter.GetResourceKey(string) Method​

protected virtual string GetResourceKey(string resourceKey);

Parameters​

resourceKey System.String

Returns​

System.String

DefaultFormatter.GetResourceKey(string, int) Method​

Override this method if your locale has complex rules around multiple units; e.g. Arabic, Russian

protected virtual string GetResourceKey(string resourceKey, int number);

Parameters​

resourceKey System.String

The resource key that's being in formatting

number System.Int32

The number of the units being used in formatting

Returns​

System.String

DefaultFormatter.TimeSpanHumanize(TimeUnit, int, bool) Method​

Returns the string representation of the provided TimeSpan

public virtual string TimeSpanHumanize(Humanizer.Localisation.TimeUnit timeUnit, int unit, bool toWords=false);

Parameters​

timeUnit TimeUnit

A time unit to represent.

unit System.Int32

toWords System.Boolean

Implements TimeSpanHumanize(TimeUnit, int, bool)

Returns​

System.String

Exceptions​

System.ArgumentOutOfRangeException
Is thrown when timeUnit is larger than TimeUnit.Week

DefaultFormatter.TimeSpanHumanize_Zero() Method​

0 seconds

public virtual string TimeSpanHumanize_Zero();

Implements TimeSpanHumanize_Zero()

Returns​

System.String
Returns 0 seconds as the string representation of Zero TimeSpan