aspnetcore: Blazor Server Side Localization not working
Trying to stand up a super simple example of Blazor Server Side with Localization/Translation support.
I posted the spike here: https://github.com/aherrick/BlazorServerSideLocalization
It appears in my Index.razor view @inject IViewLocalizer L is always null. I have a Resources folder with a Pages.Index.en.resx
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 20 (3 by maintainers)
@aherrick not really. I’ll leave this as a question for community members to help you out with.
Localization is critical for us. I really hope MS comes up with official guidance on this soon. I also hope that the mechanism will be server/client side agnostic as well as not impact unit testing.
I’d like to expand on @SeppPenner post, as I found the following to work based on the browser’s preferred language.
Startup.cs
Pages/Index.razor
Resource files
/Resources …/Pages …Index.fr.resx …Index.resx
OK - it would be nice if there was some documentation or examples on how to do Localization with Blazor.
What about
IStringLocalizer<>? I already asked a similar question here: https://github.com/aspnet/AspNetCore/issues/12277.Don’t forget to add
to your
ConfigureServicesmethod in theStartupfile.Translationshere is a folder in your project on root level containing all the*.resxfiles used for your view localization.@aherrick
I whipped together something very crude last week as I ran into the same problem and I needed a quick fix for it. I ended up with something along the lines of the following. Maybe it can send you on the right track for your needs.
See this gist: https://gist.github.com/christiansparre/5576907ad391b972581714f7564674b7