aspnetcore: Blazor localization not working

Describe the bug

I am trying to localize a custom component (the component itself, not the page it is displayed in), but the .resx files are not being used at all.

To Reproduce

Steps to reproduce the behavior:

  1. Clone the repo at: https://github.com/Stamo-Gochev/blazor-test-localization
  2. Try to change the culture using the dropdown, e.g. from “English” to “Francais”.

Expected behavior

The LocalizedComponent text is updated according to the culture of the app.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

The LocalizedComponent uses IStringLocalizer. A select element is added (similar to the docs) in order to change the culture.

Changing the culture to fr using the dropdown changes the format of the DateTime, but the localized value remains the same. Actually, it displays the key - key1, so I suppose that the localization is not triggered at all. Resources are registered in Startup.cs. Can you shed some light why this isn’t working?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

I’ll try your sample out and see what’s going on.

Using resource files will create additional satellite assemblies which aren’t downloaded by blazor. But you can embedd them in the main assembly. See https://github.com/aspnet/AspNetCore/issues/15270