SteinTech
SteinTech

Reputation: 4068

Localization on _Layout.cshtml

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

Answers (3)

Cesar Alvarado Diaz
Cesar Alvarado Diaz

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:

enter image description here

There is a video clarifying the use of Location see here

Upvotes: 8

SteinTech
SteinTech

Reputation: 4068

Solution

Implement SharedResources with resource files and use Localization on the SharedResources object in shared Views

Upvotes: 3

user2262068
user2262068

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

Related Questions