The Localize component emulates the ASP.NET Web Forms asp:Localize control. In Web Forms, Localize inherits directly from Literal and is functionally identical to it — the only difference is semantic. Localize marks text as localizable for design-time tooling and resource expression support (<%$ Resources:... %>). In Blazor, there is no design-time localization distinction, so this component exists purely for markup compatibility during migration.
Original Microsoft documentation: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.localize?view=netframework-4.8
Text- the text content to display (pass localized strings fromIStringLocalizer<T>)Mode- specifies how the content is rendered (Encode,PassThrough, orTransform)Visible- controls whether the text is rendered
Localizeinherits fromLiteraland behaves identically. All properties, rendering, and modes are inherited.- No wrapper HTML element is rendered — the text is output directly into the DOM.
- When
ModeisEncode(the default), text is HTML-encoded. WhenModeisPassThrough, text is rendered as raw markup.
!!! warning "Localization in Blazor"
In Web Forms, Localize enabled design-time localization via resource expressions like <%$ Resources:MyResource, MyKey %>. Blazor does not have resource expressions. Instead, inject IStringLocalizer<T> and pass localized strings to the Text property. See Microsoft's Blazor globalization documentation for details.
- Resource Expressions (
<%$ Resources:... %>) - Not supported in Blazor; useIStringLocalizer<T>instead - Design-time localization tooling - No Blazor equivalent; localization is handled at runtime via .NET localization APIs
- EnableTheming / SkinID - Theming is not supported in Blazor
<asp:Localize
EnableTheming="True|False"
EnableViewState="True|False"
ID="string"
Mode="Transform|PassThrough|Encode"
OnDataBinding="DataBinding event handler"
OnDisposed="Disposed event handler"
OnInit="Init event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnUnload="Unload event handler"
runat="server"
SkinID="string"
Text="string"
Visible="True|False"
/><Localize Text="Hello, World!" />@inject IStringLocalizer<MyPage> Localizer
<Localize Text="@Localizer["WelcomeMessage"]" /><Localize Text="<strong>Bold text</strong>" Mode="LiteralMode.PassThrough" />
<Localize Text="<script>alert('safe')</script>" Mode="LiteralMode.Encode" />Localize renders no wrapper HTML element — text is output directly into the DOM, identical to Literal.
Blazor Input:
<Localize Text="Hello, World!" />Rendered HTML:
Hello, World!With Mode=PassThrough:
<Localize Text="<em>emphasized</em>" Mode="LiteralMode.PassThrough" />Rendered HTML:
<em>emphasized</em>With Mode=Encode (default):
<Localize Text="<em>encoded</em>" Mode="LiteralMode.Encode" />Rendered HTML:
<em>encoded</em>When migrating from Web Forms to Blazor:
- Remove
asp:prefix - Change<asp:Localize>to<Localize> - Remove
runat="server"- Not needed in Blazor - Replace resource expressions - Replace
<%$ Resources:MyResource, MyKey %>withIStringLocalizer<T>injection - Static text - If the
Textwas hardcoded, no additional changes are needed
<asp:Localize ID="lblWelcome"
Text="<%$ Resources:Messages, WelcomeText %>"
Mode="Encode"
runat="server" />@inject IStringLocalizer<MyPage> Localizer
<Localize Text="@Localizer["WelcomeText"]" Mode="LiteralMode.Encode" />!!! tip "Consider Using Literal"
Since Localize is identical to Literal in Blazor, you can use either component interchangeably. If you are writing new Blazor code (not migrating), Literal is the conventional choice. Use Localize when migrating existing markup that already uses <asp:Localize> to minimize changes.
- Literal - Identical component; Localize inherits from Literal
- Blazor Globalization and Localization - Microsoft's guide to localization in Blazor