Skip to content

Backend Messages Localization

Ziya Mollamahmut edited this page May 7, 2020 · 1 revision

Custom error messages can be localized by injecting ISharedCultureLocalizer to the controller or PageModel as below:

using LazZiya.ExpressLocalization

public class IndexModel : PageModel
{
    private readonly ISharedCultureLocalizer _loc;

    public string CustomMessage { get; set; }

    public IndexModel(ISharedCultureLocalizer loc)
    {
        _loc = loc;
    }

    public void OnGet() 
    {
        CustomMessage = _loc["Localized custom backend message"];
    }
}

Extra: If you want to have bootstrap styled messages (Success, Warning, Danger, etc.) I suggest you have a look at AlertTagHelper in LazZiya.TagHelpers nuget package.

Clone this wiki locally