Localization Example: CRM RBS Sample Application
Hello,
I want to share an example of localization using LocoMat. I took the CRM sample from Radzen samples and processed it to create a (almost) fully localized application in Czech. You can find the source code on the GitHub repository:
CRM Sample - LocoMat GitHub Repository
This example demonstrates how LocoMat can be used to automate the localization process, making it easier to create applications in different languages. Feel free to explore the code and see how LocoMat simplifies the localization of Blazor applications.
In this example is new RadzenSupport
folder, which contains the scaffolded localization support for all Radzen controls. It includes the necessary resource files and code for localizing Radzen controls. This folder is created with scaffold
command.
How scaffold works?
- Creates overrided control which takes text from resource, for example DataFilter, original text is written to resource file
public class RadzenDataFilterLocalized<TItem> : RadzenDataFilter<TItem>
{
[Inject] RadzenLocalizer L { get; set; }
protected override void OnInitialized()
{
FilterText = L["RadzenDataFilter.FilterText"] ?? FilterText;
EnumFilterSelectText = L["RadzenDataFilter.EnumFilterSelectText"] ?? EnumFilterSelectText;
AndOperatorText = L["RadzenDataFilter.AndOperatorText"] ?? AndOperatorText;
OrOperatorText = L["RadzenDataFilter.OrOperatorText"] ?? OrOperatorText;
ApplyFilterText = L["RadzenDataFilter.ApplyFilterText"] ?? ApplyFilterText;
ClearFilterText = L["RadzenDataFilter.ClearFilterText"] ?? ClearFilterText;
AddFilterText = L["RadzenDataFilter.AddFilterText"] ?? AddFilterText;
RemoveFilterText = L["RadzenDataFilter.RemoveFilterText"] ?? RemoveFilterText;
AddFilterGroupText = L["RadzenDataFilter.AddFilterGroupText"] ?? AddFilterGroupText;
EqualsText = L["RadzenDataFilter.EqualsText"] ?? EqualsText;
NotEqualsText = L["RadzenDataFilter.NotEqualsText"] ?? NotEqualsText;
LessThanText = L["RadzenDataFilter.LessThanText"] ?? LessThanText;
LessThanOrEqualsText = L["RadzenDataFilter.LessThanOrEqualsText"] ?? LessThanOrEqualsText;
GreaterThanText = L["RadzenDataFilter.GreaterThanText"] ?? GreaterThanText;
GreaterThanOrEqualsText = L["RadzenDataFilter.GreaterThanOrEqualsText"] ?? GreaterThanOrEqualsText;
EndsWithText = L["RadzenDataFilter.EndsWithText"] ?? EndsWithText;
ContainsText = L["RadzenDataFilter.ContainsText"] ?? ContainsText;
DoesNotContainText = L["RadzenDataFilter.DoesNotContainText"] ?? DoesNotContainText;
StartsWithText = L["RadzenDataFilter.StartsWithText"] ?? StartsWithText;
IsNotNullText = L["RadzenDataFilter.IsNotNullText"] ?? IsNotNullText;
IsNullText = L["RadzenDataFilter.IsNullText"] ?? IsNullText;
IsEmptyText = L["RadzenDataFilter.IsEmptyText"] ?? IsEmptyText;
IsNotEmptyText = L["RadzenDataFilter.IsNotEmptyText"] ?? IsNotEmptyText;
base.OnInitialized();
}
}
- Registering component overrides
{
public static IServiceCollection AddRadzenLocalization(this IServiceCollection services)
{
var componentActivator = new OverridableComponentActivator();
componentActivator.RegisterOverride(typeof(PagedDataBoundComponent<>), typeof(PagedDataBoundComponentLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenColorPicker), typeof(RadzenColorPickerLocalized));
componentActivator.RegisterOverride(typeof(RadzenDataFilter<>), typeof(RadzenDataFilterLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenDataGrid<>), typeof(RadzenDataGridLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenDataList<>), typeof(RadzenDataListLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenDropDown<>), typeof(RadzenDropDownLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenDropDownDataGrid<>), typeof(RadzenDropDownDataGridLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenFileInput<>), typeof(RadzenFileInputLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenGrid<>), typeof(RadzenGridLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenLogin), typeof(RadzenLoginLocalized));
componentActivator.RegisterOverride(typeof(RadzenPager), typeof(RadzenPagerLocalized));
componentActivator.RegisterOverride(typeof(RadzenScheduler<>), typeof(RadzenSchedulerLocalized<>));
componentActivator.RegisterOverride(typeof(RadzenSteps), typeof(RadzenStepsLocalized));
componentActivator.RegisterOverride(typeof(RadzenUpload), typeof(RadzenUploadLocalized));
services.AddSingleton<RadzenLocalizer>();
services.AddSingleton<IComponentActivator>(componentActivator);
return services;
}
- register activator in Program.cs
builder.Services.AddRadzenLocalization();
var app = builder.Build();
OverridableComponentActivator
provides a way to dynamically replace or override component types during runtime, allowing for flexibility and customization in component instantiation. In this case by replacing original component with localized.
Localization
finds localizable strings, replaces them with localizer call and writes key/value pair to resource file.