Table of Contents

Class TlumachCulture

Namespace
Tlumach.Blazor
Assembly
Tlumach.Blazor.dll

An immutable snapshot of the culture of one user, cascaded to components by TlumachCultureState.

A component that declares a cascading parameter of this type is re-rendered when the user switches the language. The methods of this class retrieve texts for Culture explicitly, which is what keeps the users of a Blazor Server application apart.

public sealed class TlumachCulture
Inheritance
TlumachCulture
Inherited Members

Constructors

TlumachCulture(CultureInfo)

Initializes a new instance of the TlumachCulture class.

public TlumachCulture(CultureInfo culture)

Parameters

culture CultureInfo

The culture of the user.

Properties

Culture

Gets the culture of the user.

public CultureInfo Culture { get; }

Property Value

CultureInfo

Methods

Get(BaseTranslationUnit)

Returns the text of the unit for Culture as plain (not HTML-encoded) text, suitable for attributes and code.

public string Get(BaseTranslationUnit unit)

Parameters

unit BaseTranslationUnit

The translation unit.

Returns

string

The text.

Get(BaseTranslationUnit, IDictionary<string, object?>)

Returns the text of the unit for Culture with named placeholders replaced by the values in args.

public string Get(BaseTranslationUnit unit, IDictionary<string, object?> args)

Parameters

unit BaseTranslationUnit

The translation unit.

args IDictionary<string, object>

The values of the placeholders, keyed by placeholder names.

Returns

string

The text.

Get(BaseTranslationUnit, params object[])

Returns the text of the unit for Culture with indexed placeholders replaced by values.

public string Get(BaseTranslationUnit unit, params object[] values)

Parameters

unit BaseTranslationUnit

The translation unit.

values object[]

The values of the placeholders, in the order of their indexes.

Returns

string

The text.

GetFrom<TArgs>(BaseTranslationUnit, TArgs)

Returns the text of the unit for Culture with named placeholders replaced by the values of the public properties of args, e.g., an anonymous object. The trimmer keeps those properties, so this method is safe in trimmed applications.

public string GetFrom<TArgs>(BaseTranslationUnit unit, TArgs args)

Parameters

unit BaseTranslationUnit

The translation unit.

args TArgs

The object that supplies the values.

Returns

string

The text.

Type Parameters

TArgs

The type that supplies the values through its public properties.

Markup(BaseTranslationUnit)

Returns the text of the unit for Culture as markup. Use it only for translations that contain trusted HTML.

public MarkupString Markup(BaseTranslationUnit unit)

Parameters

unit BaseTranslationUnit

The translation unit.

Returns

MarkupString

The markup.

Markup(BaseTranslationUnit, IDictionary<string, object?>)

Returns the text of the unit for Culture with named placeholders replaced, as markup. Use it only for translations that contain trusted HTML.

The translation text is trusted, while the values are data: string values are HTML-encoded before they are substituted. To insert trusted HTML through a value, pass a MarkupString. Other values (numbers, dates, ...) are formatted as usual. When WebEncodeValues is set, the unit encodes the whole text, values included, and the values are not encoded again.

public MarkupString Markup(BaseTranslationUnit unit, IDictionary<string, object?> args)

Parameters

unit BaseTranslationUnit

The translation unit.

args IDictionary<string, object>

The values of the placeholders, keyed by placeholder names.

Returns

MarkupString

The markup.