Skip to content

Commit 970b696

Browse files
authored
Request Localization MW processing location (#33848)
1 parent 0965570 commit 970b696

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

aspnetcore/blazor/globalization-localization.md

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,17 @@ Add the following line to the `Program` file where services are registered:
254254
builder.Services.AddLocalization();
255255
```
256256

257-
In ***server-side development***, you can specify the app's supported cultures immediately after Routing Middleware is added to the processing pipeline. The following example configures supported cultures for United States English and Costa Rican Spanish:
257+
:::moniker range=">= aspnetcore-8.0"
258+
259+
In ***server-side development***, specify the app's supported cultures before any middleware that might check the request culture. Generally, place Request Localization Middleware immediately before calling <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A>. The following example configures supported cultures for United States English and Costa Rican Spanish:
260+
261+
:::moniker-end
262+
263+
:::moniker range="< aspnetcore-8.0"
264+
265+
In ***server-side development***, specify the app's supported cultures immediately after Routing Middleware (<xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting%2A>) is added to the processing pipeline. The following example configures supported cultures for United States English and Costa Rican Spanish:
266+
267+
:::moniker-end
258268

259269
```csharp
260270
app.UseRequestLocalization(new RequestLocalizationOptions()
@@ -371,7 +381,21 @@ In the `Program` file:
371381
builder.Services.AddLocalization();
372382
```
373383

374-
Specify the static culture in the `Program` file immediately after Routing Middleware is added to the processing pipeline. The following example configures United States English:
384+
:::moniker-end
385+
386+
:::moniker range=">= aspnetcore-8.0"
387+
388+
Specify the static culture in the `Program` file before any middleware that might check the request culture. Generally, place Request Localization Middleware immediately before <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A>. The following example configures United States English:
389+
390+
:::moniker-end
391+
392+
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
393+
394+
Specify the static culture in the `Program` file immediately after Routing Middleware (<xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting%2A>) is added to the processing pipeline. The following example configures United States English:
395+
396+
:::moniker-end
397+
398+
:::moniker range=">= aspnetcore-6.0"
375399

376400
```csharp
377401
app.UseRequestLocalization("en-US");
@@ -638,13 +662,13 @@ Set the app's default and supported cultures with <xref:Microsoft.AspNetCore.Bui
638662

639663
:::moniker range=">= aspnetcore-8.0"
640664

641-
Before the call to `app.MapRazorComponents` in the request processing pipeline, place the following code:
665+
Before the call to <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> in the request processing pipeline, place the following code:
642666

643667
:::moniker-end
644668

645669
:::moniker range="< aspnetcore-8.0"
646670

647-
After the call to `app.UseRouting` in the request processing pipeline, place the following code:
671+
After Routing Middleware (<xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting%2A>) is added to the request processing pipeline, place the following code:
648672

649673
:::moniker-end
650674

@@ -1125,7 +1149,7 @@ builder.Services.AddLocalization();
11251149

11261150
Set the app's default and supported cultures with <xref:Microsoft.AspNetCore.Builder.RequestLocalizationOptions>.
11271151

1128-
Before the call to `app.MapRazorComponents` in the request processing pipeline, place the following code:
1152+
Before the call to <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A> in the request processing pipeline, place the following code:
11291153

11301154
```csharp
11311155
var supportedCultures = new[] { "en-US", "es-CR" };
@@ -1366,7 +1390,21 @@ If the app doesn't already support dynamic culture selection:
13661390
builder.Services.AddLocalization();
13671391
```
13681392

1369-
Immediately after Routing Middleware is added to the processing pipeline:
1393+
:::moniker-end
1394+
1395+
:::moniker range=">= aspnetcore-8.0"
1396+
1397+
Place Request Localization Middleware before any middleware that might check the request culture. Generally, place the middleware immediately before calling <xref:Microsoft.AspNetCore.Builder.RazorComponentsEndpointRouteBuilderExtensions.MapRazorComponents%2A>:
1398+
1399+
:::moniker-end
1400+
1401+
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
1402+
1403+
Immediately after Routing Middleware (<xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting%2A>) is added to the processing pipeline:
1404+
1405+
:::moniker-end
1406+
1407+
:::moniker range=">= aspnetcore-6.0"
13701408

13711409
```csharp
13721410
var supportedCultures = new[] { "en-US", "es-CR" };
@@ -1393,7 +1431,7 @@ In `Startup.ConfigureServices` (`Startup.cs`):
13931431
services.AddLocalization();
13941432
```
13951433

1396-
In `Startup.Configure` immediately after Routing Middleware is added to the processing pipeline:
1434+
In `Startup.Configure` immediately after Routing Middleware (<xref:Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseRouting%2A>) is added to the processing pipeline:
13971435

13981436
```csharp
13991437
var supportedCultures = new[] { "en-US", "es-CR" };

0 commit comments

Comments
 (0)