Skip to content

Commit 01ee9a2

Browse files
authored
Broader globalization culture configuration (#36247)
1 parent 41d7c86 commit 01ee9a2

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

aspnetcore/blazor/globalization-localization.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to render globalized and localized content to users in di
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 10/02/2025
8+
ms.date: 10/23/2025
99
uid: blazor/globalization-localization
1010
---
1111
# ASP.NET Core Blazor globalization and localization
@@ -289,7 +289,10 @@ In ***server-side development***, specify the app's supported cultures before an
289289

290290
:::moniker range="< aspnetcore-8.0"
291291

292-
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:
292+
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 using the following API:
293+
294+
* <xref:Microsoft.AspNetCore.Builder.RequestLocalizationOptions.AddSupportedCultures%2A> adds the set of the supported cultures for *globalization* (date, number, and currency formatting).
295+
* <xref:Microsoft.AspNetCore.Builder.RequestLocalizationOptions.AddSupportedUICultures%2A> adds the set of the supported UI cultures *for localization* (translated UI strings for rendering content).
293296

294297
:::moniker-end
295298

@@ -299,6 +302,26 @@ app.UseRequestLocalization(new RequestLocalizationOptions()
299302
.AddSupportedUICultures(new[] { "en-US", "es-CR" }));
300303
```
301304

305+
In the preceding example, the same supported formatting cultures and UI cultures are specified in a narrow case where the app is only used in the United States and Costa Rica. Alternatively, an app can use a broader set of cultures for date, number, and currency formatting but only provide localized content for the United States and Costa Rica, as the following example demonstrates:
306+
307+
```csharp
308+
var uiCultures = new[] { "en-US", "es-CR" };
309+
310+
var formattingCultures = CultureInfo
311+
.GetCultures(CultureTypes.SpecificCultures)
312+
.Select(c => c.Name)
313+
.ToArray();
314+
315+
var localizationOptions = new RequestLocalizationOptions()
316+
.SetDefaultCulture(uiCultures[0])
317+
.AddSupportedCultures(formattingCultures)
318+
.AddSupportedUICultures(uiCultures);
319+
320+
app.UseRequestLocalization(localizationOptions);
321+
```
322+
323+
In the preceding example, [`CultureTypes.SpecificCultures`](xref:System.Globalization.CultureTypes) returns only cultures that are specific to a country or region—such as `en-US` or `fr-FR`—which come with full, concrete globalization data (for dates, numbers, calendars, and other cultural UI) that .NET can use for accurate formatting and parsing. Neutral cultures, such as `en` or `fr`, may not have complete globalization data, so they aren't included in this list.
324+
302325
For information on ordering the Localization Middleware in the middleware pipeline of the `Program` file, see <xref:fundamentals/middleware/index#middleware-order>.
303326

304327
Use the `CultureExample1` component shown in the [Demonstration component](#demonstration-component) section to study how globalization works. Issue a request with United States English (`en-US`). Switch to Costa Rican Spanish (`es-CR`) in the browser's language settings. Request the webpage again.

0 commit comments

Comments
 (0)