elsa-workflows / elsa-workflows/elsa-studio
app.UseElsaLocalization() block app loading
- Dominant language
- C#
- Stars
- 301
- Forks
- 181
- Avg merge
- 17h 12m
- Merged PRs (30d)
- 42
Description
## Issue
When I add Localization to the WebAssembly app, the `async app.UseElsaLocalization()` method block the loading of the app.
In the browser console, I get this error :
```
Blazor detected a change in the application's culture that is not supported with the current project configuration. To change culture dynamically during startup, set true in the application's project file.
```
By setting the `BlazorWebAssemblyLoadAllGlobalizationData` parameter in the solution to true, the app loads.
## Question
- Is it normal and clean to set this parameter ?
- Why this parameter must be set to true ?
- Shouldn't it be added in the Localization documentation that this parameter must be set ?
## To get to the same state as me
1. Install Elsa WebAssembly from this tutorial :
https://docs.elsaworkflows.io/application-types/elsa-studio
--> It should work well.
2. Now, add localization to the app following this tutorial :
https://docs.elsaworkflows.io/studio/localization.
3. Use the `ResxLocalizationProvider` from Elsa.Studio.Translations
Your Program.cs should look like this :
```c#
using Elsa.Studio.Contracts;
using Elsa.Studio.Core.BlazorWasm.Extensions;
using Elsa.Studio.Dashboard.Extensions;
using Elsa.Studio.Extensions;
using Elsa.Studio.Localization.BlazorWasm.Extensions;
using Elsa.Studio.Localization.Models;
using Elsa.Studio.Localization.Options;
using Elsa.Studio.Login.BlazorWasm.Extensions;
using Elsa.Studio.Login.Extensions;
using Elsa.Studio.Login.HttpMessageHandlers;
using Elsa.Studio.Models;
using Elsa.Studio.Shell;
using Elsa.Studio.Shell.Extensions;
using Elsa.Studio.Translations;
using Elsa.Studio.Workflows.Designer.Extensions;
using Elsa.Studio.Workflows.Extensions;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
// Build the host.
var builder = WebAssemblyHostBuilder.CreateDefault(args);
var configuration = builder.Configuration;
// Register root components.
builder.RootComponents.Add("#app");
builder.RootComponents.Add("head::after");
builder.RootComponents.RegisterCustomElsaStudioElements();
// Register shell services and modules.
builder.Services.AddCore();
builder.Services.AddShell();
builder.Services.AddRemoteBackend(new BackendApiConfig
{
ConfigureBackendOptions = backendOptions => configuration.GetSection("Backend").Bind(backendOptions),
ConfigureHttpClientBuilder = elsaClient => elsaClient.AuthenticationHandler = typeof(AuthenticatingApiHttpMessageHandler)
}
);
// Setup localization
builder.Services.AddLocalizationModule(new LocalizationConfig
{
ConfigureLocalizationOptions = options =>
{
configuration.GetSection(LocalizationOptions.LocalizationSection).Bind(options);
options.SupportedCultures = new[] { options?.DefaultCulture ?? new LocalizationOptions().DefaultCulture }
.Concat(options?.SupportedCultures.Where(culture => culture != options?.DefaultCulture) ?? []).ToArray();
}
});
builder.Services.AddTranslations();
builder.Services
.AddLoginModule()
.UseElsaIdentity();
builder.Services.AddDashboardModule();
builder.Services.AddWorkflowsModule();
// Build the application.
var app = builder.Build();
// Use the localization Middleware
await app.UseElsaLocalization();
// Run each startup task.
var startupTaskRunner = app.Services.GetRequiredService();
await startupTaskRunner.RunStartupTasksAsync();
// Run the application.
await app.RunAsync();
```
Contributor guide
Assessment
This issue has not been assessed yet.