Select theme:
You can easily localize your Blazor application - add different cultures and change the UI messages by visually editing resource files (.resx).
The first step to localizing a Blazor applications is to add cultures.
Radzen Blazor Studio will:
CulturePicker
component to MainLayout.razor
which allows the user to chose the current culture.Let's test that by showing a value that has culture-specific display. For example DateTime.Now.ToLongDateString()
.
@DateTime.Now.ToLongDateString()
.Now run the application and try changing the culture from the dropdown. You should see the date changing.
The next step is to localize the messages that your page displays based on the current culture. In .NET this is done via resource files. Here is how to easily do that with Radzen Blazor Studio.
RadzenText
.Text
property of RadzenText
. Click Radzen Blazor Studio injects a property L
of type IStringLocalizer
in localized pages. You can use it to localize messages in C# code:
var message = L["Text1"]; // A key "Text1" should exist in the resx file.
To localize C# code which is not page related follow the Microsoft instructions:
AccountController.cs
. Create a new resx file named AccountController.en.resx
next to AccountController.cs
. The name is important - it should be the same as the file and have .<culture>.resx
as extension.
Add some keys and values to the resx file.<root>
<!-- XSD stuff -->
<data name="InvalidUser" xml:space="preserve">
<value>Invalid user name or password</value>
</data>
</root>
AccountController.cs
.using Microsoft.Extensions.Localization;
private IStringLocalizer<AccountController> L { get; set };
public AccountController(/* other parameters */, IStringLocalizer<AccountController> localizer)
{
/* other initialization */
L = localizer;
}
return RedirectWithError(L["InvalidUser"], redirectUrl);
Radzen is free to use. You can also test the premium features for 15 days.
Download NowSelect theme: