Class TlumachComponentBase
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
Culture
Gets the culture snapshot used by the T methods.
protected TlumachCulture Culture { get; }
Property Value
CultureState
Gets or sets the culture state of the user, e.g. for switching the language.
[Inject]
protected TlumachCultureState CultureState { get; set; }
Property Value
Methods
OnCultureChangedAsync(TlumachCulture)
Called before the component re-renders because the user has switched the language.
protected virtual Task OnCultureChangedAsync(TlumachCulture culture)
Parameters
cultureTlumachCultureThe 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
parametersParameterViewThe 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
unitBaseTranslationUnitThe 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
unitBaseTranslationUnitThe translation unit.
argsIDictionary<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
unitBaseTranslationUnitThe translation unit.
valuesobject[]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
unitBaseTranslationUnitThe translation unit.
argsTArgsThe object that supplies the values.
Returns
- string
The text.
Type Parameters
TArgsThe type that supplies the values.