ScarletKuro / Blazor.WebAssembly.DynamicCulture

Blazor.WebAssembly.DynamicCulture.Loader is a powerful tool that simplifies the process of loading multiple localization satellite assemblies simultaneously during startup in Blazor WebAssembly applications. With this tool, there's no need to manually refresh the page in order to access the new resource assembly.
MIT License
8 stars 0 forks source link

A question about this project #1

Closed IngoManthey closed 2 years ago

IngoManthey commented 2 years ago

I have 4 language resources: new CultureInfo("en") new CultureInfo("pt") new CultureInfo("de") new CultureInfo("cs") I use the following cultures: new CultureInfo("en-US"), new CultureInfo("en-ZA"), new CultureInfo("en-CA"), new CultureInfo("en-NZ"), new CultureInfo("pt-BR"), new CultureInfo("pt-PT"), new CultureInfo("de-DE"), new CultureInfo("de-CH"), new CultureInfo("de-AT"), new CultureInfo("cs-CZ"), Do I now have to specify all cultures in LoadSatelliteCultureAssembliesCultureAsync or is it sufficient that the languages are set?

ScarletKuro commented 2 years ago

You need to specify all cultures, i.e.

new CultureInfo("en-US"),
new CultureInfo("en-ZA"),
new CultureInfo("en-CA"),
new CultureInfo("en-NZ"),
new CultureInfo("pt-BR"),
new CultureInfo("pt-PT"),
new CultureInfo("de-DE"),
new CultureInfo("de-CH"),
new CultureInfo("de-AT"),
new CultureInfo("cs-CZ"),

Also, to make things clear. If you use only the Blazor.WebAssembly.DynamicCulture.Loader then you have to specify it here: await host.LoadSatelliteCultureAssembliesCultureAsync(cultureList); if you using it together with Blazor.WebAssembly.DynamicCulture then its enough to define it here

builder.Services.AddLocalizationDynamic(options =>
{
  options.SetDefaultCulture("en-US"); 
  options.AddSupportedCultures(list of your cultures);
  options.AddSupportedUICultures(list of your ui cultures, usually the same as cultures);
});

Currently making sample with comments to make some things more clear.

ScarletKuro commented 2 years ago

Pushed a sample with Blazor.WebAssembly.DynamicCulture gif

Not sure if there is need for a sample with just the Blazor.WebAssembly.DynamicCulture.Loader since it simply loads all the language resources, the rest is up to the user on how to handle this resources, how to switch language, how to call StateHasChanged() for page etc.

IngoManthey commented 2 years ago

Thank you for this great project.