auron344
auron344

Reputation: 81

NET CORE 2.0 Put IHtmlLocalizer in _Layout and use it in .cshtml files

I have a question. Localization is working in my application correctly but it feels a bit clunky.

I mean, is there a way to put all of these imports and injections in _Layout.cshtml

@using Microsoft.AspNetCore.Mvc.Localization;
@using Voxel.WebApis.IDP.Resources;
@inject IHtmlLocalizer<General> GeneralLocalizer;

And use my GeneralLocalizer in the rest of pages? Or i have to put all the "injection" and "using" code in every .cshtml i want to localize?

Right now parser error forces me to copy paste the code in every .cshtml i want to put translations...

Any solution?

Upvotes: 0

Views: 362

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239380

This is pretty much exactly what _ViewImports.cshtml is for.

Upvotes: 2

Related Questions