Localization in Blazor Server - How To Change Languages and Cultures

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ธ.ค. 2024

ความคิดเห็น • 201

  • @randomdevfromgermany1951
    @randomdevfromgermany1951 4 ปีที่แล้ว +1

    I literally wasted an hour searching for two minor mistakes with my localization yesterday, and then you uploaded this video. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      Glad I could help! Timing is everything! LOL

  • @emersonstori
    @emersonstori ปีที่แล้ว

    Congratulations, this is the best video on this subject on the entire internet.

  • @bujin1977
    @bujin1977 4 ปีที่แล้ว +2

    I have no idea why I just spent the last hour and twenty minutes watching a video on something I already know how to do. But I don't regret it.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      I'm glad it was enjoyable.

  • @TechNobo
    @TechNobo 3 ปีที่แล้ว +2

    This ONLY works if the "Assembly Name" is the same as the "Root Namespace". I struggled for HOURS to figure this out.
    I NEED them to be different (One has "-"s, the other has "_"s).
    How do I get it to work with these different? I can't figure it out and I've spent numerous hours on this. It's a .NET 5 Blazor project.

  • @RalfsBalodis
    @RalfsBalodis 3 ปีที่แล้ว +1

    0:00 - Intro
    1:36 - Creating Blazor Server App
    3:05 - Localization in Blazor explained
    9:28 - NuGet reference
    10:00 - Project configuration: startup and appsettings
    28:24 - Adding MVC controller: Cookies and LocaRedirect
    35:10 - Adding Razor Component: code behind culture change
    46:06 - Adding Razor Component: building dropdown menu
    55:07 - Cookie information
    58:04 - Resource files: App.resx
    1:15:22 - Summary and concluding remarks
    Sveiki Pasaule

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      Thanks! Are you saying 'Sveiki Pasaule' contributed this?

    • @RalfsBalodis
      @RalfsBalodis 3 ปีที่แล้ว

      @@IAmTimCorey I'm saying "Hello World" :)

    • @RalfsBalodis
      @RalfsBalodis 3 ปีที่แล้ว

      @@IAmTimCorey Sorry for confusion

  • @Hazuuur
    @Hazuuur 3 ปีที่แล้ว

    Thanks Tim, you are always here when I need help :D

  • @dyakobaram
    @dyakobaram 4 ปีที่แล้ว +5

    I was talking about my friend about something like this a few days ago I am glad you made a video about it. hope you cover about identity soon or authentication and authorization in general :)

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +7

      That is high on my priority list.

    • @stievenhultermans4559
      @stievenhultermans4559 3 ปีที่แล้ว

      @@IAmTimCorey I'm very much interested in a tutorial where Identity Server is used as an API and not directly included in the blazor ui as you see in most examples or tutorials.
      In my setup my UI talks to my API to load data. So only my API talks to the dbcontext (seperate project). But to include Identity Server in my UI I had to add a reference to the dbcontext directly and i don't like it that way. It should also pass via the API.

  • @DoronAviadEnduroKTM
    @DoronAviadEnduroKTM 3 ปีที่แล้ว +3

    how can we add support for RTL languages (Arabic, Hebrew) ? in this case we also have to flip the screen from right to left

  • @chilledwine4739
    @chilledwine4739 2 ปีที่แล้ว

    Great tutorial, implemented it while watching almost without stopping! Excellent explained... Keep going!

  • @MarcR1v
    @MarcR1v 2 ปีที่แล้ว +2

    Great video as usual Tim. I understood what you were teaching. My question is more fundamental. Why does the click event for the setting need to be handled with a controller. Why can it not be handled by the click event of the drop down list directly. I use controllers for build REST services, but for this example, I do not understand why it is required. Thx.

  • @c7e7c7g7
    @c7e7c7g7 3 ปีที่แล้ว +2

    HELP!!!! i have a question: Can i do a Localization to a C# class that is used as a Model and has Data Annotations?? cause i need to translate those data Annotations but not sure how to do it. P.S. GREATE VIDEO.. LOVED IT

  • @troymitchel4790
    @troymitchel4790 4 ปีที่แล้ว +1

    Hey, just stopped by to give you a thumbs up for all your contributions to the .net world.

  • @stievenhultermans4559
    @stievenhultermans4559 3 ปีที่แล้ว

    Super tutorial. Made me be able to change the language on my Blazor site!

  • @مرتضی_المطیري-م7ف
    @مرتضی_المطیري-م7ف ปีที่แล้ว

    tank you very much for your explanation but I have question what we should name resx file or where should we store it if we want to access with that file to class models or pages in another project???

  • @KrisHahn-p5u
    @KrisHahn-p5u 10 หลายเดือนก่อน

    I have a WebAssembly Blazor project and I would like to have subfolders under my Resources folder and then put resource files under each of the sub folders but I cannot figure out how to access the resource files using IStringLocalizer
    Ideas?

  • @shawnmofid7131
    @shawnmofid7131 4 ปีที่แล้ว

    I am so glad I saw this. I really like the supped up layout of blazer pages.

  • @randomdevfromgermany1951
    @randomdevfromgermany1951 3 ปีที่แล้ว

    51:45 Perhaps you don't remember anymore after almost a year, but why was it not ideal to switch the language with the onchanged event? Was there any bug or uncontrolled behaviour because of that?

  • @TravelingGonad
    @TravelingGonad 10 หลายเดือนก่อน

    Is there a pure Blazor method to set the language? It's inefficient to call an MVC controller and reload the entire app just to switch the language. It also makes it difficult to detect and SET the language when they first come to the site, so what are we expected to do, load the app twice??

  • @99MrX99
    @99MrX99 4 ปีที่แล้ว +5

    Great video! Have you heard of the Visual Studio extension ResX Manager? That makes handling the translations in the resx files much easier.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +2

      I haven't. I'll check it out. Thanks!

  • @abdouldia1605
    @abdouldia1605 3 ปีที่แล้ว

    Wonderfull video. Solved my problem at work. You are great Tim. Keep it up.

  • @androidsavior
    @androidsavior 2 หลายเดือนก่อน

    does this work with blazor wasm ?

  • @natalyalmassry6775
    @natalyalmassry6775 3 ปีที่แล้ว

    Thank you for the video and detailed explanation! Your video helped me to finally figure out localization in blazor

  • @norbertcsibi7720
    @norbertcsibi7720 3 ปีที่แล้ว

    When I add the @bind to the select tag, it shows an error which I cannot figure out what exactly it is :/ I`m binding exactly like you in [47:48].
    The error is the following:
    Cannot resolve method Create(ChooseLanguage, string) candidates are:
    Microsoft.AspNet.Core.Components.EventCallback Create(Object, EventCallback)
    Any ideas why is this been thrown? :)

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      Did you name your method "Create"? It sounds like there are two "Create" methods now and C# doesn't know which one to pick. If you did, rename your method to be "CreateItem" or something similar in order to remove the conflict.

  • @mirragemelkyr
    @mirragemelkyr 4 ปีที่แล้ว +1

    Great Video, thanks for covering this topic, for some reason this didn't work the same on firefox, but chrome sure works.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Good to hear and thanks for sharing the info.

    • @tamaslittmann2872
      @tamaslittmann2872 3 ปีที่แล้ว

      I can confirm this, try to find the problems for hours, without any success :( Chrome MS Edge works fine.)
      Also, there is no cookies in Firefox for this project (others, like login, etc. works perfect on firefox and can create cookies).

    • @klemen6961
      @klemen6961 ปีที่แล้ว

      Were you able to find the answer to this problem?

  • @casastreetview9856
    @casastreetview9856 ปีที่แล้ว

    Hi Tim, Great video thank you

  • @Top3reee
    @Top3reee 3 ปีที่แล้ว

    Thanks for this great one Tim, fan from India

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      Glad you enjoyed it!

  • @ТетянаСтолярчук-э8ф
    @ТетянаСтолярчук-э8ф 3 ปีที่แล้ว

    Thank you very much for your work, I will say that you are a great teacher and your actions inspire good work.

  • @brirembillel1959
    @brirembillel1959 3 ปีที่แล้ว +1

    thank you very much , Great video, but how we can use localization in Razor class Library!???

  • @nielserikmeier9721
    @nielserikmeier9721 3 ปีที่แล้ว

    I have to use a lot of labels in my project, are there anyway to use multiple resources files like one for Errors, one for index page, one for ...? Just a hint for the right direction where to look

  • @Folkert1975
    @Folkert1975 3 ปีที่แล้ว

    Thanks for the tutorial. Helpful.
    A question: how can i pickup and apply a CultureCode from some storage in Blazor Server Side when starting the application?
    E.g.: localstorage and OnAfterRender.
    I tried to do this, but it is continuously rerendering my index page (even when putting the logic within the "firstrender" check).

  • @jaywalks9918
    @jaywalks9918 3 ปีที่แล้ว

    Where is the Time zone for the client/server set? Or maybe dates set on the client are always in UTC?

  • @kctripathy
    @kctripathy 3 ปีที่แล้ว

    Thank you so much for such a wonderful video. Kudous to your efforts

  • @hfpsc27
    @hfpsc27 3 ปีที่แล้ว

    Thank You. This video shows how to translate the UI, right? Imagine I have an APP like Tim Corey Retail Manager and I wan't to translate the contents of the data base, like a product name. Wich is the best practice? Should I save all the translations in the database, in culture table? This means that for each table, I need a Culture table (Products and Products culture, etc.)?

  • @bigtech59
    @bigtech59 ปีที่แล้ว

    you introduced well .
    thanks alot from iran ❤

  • @Dorsalwarrior0
    @Dorsalwarrior0 3 ปีที่แล้ว

    Really helpful, works like a dream thank you sir.

  • @aog.tr.6828
    @aog.tr.6828 2 ปีที่แล้ว

    Great video! Thank you very much.

  • @littledreamertorytime
    @littledreamertorytime 3 ปีที่แล้ว

    Hi Tim, trying to using this in a razor componment @inject IStringLocalizer Localizer, but I go this this error => Found a malformed 'App' tag helper. Tag helpers must have a start and end tag or be self closing.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      The syntax is "@inject IStringLocalizer Localizer"

    • @littledreamertorytime
      @littledreamertorytime 3 ปีที่แล้ว

      @@IAmTimCorey [Inject]
      public IStringLocalizer Localizer { get; set; } , I tried to inject it in a componentbase class file, but I got an error of "The type or namespace name 'App' could not be found" Thank you!

  • @maksy09
    @maksy09 3 ปีที่แล้ว +1

    Great video! For some reason, the navigaton tp the cpntroller doesnt work in firefox. It works fine in Chrome and edge. Anyone got similiar issues?

    • @tonyevers
      @tonyevers ปีที่แล้ว

      I have this issue as well....

  • @marcusmaunula5018
    @marcusmaunula5018 4 ปีที่แล้ว

    Appreciate the Localization clip. This is imho the least made course type for C# :)

    • @marcusmaunula5018
      @marcusmaunula5018 4 ปีที่แล้ว

      Also. What is the difference with Client Blazor then?

    • @Baby4Ghost
      @Baby4Ghost 4 ปีที่แล้ว +1

      ​@@marcusmaunula5018 The main difference is the Startup, in WASM there isnt any by default so you wire it up in the Program.cs. I also use localStorage throu IJSRuntime.
      The way I did it, is using the IJSRuntime to set an localStorage value with a razor component: CultureSelector.razor (same way as in video, from the appsettings.json), and in Program.cs set the CultureInfo.DefaultThreadCurrentCulture and CultureInfo.DefaultThreadCurrentUICulture using IJSRuntime to get the culture from localStorage.
      Thats it. Now you can use the resource files just like in the video. As for the resource keys I recommend using nested static classes with const string properties avoiding magic string.
      I can create an github project to showcase it if you like?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      This GitHub project will show you how to do localization in Blazor WebAssembly (it is the one I used as a sample in my Exploring Blazor WebAssembly course, where we learned how to do localization from it): github.com/SteveSandersonMS/CarChecker

    • @marcusmaunula5018
      @marcusmaunula5018 4 ปีที่แล้ว

      @@Baby4Ghost Thanx, sorry for the the late reply but appreciated nonetheless :).

    • @marcusmaunula5018
      @marcusmaunula5018 4 ปีที่แล้ว

      @@IAmTimCorey Thank you.

  • @CeranPOL
    @CeranPOL ปีที่แล้ว

    So how to change language in all of the components that use localization with single button?

  • @maacpiash
    @maacpiash 4 ปีที่แล้ว +4

    Mr. Corey, First of all, I'm a huge fan of your videos. I would really appreciate it if you could shed some light on how to manage the (global) state of a Blazor app, kind of like how React does via Redux or Context API.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +4

      Noted! Added to the list.

    • @carlosjosejimenezbermudez9255
      @carlosjosejimenezbermudez9255 4 ปีที่แล้ว

      Blazor has a built in tool for sharing state across any hierarchy in the components. You will see that the authentication state in the individual accounts template uses it to share auth state to the entire sample app. Alternatively for a more redux-like experience, there's fluxor.

    • @ltacid
      @ltacid 4 ปีที่แล้ว

      @@IAmTimCorey yes please!

  • @davidjnevin
    @davidjnevin 2 ปีที่แล้ว

    Great stuff! We're branching out into two additional languages. Really useful. 👏👏

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว

      Glad it was helpful!

  • @zulhishamtan4308
    @zulhishamtan4308 4 ปีที่แล้ว

    This is super awesome video.
    Thank you Tim for the precious information sharing.
    .Net is the best of the best ever.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Glad you enjoyed it!

  • @KurtInTampa
    @KurtInTampa 3 ปีที่แล้ว

    Thanks, timely information. If creating a site to be sold to multiple different customers that will want to personalize or update text, would it make more sense to create an admin screen that updates the resource files or to skip the resource files and pull text from a db?

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      I would pull the text from a database for most things.

  • @MarioStaats
    @MarioStaats 4 ปีที่แล้ว

    Great work as always @IAmTimCorey *ThumbUp

  • @salvatoreseverini9734
    @salvatoreseverini9734 4 ปีที่แล้ว

    Hi TIM great video just what I needed.
    I have only one problem is it concerns the localization of component libraries (razor and not). what is the procedure in these cases?

  • @simonlapointeaudet3644
    @simonlapointeaudet3644 3 ปีที่แล้ว

    You do the job that Microsoft should do. Thank you very much.
    You should put your video on Udemy ! Very very good.

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 ปีที่แล้ว +2

      Thanks! Tried the Udemy route. Udemy demands the majority of the price the viewer pays. For example, viewers often pay $10 for a course on sale, and the creator may only get less then a buck of it. Tim simply cannot affort to use Udemy.

  • @mastercompuk
    @mastercompuk 4 ปีที่แล้ว

    His Tim I'm trying to hide message attempting to reconnect to server in blazon server app. I have found few solutions in Internet but it doesn't work. Could you please mention in one of you video how to do it, or what is the best solution for it. Thank you. As always big thank you for great tutorial.

  • @giorgimgebrishvili4251
    @giorgimgebrishvili4251 2 ปีที่แล้ว

    1) I cannot use controllers in blazor SSERVER version. 2) When I write same cookie saving code for culture it does not change the culture...

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว +1

      1) yes you can. 2) probably you missed something small.

    • @giorgimgebrishvili4251
      @giorgimgebrishvili4251 2 ปีที่แล้ว

      @@IAmTimCorey I used middleware in startup an set Thread.CurrentCulture. Otherwise setting culture only once doesnt help...

    • @giorgimgebrishvili4251
      @giorgimgebrishvili4251 2 ปีที่แล้ว

      @@IAmTimCorey Finally I used middleware and each time I set Thread.CurrentCultureUI

  • @klemen6961
    @klemen6961 ปีที่แล้ว

    This code works for chrome/edge but not for firefox/safari. Any idea why?

  • @dyakobaram
    @dyakobaram 4 ปีที่แล้ว +1

    can you make a video about cookies and session? how do they work? when to use them or not? is both the same as PHP?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +2

      Thanks, added to the suggestions list.

    • @ltacid
      @ltacid 4 ปีที่แล้ว

      @@IAmTimCorey yes please, I need it. I am confused when people mention state in Blazor and talk about using things like Redux.

    • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
      @SayWhaaaaaaaaaaaaaaaaaaaaaaat 4 ปีที่แล้ว

      it's just a temporary storage..what to not understand?? cookie is cookie no matter what programming language you use..it's just a data in HTTP header.

  • @jebbaz
    @jebbaz 2 ปีที่แล้ว

    How to change DateTimes in interface, depending on user culture? Very straightforward with WinForms as it's tied to the culture. Every method appears to require JS.

  • @seenals7102
    @seenals7102 4 ปีที่แล้ว

    How should localization be handled for large/ blocks of texts?. For that should we go with string contants for each language?. In that case how to identify the current culture?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      For a large block of text, you would create a text identifier that is shorter and then make sure you have your default value loaded in the main file (app.resx).

  • @AthulRajts
    @AthulRajts 4 ปีที่แล้ว

    Is it possible to use IStringLocalizer in a WPF application ?

  • @Foodies-pv7ih
    @Foodies-pv7ih 4 ปีที่แล้ว

    much needed, thanks

  • @Glupostiify
    @Glupostiify 3 ปีที่แล้ว

    Changing the country is more efficient without buttons.
    --> It would be even nicer with the flags near by

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 ปีที่แล้ว

      Thanks for sharing

    • @trafalgarlaw5336
      @trafalgarlaw5336 3 ปีที่แล้ว

      It is also possible to use a variable get; set;
      ....
      private string _selectedCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
      private string SelectedCulture
      {
      get => _selectedCulture;
      set
      {
      _selectedCulture = value;
      RequestCultureChange();
      }
      }

  • @habibm19
    @habibm19 ปีที่แล้ว

    Hi Tim...please show us how to do this with Blazor SPA...since SPA will have single Http response, how can we update the cookie? . Please inform

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @AhmadRadi
    @AhmadRadi 3 ปีที่แล้ว

    Thanks, Tim! Localization in Blazor is straightforward and easier than WPF. I had to use a workaround in WPF to make it work.
    What if we replace the controller with a service class and inject it into a component? I guess that would work.
    Thank you for all the effort you put in!

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 ปีที่แล้ว

      Thanks for watching and sharing your thoughts!

    • @frogger3d
      @frogger3d 3 ปีที่แล้ว

      Localization in WPF is straightforward since they added x:Static. If you have code generation on for the main resx file and the xml namespace setup you can access localized texts like so: Text="{x:Static text:App.HelloWorld}"

  • @Foizman
    @Foizman 3 ปีที่แล้ว

    Hi Tim,
    found an error.
    This approach only works, cause there is a well-known component called "App.razor" that luckily fits exactly the name of your chosen name "Resources/App.resx".
    If you try to add another resource-file (e.g. Langbasics.resx), inject it (@inject IStringLocalizer LangBasics) and use it (@LangBasics["Test"]), this approach doesn't work, cause there is no class "Langbasics" in the solution.
    If you add a dummy class Langbasics.cs in "/Resources", it will find the class, no more build errors, but the key/value-pair of "Test" isn't shown.
    Any idea?

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      That wasn't luck, that was by design. By default, our application is called App. If you look at _Host.cshtml, you will see "

    • @Foizman
      @Foizman 3 ปีที่แล้ว

      @@IAmTimCorey Hi Tim,
      of cause it wasn't luck, that was ironic!
      The idea was to split things up in several smaller resource-files, not one huge app.resx
      So I tried to add another one, e.g. LangBasic.resx in addition to your app.resx in the same folder.
      No chance to get your code working with that.
      Cheers from Graz/Austria
      Volker

  • @Gray-Wolf-Media
    @Gray-Wolf-Media 4 ปีที่แล้ว

    Talking about TimeDate formats in the US, the DOD uses a different schema as well. They use YYYYMMDD.
    So if you wanted to show the Country Flag also put that in the ForEach as well?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      That date format isn't a culture-specific change but a preference. You would need to account for that in code manually. Not sure what you mean by the ForEach for the country flag.

    • @Gray-Wolf-Media
      @Gray-Wolf-Media 4 ปีที่แล้ว

      On some websites they include a country flag on the menu bar instead of selecting the country. I guess instead of having the text in the appsettings file you would want to point to a country gif instead

    • @KurtInTampa
      @KurtInTampa 3 ปีที่แล้ว

      Yep, after 9 years in the Military I have to think to translate civilian dates :)

  • @norbertcsibi7720
    @norbertcsibi7720 3 ปีที่แล้ว

    If we have a blazor server, and a webassembly under the same solution, on which project should we add the localization?

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      Both.

    • @norbertcsibi7720
      @norbertcsibi7720 3 ปีที่แล้ว

      @@IAmTimCorey Since you mentioned "Both", I`m assuming that the razor component you create here on the server, needs to be done in WebAssembly and the other code which includes StartUp & appsettings needs to be on the server side? Also, are you referencing WebAssembly to server so that you can use the IConfig?

  • @sheikhbashar1
    @sheikhbashar1 4 ปีที่แล้ว

    Thanks So much TimCory

  • @sGeforce
    @sGeforce ปีที่แล้ว

    Hi Tim,
    My local culture is English (India). I get that using CultureInfo.CurrentCulture. However when the app is published to Azure, the Current Culture returned is English (United States). I suppose the CurrentCulture returns the azure server culture instead of the client. I just tried what you have have in the code. (System.Threading.Thread.CurrentThread.CurrentUICulture), this one returns English (United States) in both my dev and on published site. Can you suggest how to get current culture of the client after the app is published. Thanks.

  • @randomdevfromgermany1951
    @randomdevfromgermany1951 4 ปีที่แล้ว

    For some reason I'm not getting the cookie generated in Firefox, but it works under Opera and Edge (which are Chromium-based). What could be the reason for this and how to even debug this kind of issue?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      I'm looking into this. You aren't the only one to report it. Not sure what is going on yet.

    • @klemen6961
      @klemen6961 ปีที่แล้ว

      @@IAmTimCorey I'm using Firefox and I get the same problem. Where you able to resolve this issue?

  • @gupsekobas2209
    @gupsekobas2209 ปีที่แล้ว

    great video indeed!

  • @christianwejwoda7988
    @christianwejwoda7988 3 ปีที่แล้ว

    How would i localize the messages outputed by ?

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      Those messages come from the model, so you would need to do the localization in the model.

  • @chamir4614
    @chamir4614 4 ปีที่แล้ว

    I have a question about another topic. When you are using sqlconnections with aspnet core, its better to use the using keyword for each query or its better to use the same connection along the request? I mean, for example if you have to authenticate the user with a token and then you need to do some query, its better to use the same connection or use a new one?

    • @Baby4Ghost
      @Baby4Ghost 4 ปีที่แล้ว +1

      Use the same connection. No need for a new connection, always try to use the connection you already have because more connections means more resources used.
      An new connection is viable when you use an different connectionstring (maybe admin account), but as long as the connection doesnt need change, reuse the existing connection as much as possible.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      Unless the calls are sequential, I highly recommend creating a new connection each time. The computer has connection pooling which will help you out automatically. Creating one connection and leaving it open is a BAD idea. In doing so, you hold up resources on your SQL Server instead of releasing them for other applications to use. You also risk keeping them open indefinitely if your application crashes. That can bog a server down and eventually crash it.

  • @PowerSkor
    @PowerSkor 4 ปีที่แล้ว

    I keep getting values from the default resource file. The notFound variable is false so he is not falling through but just not looking for any other file when the culture has been set differently. I have already checked the cookie and everything on that side seems to work. Any tips?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Make sure you have enabled the proper cultures, make sure the file is named correctly, and make sure you are using the right namespace (I used App so my files are all named App).

    • @PowerSkor
      @PowerSkor 4 ปีที่แล้ว

      I did find the solution. My default resource file was set to embedded but the others were not. Thanks for your response!

  • @michaelhochriegl9501
    @michaelhochriegl9501 3 ปีที่แล้ว

    Awesome video Tim! I'm currently trying to get localization to work on a razor class library and can't get it to work. Do you or anyone else in the comments can give me some hint on how to achieve a localization in a razor class library used by a Blazor server project?

  • @Barto2You
    @Barto2You 4 ปีที่แล้ว

    Hi Tim, as always: love your videos. Interesting to see that you can use MVC in Blazor. But why not the cookies logic in the RequestCultureChange? do you have a reason for that?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +2

      I wanted to show off mixing the two (plus, the foundation of it came from an example in the Microsoft docs).

  • @daten4705
    @daten4705 4 ปีที่แล้ว

    So my question is, If you are translating say, a paragraph, 100+ words, Surely its not a good idea to store that as the key? would you then at that point start using references instead of the full text, which then also means you would have to make sure it can never default to the text in the localization brackets?

    • @Baby4Ghost
      @Baby4Ghost 4 ปีที่แล้ว

      Use an short descriptive key: product_description_specs | home_intro_text
      Furthermore, I use a static class with constant string properties to match the keys and use the static class in my code.
      resource file: Resources/Pages/Index.en.resx
      key: product_description_specs
      nested static class, const string: ResourceNames.Pages.Index.PRODUCT_DESCRIPTION_SPECS = "product_description_specs"
      usage:
      @inject IStringLocalizer LocalLoc
      @LocalLoc[ResourceNames.Pages.Index.PRODUCT_DESCRIPTION_SPECS]

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      If you have a paragraph then yes, it would be the exception. You would just need to be sure that the fallback text was in the main file.

  • @mahdyataey1051
    @mahdyataey1051 4 ปีที่แล้ว

    Thank you dear teacher

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      You are very welcome

  • @EpicBugHD
    @EpicBugHD 4 ปีที่แล้ว

    Hi Tim, at first i appreciate your videos very much. You have a great understanding for what people want to know in certain topics. I'm always wondering how you come up with videos for things i was struggeling with a few days before. Keep on with IT!
    Now to my question: If i just want to change the Application internal Culture for example Date Formats how would i do it ? Without creating those dictionaries for the UI Texts.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      If you just change the culture and not the cultureUI, you will change the data formats, money, etc. without needing the resource files.

  • @the_real_daniel_weber
    @the_real_daniel_weber 4 ปีที่แล้ว

    Hi, thx for this great tutorial, do you have made more tutorials about Blazor?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      Yes I have. Go to my TH-cam channel page and use the search option under the subscribe/unsubscribe button - th-cam.com/channels/-ptWR16ITQyYOglXyQmpzw.html It will only show you videos from my channel

    • @the_real_daniel_weber
      @the_real_daniel_weber 4 ปีที่แล้ว

      @@IAmTimCorey thx for the fast response

  • @volibita8902
    @volibita8902 ปีที่แล้ว

    Tim, thx for the amazing explanation of this topic!
    i think i do something wrong.....
    everything works only if the resource file is one single and inject like
    @inject IStringLocalizer Localizer
    if you make separate resource files for each component
    and import them into the component, let's say like this
    @inject IStringLocalizer Localizer
    @inject IStringLocalizer Localizer
    ..
    it doesn't work
    people in comments say "the files must be a public"
    my files are public, but locatization still not work
    Does anyone know how to do it?

  • @borislavnikolov1078
    @borislavnikolov1078 4 ปีที่แล้ว

    How can I put my projects in a separate project library? And use it?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Sorry, I am not sure what you are asking. If you want to put code in a separate project library, you use a class library project. Is that what you are asking? If you are asking about the localization files, they are UI-specific so I would recommend against trying to put them somewhere else. That does not give you any benefits but it does cause problems.

    • @borislavnikolov1078
      @borislavnikolov1078 4 ปีที่แล้ว

      @@IAmTimCorey Yes, that is what I was asking. I figured it out. I needed just to make my resource's 'Access modifier' to 'Public' and then use it. Also, the path to be empty in DI.

  • @akmalbukhariev7932
    @akmalbukhariev7932 ปีที่แล้ว

    Hello I am working on the project that I need to use multiple language and then I want to set default culture. Everything is working fine and I can change the language, it works but I couldn't set default culture. Project is starting with default English language, even though I changed it to Russian language. Thank you.
    var supportedCultures = new[] { "en-US", "uz-UZ", "uz-Cyrl", "ru-RU" };
    var localizationOptions = new RequestLocalizationOptions()
    .SetDefaultCulture(supportedCultures[3])
    .AddSupportedCultures(supportedCultures)
    .AddSupportedUICultures(supportedCultures);

  • @majormartintibor
    @majormartintibor 4 ปีที่แล้ว

    There is a bit of a sloppy "mistake" in here. If you open the dropdown and instead choosing a language you click on select... and then click change the application crashes. Would have been nice to prevent this.

    • @zulhishamtan4308
      @zulhishamtan4308 4 ปีที่แล้ว

      You can just assign the option value to an empty value.
      Here is the example :
      It will never get changes.

  • @ramioopgotoguy9642
    @ramioopgotoguy9642 3 ปีที่แล้ว

    thank you man

  • @seenals7102
    @seenals7102 4 ปีที่แล้ว

    Thanks for this video. It gave a good understanding on localization in blazor server app. Could you also please do one video on logging infrastructure available in asp.net core blazor server app. And how to fake or mock it during unit testing.?

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Noted and added to the list. Thanks!

    • @seenals7102
      @seenals7102 4 ปีที่แล้ว

      @@IAmTimCorey thank you

  • @ayushiverma9068
    @ayushiverma9068 4 หลายเดือนก่อน

    i have given my mail id but i didnt recieve the source code

    • @IAmTimCorey
      @IAmTimCorey  4 หลายเดือนก่อน

      It should have recently arrived.

  • @danieljohnson4462
    @danieljohnson4462 3 ปีที่แล้ว

    Any plans of doing a tutorial on Razor Class Library? Would be a nice addition ;)

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      It is on the suggestion list.

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
    @SayWhaaaaaaaaaaaaaaaaaaaaaaat 4 ปีที่แล้ว

    Sad you did not include SUPER IMPORTANT steps... How to put variable in translation? How to use counts?? in many languages, almost all, numbers have different endings in words..not to mention that words have sex.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      It depends on what you mean by putting a variable in a translation. You can't put a variable in and have it translated in some way. Translation files are static. So if you have a variable, that's the value it will be. You can put that variable into the translation using the curly braces but that is going to put the same value in that spot regardless of which language is being displayed. As for words having sex, again, the system isn't doing any translating. You are. So you can put the right sex in the translation for a given language.

  • @phucnguyen0110
    @phucnguyen0110 3 ปีที่แล้ว

    Not sure what I did wrong, I can get the culture to work, but not the actual translation of the elements.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      Maybe download and compare my source code to yours. That should show you the difference.

    • @phucnguyen0110
      @phucnguyen0110 3 ปีที่แล้ว

      @@IAmTimCorey Will do, thank you!

    • @phucnguyen0110
      @phucnguyen0110 3 ปีที่แล้ว

      @@IAmTimCorey Something unrelated/related to this, since you've mentioned that we can implement MVC from the older ASP.NET Framework, that means we can use it to create registration/login/logout pages without the built-in Identity framework.
      So I can do the same thing (login/register controller) here in the Blazor Server app? Would love to have some additional pointers! Thank you.

  • @ideuterium
    @ideuterium 2 ปีที่แล้ว

    so great...

  • @cryptodapps3340
    @cryptodapps3340 4 ปีที่แล้ว

    Because you talked about browser cookie I got cookie ads below this video lol

  • @guntergottbrecht5915
    @guntergottbrecht5915 3 ปีที่แล้ว

    Hi Tim,
    a great video, thanks so far. i couldn't make it run in .net 6.0 unlikely.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      It should work just the same in .NET 6.

    • @guntergottbrecht5915
      @guntergottbrecht5915 3 ปีที่แล้ว

      @@IAmTimCorey That is what i think. but in .net 6 you dont have the startup.cs anymore. So i need to find another approach to implement it.

  • @aliascross
    @aliascross 4 ปีที่แล้ว

    Hello, great job !
    For information and maybe help others, i had an issue out of the box with NavigationManager.NavigateTo() which didn't change the page. To fix it, i replace "form" by "span" in " in ChooseLanguage.razor. It works well now. I use a VS 2019 16.8.2 on a VM Windows 10 version 2004.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      Thanks for sharing

  • @FocusAmbientMusic
    @FocusAmbientMusic 3 ปีที่แล้ว

    Hi Tim, another great video i have try with .net core 5 but dont create the cookie maybe i do something wrong. I would try to find the problem. Edit: Find the problem miss a "@" :)

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      I'm glad you figured it out.

  • @salmamerieh5704
    @salmamerieh5704 ปีที่แล้ว

    we need translation using Json files

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      Unfortunately, I don't see that on the roadmap.

  • @lordjim9971
    @lordjim9971 2 ปีที่แล้ว

    Know everybody. :) How to do it without Controller?

  • @zulhishamtan4263
    @zulhishamtan4263 4 ปีที่แล้ว

    . Net is the best of the best

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      I am glad you enjoy it.

  • @deandre1988
    @deandre1988 9 หลายเดือนก่อน

    2024 ? Dont waste your time watching this or programming it. No longer how things are done

  • @denis.akopyan
    @denis.akopyan 4 ปีที่แล้ว

    Thanks for covering this topic. However, I find it weird that you explain every little detail. I'd rather say that this video is for those, who have at least 3 months of experience or something like that instead of explaining what a dictionary is in a video for developing C# webapps.

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +5

      I try to reduce assumptions. You may know about Dictionaries but someone else might not. They might know about the _imports file and you might not. If I assume too much, I make it difficult for people to learn.

  • @dastansmailov4923
    @dastansmailov4923 4 ปีที่แล้ว

    How can I get a job in Europe or USA as .NET developer? Share with links if you have any

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      It all depends on what you mean. If you need to learn C#, I have videos to help you out (check out my learning path video). If you are looking to know how to get a job once you are ready to apply, check out my Dev Questions playlist. I cover quite a few questions you probably have. If you are looking for specific jobs to apply to, this isn’t the place to find them.

  • @teckyify
    @teckyify ปีที่แล้ว

    That's a loooooot of talking in the first 9 minutes, completely unnecessary

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
    @SayWhaaaaaaaaaaaaaaaaaaaaaaat 4 ปีที่แล้ว +2

    1 hour 20 minutes to add localization!!!! Not even watching and can tell this is the bad way to do it. If i cant do it 10 minutes-it's wrong. Not by Tim but wrong and shitty implementation by Microsoft.

  • @charliersfrederic660
    @charliersfrederic660 ปีที่แล้ว

    Faaaaaaaaaaaaaaaaaaaaaaaaar tooo slooooow .. com'on guy we try to understand how work localization! not how work a dictionnary!

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      In other words, it wasn't for you. That's fine. I can't create content for everyone. Sorry you didn't find what you were looking for.