Table of Contents

Class BobLocalizerHtmlExtensions

Namespace
BlazOrbit.Localization
Assembly
BlazOrbit.Core.dll

HTML-aware helpers over Microsoft.Extensions.Localization.IStringLocalizer<T>. Use when a translation contains markup (e.g. <strong>, <br />) and the value must reach the DOM without Blazor's default HTML escaping.

public static class BobLocalizerHtmlExtensions
Inheritance
object
BobLocalizerHtmlExtensions

Remarks

Threat model. The translation template ships in source-controlled .tn files - audited the same way as inline Razor markup. Format arguments passed to Html<T>(IStringLocalizer<T>, string, params object?[]) are treated as untrusted and HTML-encoded before substitution so a runtime value can never inject markup. The resulting Microsoft.AspNetCore.Components.MarkupString is therefore safe whenever the consumer keeps:

  • translations under version control (no end-user editing),
  • dynamic values passed only as format arguments - not concatenated into the key string.

If a custom provider sources translations from an unvetted store (CMS, user-editable DB), run an HTML sanitiser before wrapping the value in Microsoft.AspNetCore.Components.MarkupString; the encoder here only neutralises the arguments, not the template.

Methods

Html<T>(IStringLocalizer<T>, string, params object?[])

Resolves name as HTML markup. Each entry of args is HTML-encoded via System.Text.Encodings.Web.HtmlEncoder.Default before being substituted into the template, so untrusted runtime values cannot inject markup. The template itself is rendered verbatim - author it with safe markup only.

public static MarkupString Html<T>(this IStringLocalizer<T> localizer, string name, params object?[] args)

Parameters

localizer IStringLocalizer<T>

The Microsoft.Extensions.Localization.IStringLocalizer<T> to resolve through.

name string

Translation key.

args object[]

Optional format arguments. Each is HTML-encoded before substitution.

Returns

MarkupString

A Microsoft.AspNetCore.Components.MarkupString ready to bind with @ in a Razor file.

Type Parameters

T

Bundle marker type.