Skip to main content

Curiosus.Localization.MVC

NuGet Downloads Coverage

ASP.NET Core MVC add-on for Curiosus.Localization: returns source-text based translations as LocalizedHtmlString for Razor views and adds plural-form helpers for IViewLocalizer.

Installation​

dotnet add package Curiosus.Localization.MVC

Usage​

MvcLocalizerCore extends LocalizerCore with GetHtml, which returns a LocalizedHtmlString that Razor renders with HTML encoding of the arguments:

public static class ViewLNG
{
private static readonly LocalizationOptions Options = new();
private static readonly MvcLocalizerCore Localizer = new(typeof(ViewLNG).Assembly, Options);

public static LocalizedHtmlString Html(string source, params object[] arguments)
{
return Localizer.GetHtml(Options.Prefix, source, arguments);
}
}
<h1>@ViewLNG.Html("Добро пожаловать, {0}!", Model.UserName)</h1>

Unlike LocalizerCore.Get, GetHtml always looks the text up in the resources (falling back to the source text), including for the default language.

Plural forms with the standard IViewLocalizer (looks up key_1, key_2 or key_5):

@inject IViewLocalizer Localizer
<span>@Localizer.GetQuantityString("OrdersCount", Model.Count, Model.Count)</span>

See also​