-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Describe the bug
I am trying to localize text in a Blazor WASM app. The process which loads the appropriate satellite assemblies seems to be very picky. In a simple "Hello World" blazor WASM app, it works as it should. If I implement the same steps in a more complex WASM app, switching cultures works (checked by logging), but not loading the assemblies.
To Reproduce
I tried to reproduce the issue in a simple repository: https://repos.tsommer.org/thorsten/BugWASMI18N. Right now, I'm failed to do so. The simple WASM app works as intended. Implementing the same steps in a complex real-world app, the situation arises that the satellite assemblies are not loaded. I will keep trying to reproduce the issue in the simple repository.
What I did (in the simple & complex app):
- Add the package
<PackageReference Include="Microsoft.Extensions.Localization" Version="6.0.0-rc.1.21452.15" />
- Add the
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
option to the project file - Add resource files to the project with localized text
- Add a piece of JS code to the
index.html
to store & load the user's culture, e.g.window.localStorage['AppLanguage']
- Add the localization service
builder.Services.AddLocalization()
- Load the user's culture
var appLanguage = await jsInterop.InvokeAsync<string>("appCulture.get");
- Enable the culture e.g.
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
etc. - Finally, localize text e.g.
@Localize["Name"]
etc.
The result in the simple app (https://repos.tsommer.org/thorsten/BugWASMI18N): It works as intended. The result in the complex app: the culture gets changed. Since the corresponding satellite assembly gets not loaded, @Localize["KEY"]
returns the none-localized text. This means, though, that the configuration & detection of the resource works.
Call for help
So that I can further narrow down the troubleshooting: Can you tell me the formal criteria that Blazor uses to decide that a satellite assembly needs to be loaded? Only blazor.boot.json
can serve as a basis for decision, in my opinion. Here all satellites are listed correctly. Does a name matching take place here? What are the rules if so? At which point in the code should the satellite assembly be loaded? Should it happens after setting CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
?
I am appreciative of any support and advice 🙂
Further technical details
.NET SDK (reflecting any global.json):
Version: 6.0.100-rc.1.21458.32
Commit: d7c22323c4
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.6
OS Platform: Darwin
RID: osx.11.0-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.100-rc.1.21458.32/
Host (useful for support):
Version: 6.0.0-rc.1.21451.13
Commit: d7619cd4b1
.NET SDKs installed:
6.0.100-rc.1.21458.32 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.0-rc.1.21452.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0-rc.1.21451.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]