Blazor Localization in .NET 8 & Blazor Server

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 64

  • @ClaudioBernasconi
    @ClaudioBernasconi  10 месяцев назад

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

    • @НесторГрин
      @НесторГрин 9 месяцев назад

      Thank you for your video, i am getting my resources with keys, but in net 8 blazor server, their values have null

  • @10Totti
    @10Totti 9 месяцев назад +5

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

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад +1

      Thanks, I will make sure you can see all the important bits. 🙂

  • @mattpavey
    @mattpavey 5 месяцев назад +1

    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!

    • @ClaudioBernasconi
      @ClaudioBernasconi  5 месяцев назад +1

      Thanks for your great and detailed feedback, Matt! 🙏

  • @anrizakurniaaziiz1737
    @anrizakurniaaziiz1737 3 месяца назад

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

    • @ClaudioBernasconi
      @ClaudioBernasconi  3 месяца назад

      @@anrizakurniaaziiz1737 that's amazing! Well done and thanks for commenting. 😉

  • @MrXHDTV
    @MrXHDTV 9 месяцев назад +1

    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.

  • @PaulVanBladel
    @PaulVanBladel 10 месяцев назад +1

    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 ?

    • @allannielsen4752
      @allannielsen4752 10 месяцев назад +1

      Thanks for this video, i agree, very informative. I would also like to see WASM, or even better, one that explains how to do it using the Auto mode where both Server and WASM are used.

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад +1

      I will work on it. Stay tuned. 😎

    • @altareb10
      @altareb10 10 месяцев назад

      we are waiting ​@@ClaudioBernasconi

    • @PaulVanBladel
      @PaulVanBladel 9 месяцев назад

      @@ClaudioBernasconi Do you run in some specific problem?

    • @trafalgarlaw5336
      @trafalgarlaw5336 Месяц назад

      @@allannielsen4752 Hi, did you find a video or solution for the auto mode?

  • @ifullerlove
    @ifullerlove 9 месяцев назад

    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!

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад +1

      Thanks for your great question. It's hard to reply without having your code. You might want to create an example repo and post it on StackOverflow for more detailed help. What I can say is that when you detect the language in the middleware, you should (in my opinion) be able to render the page with the correct language on the first render. The reason is that each HTTP request goes through the whole middleware pipeline. I hope this helps somewhat.

  • @joehernandez3231
    @joehernandez3231 10 месяцев назад

    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?

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад +1

      It should be installed with Visual Studio. I don't know which workload. I will edit the comment when I find out.

  • @stevendfowler
    @stevendfowler 7 месяцев назад

    Great video, thank you. Any chance of an InteractiveWebAssembly version? I figured out that I need to add "builder.Service.AddLocalization" 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?

    • @ClaudioBernasconi
      @ClaudioBernasconi  7 месяцев назад

      Unfortunately, I haven't had the chance to implement a WebAssembly solution yet. I will keep it on my list and hope to release a video in the future. Right now, I cannot give you any pointers to a WebAssembly solution other than the "Localized Application in Blazor WebAssembly" article on DotNetCurry.

  • @md.shakirhossain
    @md.shakirhossain 5 месяцев назад

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

  • @MrXHDTV
    @MrXHDTV 9 месяцев назад +1

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

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад

      Great question. There are other solutions but this one works, is a simple implementation, and user's usually don't change the language often so a reload is acceptable in most of the cases. If you have other requirements, feel free to choose a different implementation that suits your needs.

  • @lucascida8698
    @lucascida8698 Месяц назад

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

  • @GuillermoMarcel
    @GuillermoMarcel 9 месяцев назад

    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 ?

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад

      The code in your CultureSelector component should call your controller method (Web API) whenever you change the value of the dropdown. It seems like that is not correctly implemented in your case. You can debug both ends and see where the issue is. The link to my source code is in the video description as a reference.

    • @GuillermoMarcel
      @GuillermoMarcel 9 месяцев назад +2

      @@ClaudioBernasconi Yes, but it looks there an option that if missing wont call the setter when interact with the site.
      In the App.razor file I had: and
      And what fix everything was adding the Interactive Server option like this:

    • @KamaruAshamae
      @KamaruAshamae 4 месяца назад

      @@GuillermoMarcel Tried this rendor mode method and its still not working for me. CultureSelector is just not called. Not sure what else to do

  • @KamaruAshamae
    @KamaruAshamae 4 месяца назад

    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?

    • @ClaudioBernasconi
      @ClaudioBernasconi  4 месяца назад

      I am sorry it doesn't work for you. It's really difficult to spot an error from your description without having access to your code. Maybe you can post your code on GitHub and somehow provide access? Feel free to put it online and tag me on Twitter, or ask on StackOverflow.

    • @KamaruAshamae
      @KamaruAshamae 4 месяца назад

      @@ClaudioBernasconi I got it figured. There was an issue in the controller and the http requests :) Thank you for responding!

  • @TheQvisionsa
    @TheQvisionsa 10 месяцев назад

    Nice example! Did you tried to not have "en-US" as first language in .SetDefaultCulture(supportedCultures[0]) ? I tried it but it returns "en-US"

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад

      As far as I understand we need to configure the default culture using this method. If we do not set it, it will take the system default which is a problem when you run it locally and have a different culture setting on your server/cloud.

    • @TheQvisionsa
      @TheQvisionsa 10 месяцев назад

      Yes! we configure the default culture using .SetDefaultCulture(supportedCultures[0]). If I set it to "el-GR" for Greek, it's not working. It will return "en-US"@@ClaudioBernasconi

  • @amrswalha
    @amrswalha 4 месяца назад

    Thank you for this great tutorial

  •  10 месяцев назад

    Thanks for your time!
    How to support rtl

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад

      Thanks for your comment! I'm sorry, I'm not an expert in that area. I saw there are CSS scripts that transform a whole website but I'm not sure if that is what you need. 🤔

  • @mohammadmuwafi3623
    @mohammadmuwafi3623 8 месяцев назад

    Thank you so much

  • @AllKnowing114
    @AllKnowing114 9 месяцев назад

    Any tips how to do the same without the controller?

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад

      Well, with Blazor Server you have ASP.NET Core on the backend anyways, so why don't you want to utilize it? There might be client-only solutions but this approach is simple and you'll have the localization client and server-side. I'm curious to learn about your use case.

  • @cissemy
    @cissemy 10 месяцев назад

    Thanks

  • @shabanelmogy7912
    @shabanelmogy7912 10 месяцев назад

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

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад

      I understand your use case but I don't know how to do that. I'm not familiar with the topic in general, I'm sorry.

  • @TravelingGonad
    @TravelingGonad 6 месяцев назад +1

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

    • @lintendo100
      @lintendo100 2 месяца назад

      Not with Blazor Server, it seems :(

  • @margosdesarian
    @margosdesarian 9 месяцев назад

    My VS 2022 (17.8.0) does not create the cs files no matter what i do - any suggestions? I changed the way i create the Resource files as per this video ruclips.net/video/kYQxB7YTPLE/видео.html and got them to work using the IStringLocalizer.
    But changing the select option in the CultureSelector does nothing. I changed the logic to get it working. Thanks for the video

    • @ClaudioBernasconi
      @ClaudioBernasconi  9 месяцев назад

      I understand your issue. I don't know if that is a known issue. I tried reopening the solution, restarting the PC, and creating a new project and trying again and again in such cases. I don't know how to fix it if it doesn't work with all those tries, I'm sorry.

  • @pradm777
    @pradm777 10 месяцев назад

    Please make video for Arabic

    • @ClaudioBernasconi
      @ClaudioBernasconi  10 месяцев назад +1

      Thanks for your interest in my videos. I know a few languages, but Arabic isn't one of them, I'm sorry.

  • @tofansahra-kb7rv
    @tofansahra-kb7rv 8 месяцев назад

    How to deal with multiple resource files for localization?
    ResourceFileA1.resx
    ResourceFileA2.resx
    ResourceFileA1.de-DE.resx
    ResourceFileA2.de-DE.resx

    • @ClaudioBernasconi
      @ClaudioBernasconi  8 месяцев назад

      When you use the IStringLocalizer type, you can set the type parameter to the specific resource file. In your case, IStringLocalizer and IStringLocalizer should work.

    • @tofansahra-kb7rv
      @tofansahra-kb7rv 8 месяцев назад

      thank you

  • @Januzzz_2021
    @Januzzz_2021 8 месяцев назад

    Thanks

  • @shabanelmogy7912
    @shabanelmogy7912 10 месяцев назад

    Thanks