Update Blazor loc 6.0 example (#24072)
parent
5286211f20
commit
35df907c2b
|
@ -476,17 +476,21 @@ For information on ordering the Localization Middleware in the middleware pipeli
|
||||||
|
|
||||||
The following example shows how to set the current culture in a cookie that can be read by the Localization Middleware.
|
The following example shows how to set the current culture in a cookie that can be read by the Localization Middleware.
|
||||||
|
|
||||||
Add the following namespaces to the top of the `Pages/_Layout.cshtml` file:
|
Modifications to the `Pages/_Host.cshtml` file require the following namespaces:
|
||||||
|
|
||||||
```csharp
|
* <xref:System.Globalization?displayProperty=fullName>
|
||||||
@using System.Globalization
|
* <xref:Microsoft.AspNetCore.Localization?displayProperty=fullName>
|
||||||
@using Microsoft.AspNetCore.Localization
|
|
||||||
```
|
|
||||||
|
|
||||||
Immediately after the opening `<body>` tag of `Pages/_Layout.cshtml`, add the following Razor expression:
|
`Pages/_Host.cshtml`:
|
||||||
|
|
||||||
```cshtml
|
```cshtml
|
||||||
|
@page "/"
|
||||||
|
@namespace {NAMESPACE}.Pages
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
@using System.Globalization
|
||||||
|
@using Microsoft.AspNetCore.Localization
|
||||||
@{
|
@{
|
||||||
|
Layout = "_Layout";
|
||||||
this.HttpContext.Response.Cookies.Append(
|
this.HttpContext.Response.Cookies.Append(
|
||||||
CookieRequestCultureProvider.DefaultCookieName,
|
CookieRequestCultureProvider.DefaultCookieName,
|
||||||
CookieRequestCultureProvider.MakeCookieValue(
|
CookieRequestCultureProvider.MakeCookieValue(
|
||||||
|
@ -494,8 +498,12 @@ Immediately after the opening `<body>` tag of `Pages/_Layout.cshtml`, add the fo
|
||||||
CultureInfo.CurrentCulture,
|
CultureInfo.CurrentCulture,
|
||||||
CultureInfo.CurrentUICulture)));
|
CultureInfo.CurrentUICulture)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<component type="typeof(App)" render-mode="ServerPrerendered" />
|
||||||
```
|
```
|
||||||
|
|
||||||
|
In the preceding example, the `{NAMESPACE}` placeholder is the app's assembly name.
|
||||||
|
|
||||||
For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see <xref:fundamentals/middleware/index#middleware-order>.
|
For information on ordering the Localization Middleware in the middleware pipeline of `Program.cs`, see <xref:fundamentals/middleware/index#middleware-order>.
|
||||||
|
|
||||||
If the app isn't configured to process controller actions:
|
If the app isn't configured to process controller actions:
|
||||||
|
|
Loading…
Reference in New Issue