Skip to content

Commit 93e524d

Browse files
committed
Broader globalization culture configuration
1 parent c787d87 commit 93e524d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

aspnetcore/blazor/globalization-localization.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,28 @@ app.UseRequestLocalization(new RequestLocalizationOptions()
299299
.AddSupportedUICultures(new[] { "en-US", "es-CR" }));
300300
```
301301

302+
Supported cultures (<xref:Microsoft.AspNetCore.Builder.RequestLocalizationOptions.AddSupportedCultures%2A>) adds the set of the supported cultures for *globalization* (date, number, and currency formatting). Supported UI cultures (<xref:Microsoft.AspNetCore.Builder.RequestLocalizationOptions.AddSupportedUICultures%2A>) adds the set of the supported UI cultures *for localization* (translated UI strings for rendering content).
303+
304+
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:
305+
306+
```csharp
307+
var uiCultures = new[] { "en-US", "es-CR" };
308+
309+
var formattingCultures = CultureInfo
310+
.GetCultures(CultureTypes.SpecificCultures)
311+
.Select(c => c.Name)
312+
.ToArray();
313+
314+
var localizationOptions = new RequestLocalizationOptions()
315+
.SetDefaultCulture(uiCultures[0])
316+
.AddSupportedCultures(formattingCultures )
317+
.AddSupportedUICultures(uiCultures );
318+
319+
app.UseRequestLocalization(localizationOptions);
320+
```
321+
322+
In the preceding example, [`CultureTypes.SpecificCultures`](xref:System.Globalization.CultureTypes) specifies cultures that are specific to a country/region.
323+
302324
For information on ordering the Localization Middleware in the middleware pipeline of the `Program` file, see <xref:fundamentals/middleware/index#middleware-order>.
303325

304326
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)