Reputation: 4068
I'm trying to apply localization on _Layout.cshtml
_Layout.cshtml
@using Microsoft.AspNetCore.Http.Extensions
@using Microsoft.AspNetCore.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
@inject IViewLocalizer LayoutLocalizer
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="margin:38px;margin-top:56px;" class="hidden-sm-down">
<h2>@LayoutLocalizer["WelcomeHeader"] <b class="text_border_darkblue">MyTitle</b></h2>
<div style="text-align:center;margin-top:42px;">
@LayoutLocalizer["WelcomeSub"]
</div>
</div>
</body>
</html>
The resource files are named named: Views.Shared._Layout.no.resx (I've tried renaming to views.shared.Layout.no.resx without any luck)
Upvotes: 10
Views: 6028
Reputation: 759
You must create a _Layout.no.resx file within the same path of the views but as a root the "Resources" folder. See sample image:
There is a video clarifying the use of Location see here
Upvotes: 8
Reputation: 4068
Solution
Implement SharedResources with resource files and use Localization on the SharedResources object in shared Views
Upvotes: 3
Reputation: 111
You can combine IViewLocalizer
and IHtmlLocalizer
for _Layout.cshtml
. If you define a resource folder inside your Visual Studio solution you can put the resource files there.
If you are using razor pages instead of MVC views inside your ASP.net core application you create a subfolder Pages instead of Views inside the folder Resources. Put the _Layout.no.resx
file in there. e.g. Resources\Pages\_Layout.no.resx
.
Upvotes: 0