Table of Contents

Class TlumachComponentBase

Namespace
Tlumach.Blazor
Assembly
Tlumach.Blazor.dll

An optional base class for components that use translations in code or in attributes, where TlumachText cannot be placed.

The component re-renders when the user switches the language, because it takes the cascading TlumachCulture value. The class subscribes to no events, so it needs no disposal.

public abstract class TlumachComponentBase : ComponentBase, IComponent, IHandleEvent, IHandleAfterRender
Inheritance
TlumachComponentBase
Implements
Inherited Members

Properties

CascadedCulture

Gets or sets the cascaded culture snapshot.

[CascadingParameter]
protected TlumachCulture? CascadedCulture { get; set; }

Property Value

TlumachCulture

Culture

Gets the culture snapshot used by the T methods.

protected TlumachCulture Culture { get; }

Property Value

TlumachCulture

CultureState

Gets or sets the culture state of the user, e.g. for switching the language.

[Inject]
protected TlumachCultureState CultureState { get; set; }

Property Value

TlumachCultureState

Methods

OnCultureChangedAsync(TlumachCulture)

Called before the component re-renders because the user has switched the language.

protected virtual Task OnCultureChangedAsync(TlumachCulture culture)

Parameters

culture TlumachCulture

The new culture snapshot. Culture still returns the previous one during the call.

Returns

Task

A task that completes when the component has reacted.

SetParametersAsync(ParameterView)

Detects a change of the cascaded culture and, when it has changed, calls OnCultureChangedAsync(TlumachCulture) before the parameters are applied.

public override Task SetParametersAsync(ParameterView parameters)

Parameters

parameters ParameterView

The parameters.

Returns

Task

A task that completes when the parameters have been set.

T(BaseTranslationUnit)

Returns the text of the unit as plain text, suitable for attributes and code.

protected string T(BaseTranslationUnit unit)

Parameters

unit BaseTranslationUnit

The translation unit.

Returns

string

The text.

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

Returns the text of the unit with named placeholders replaced.

protected string T(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.

T(BaseTranslationUnit, params object[])

Returns the text of the unit with indexed placeholders replaced.

protected string T(BaseTranslationUnit unit, params object[] values)

Parameters

unit BaseTranslationUnit

The translation unit.

values object[]

The values of the placeholders.

Returns

string

The text.

TFrom<TArgs>(BaseTranslationUnit, TArgs)

Returns the text of the unit with named placeholders replaced by the public properties of args, e.g. an anonymous object.

The method has its own name: as an overload of T, it would win over the other overloads for arrays and dictionaries and silently change their meaning.

protected string TFrom<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.