Blazor Localization in .NET 8 & Blazor Server

preview_player
Показать описание
We will learn how to localize a Blazor application in .NET 8. The same code is also applicable to .NET 7 Blazor Server. We use regular .NET NuGet packages and create regular resource files.

For Blazor WebAssembly, you need to tweak the code, it won't work as shown in this video.

00:00 What We Build in This Video
00:45 Creating the Blazor Web App in Visual Studio
01:39 Install & Setup the Required Localization Nuget Package
02:54 Create the Translation Files
06:03 Apply Translated Texts in Blazor Components
08:07 The CultureSelector Component
10:15 Add a Controller to Handle Culture Changes
12:32 Testing the Application
13:06 Conclusion

📌 Source Code

🔥 C#/.NET Bootcamp: The Fundamentals & more (Code FRIENDS10 for 10% OFF)*

📌 .NET Developer Roadmap

📌 YouTube Playlists:

✅ SUBSCRIBE FOR MORE VIDEOS

🚀 CONNECT & SUPPORT

* Affiliate Link: I earn a small commission at no additional cost
Рекомендации по теме
Комментарии
Автор

The custom tool ResXFileCodeGenerator is installed as part of Visual Studio. I couldn't figure out what workload is required, though.

ClaudioBernasconi
Автор

Great Tutorial thanks!
A tip: make the webcam smaller, sometimes it doesn't show the code.

Totti
Автор

Nonostante ho messo ResXFileCodeGenerator, non mi crea la classe .cs inerente al file resx

lucascida
Автор

Great video. The thing I kept having trouble with was the Resouce.resx file was not generating the designer file, even when it was an embedded resource and even if I tried to use the ResXFileCodeGenerator approach; however, turns out for me it was a matter of opening the Resource.resx file (in editor mode) and then changing the "Access Modifier" from "No code generation" to "Public" (or Internal depending on your needs). Once I did that the rest all worked as expected. Lastly, for what it's worth, I thought the idea to redirect and force a page reload was a good one for my use-case. I suppose others may find that to be unnecessary, but it worked well for me. Thanks for the video!

mattpavey
Автор

Why do you reload the page for a simple language change ?

MrXHDTV
Автор

Thanks for the video! I have successfully implemented in .NET 8 Blazor server using Database as the source of translations. Cheers!

anrizakurniaaziiz
Автор

I'm having quite a bit of trouble with the CultureSelector. When I use the dropdown to change the language, it can't find it. I tried the interactive server render mode method and it still errors out. Any ideas?

KamaruAshamae
Автор

I also forgot to mention about _Layout.cshtml, the html document has a default lang property that is set to en. You forgot to change that.

MrXHDTV
Автор

Great video, thank you. Any chance of an InteractiveWebAssembly version? I figured out that I need to add to both program.cs files, with it only in the main project it reverted to showing just the keys after about a second. I have a similar problem still though, if I use the selector it will change the language but again after a second it then reverts back to the initial language. The cultureselector, resources and page are in the client project, the controller is in the main project. Any suggestions? I guess I have some items in the wrong project?

stevendfowler
Автор

Nice example! Did you tried to not have "en-US" as first language in ? I tried it but it returns "en-US"

TheQvisionsa
Автор

Hi! Hello! thanks for this video, It's awesome. I'm having a big issue. When I change the selected language from the dropdown of the CultureSelector component, the Culture setter is never called, It's only called when the site is being first loaded, but never when I manually change from the drop down. Do you know what may be happening here ?

GuillermoMarcel
Автор

Any tips how to do the same without the controller?

AllKnowing
Автор

Hi Claudio, many thanks for this - a really clearly explained methodology, really excellent. One question which you may be able to help me with: I am using your approach on a multi-lingingual ecommerce site, and I want to change the language automatically to the language of the location of the user, before the page is first rendered - this is really important as I need the SEs to index the page in the new language. I can detect the user location ok, but at the moment I can only do the change of language after the first render. Do you have any tips about how I could do this? Many thanks!

ifullerlove
Автор

nice. Very well explained.
How would it work for blazor webassembly, so preferably without the controller? Would it be possible for you to extend the github repo with a pure webassembly sample ?

PaulVanBladel
Автор

Helpful video, thanks for making it.
Is the PublicResxFileCodeGenerator a Nuget package we need to add, or some external tool we need to install locally?

joehernandez
Автор

Thanks for your time!
How to support rtl

Автор

Im from egypt speak arabic and i want to change direction of website right to left

shabanelmogy
Автор

Thank you so much @ClaudioBernasconi for your nice, easy and helpful video

md.shakirhossain
Автор

There must be a better way than reloading the whole Blazor site just to change the language!

TravelingGonad
Автор

But changing the select option in the CultureSelector does nothing. I changed the logic to get it working. Thanks for the video

margosdesarian