IXafCultureInfoService.SetCultureAsync(String) Method
Saves the specified culture in CookieRequestCultureProvider.DefaultCookie and reloads the page.
Namespace: DevExpress.ExpressApp.Blazor.Services
Assembly: DevExpress.ExpressApp.Blazor.v25.1.dll
NuGet Package: DevExpress.ExpressApp.Blazor
Declaration
Parameters
| Name | Type | Description |
|---|---|---|
| culture | String | A new culture. |
Returns
| Type | Description |
|---|---|
| Task | A task that sets a new culture. |
Remarks
After calling the SetCultureAsync method, the XafApplication is recreated in a new culture. The new culture is read from cookies in RequestLocalizationMiddleware.
After calling the SetCultureAsync method, the application is reloaded even if the new culture is the same as the previous culture (that means that the culture was not changed).
Learn more: How to: Localize an XAF .NET Application (Blazor and WinForms)
Example
The code sample below demonstrates how to use the SetCultureAsync method to change the application localization.
File:
MySolution.Blazor.Server\Controllers\GermanCultureController.cs
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Blazor;
using DevExpress.ExpressApp.Blazor.Services;
using DevExpress.Persistent.Base;
// ...
public class GermanCultureController : ViewController {
BlazorApplication BlazorApplication => (BlazorApplication)Application;
IXafCultureInfoService CultureInfoService => (IXafCultureInfoService)BlazorApplication.ServiceProvider.GetService(typeof(IXafCultureInfoService));
public GermanCultureController() {
SimpleAction myAction = new SimpleAction(this, "SetGermanCulture", PredefinedCategory.Edit);
myAction.Execute += async (s, e) => await CultureInfoService.SetCultureAsync("de");
}
}