Table of Contents

Class TlumachKeyTagHelper

Namespace
Tlumach.AspNetCore.Mvc
Assembly
Tlumach.AspNetCore.Mvc.dll

Replaces the content of an element with a translation: <h1 tlumach-key="Title"></h1> or <p tlumach-unit="Strings.Home.Intro" tlumach-arg-name="@Model.Name"></p>.

A key is looked up in three steps: with the prefix of the file that is being executed (e.g. "Views.Home.Index."), then with the prefix of the main view, then without a prefix (the shared key). The second step exists because a @section of a view runs while the layout executes, so the executing file is the layout there; thanks to it, a tag helper in a section finds the keys of its own view. The side effect is that a tag helper in a layout finds the keys of the current view, if the layout has no such key. TlumachViewLocalizer does not do that: it uses the file that is being executed and the shared key.

The translation is trusted HTML; values are HTML-encoded, except IHtmlContent values. Values of tlumach-arg-* and tlumach-args are C# expressions (@Model.Name, @("text")). tlumach-culture is the name of a culture; an invalid name throws CultureNotFoundException.

[HtmlTargetElement("*", Attributes = "tlumach-key")]
[HtmlTargetElement("*", Attributes = "tlumach-unit")]
public sealed class TlumachKeyTagHelper : TagHelper, ITagHelper, ITagHelperComponent
Inheritance
TlumachKeyTagHelper
Implements
Inherited Members

Constructors

TlumachKeyTagHelper(IHtmlLocalizerFactory)

Initializes a new instance of the TlumachKeyTagHelper class.

public TlumachKeyTagHelper(IHtmlLocalizerFactory factory)

Parameters

factory IHtmlLocalizerFactory

The factory registered by AddTlumachViewLocalization(IMvcBuilder, Action<TlumachViewLocalizationOptions>?).

Properties

Args

Gets or sets the positional placeholder values.

[HtmlAttributeName("tlumach-args")]
public IReadOnlyList<object?>? Args { get; set; }

Property Value

IReadOnlyList<object>

Culture

Gets or sets the name of the culture to use instead of the culture of the request.

[HtmlAttributeName("tlumach-culture")]
public string? Culture { get; set; }

Property Value

string

Key

Gets or sets the key of the translation.

[HtmlAttributeName("tlumach-key")]
public string? Key { get; set; }

Property Value

string

NamedArgs

Gets or sets the named placeholder values, set with tlumach-arg-{name} attributes.

[HtmlAttributeName("tlumach-all-args", DictionaryAttributePrefix = "tlumach-arg-")]
public IDictionary<string, object?> NamedArgs { get; set; }

Property Value

IDictionary<string, object>

Unit

Gets or sets the translation unit, e.g. a unit of a class created by Tlumach Generator.

[HtmlAttributeName("tlumach-unit")]
public BaseTranslationUnit? Unit { get; set; }

Property Value

BaseTranslationUnit

ViewContext

Gets or sets the context of the view; set by Razor.

[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }

Property Value

ViewContext

Methods

Process(TagHelperContext, TagHelperOutput)

Synchronously executes the TagHelper with the given context and output.

public override void Process(TagHelperContext context, TagHelperOutput output)

Parameters

context TagHelperContext

Contains information associated with the current HTML tag.

output TagHelperOutput

A stateful HTML element used to generate an HTML tag.