Back to Devexpress

IXafCultureInfoService.SetCultureAsync(String) Method

expressappframework-devexpress-dot-expressapp-dot-blazor-dot-services-dot-ixafcultureinfoservice-dot-setcultureasync-x28-system-dot-string-x29.md

latest3.1 KB
Original Source

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.2.dll

NuGet Package : DevExpress.ExpressApp.Blazor

Declaration

csharp
Task SetCultureAsync(
    string culture
)
vb
Function SetCultureAsync(
    culture As String
) As Task

Parameters

NameTypeDescription
cultureString

A new culture.

|

Returns

TypeDescription
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 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

csharp
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"); 
    } 
}

See Also

Localize an XAF Application

IXafCultureInfoService Interface

IXafCultureInfoService Members

DevExpress.ExpressApp.Blazor.Services Namespace