Localization in Blazor Server - How To Change Languages and Cultures

  Рет қаралды 36,233

IAmTimCorey

IAmTimCorey

Күн бұрын

Blazor Server is an excellent choice for a web application. But unless your audience only speaks one language, you probably need to consider localization. Localization is the ability to present an application in the culture of the user. This is more than just about translating text. Different cultures have different currencies, different ways of representing numbers, different date formats, and more. In this video, we are going to apply localization to a Blazor Server app in a way that will present the user with the site in their culture, but also give them the option of changing the culture of the site.
Source Code: leadmagnets.app/?Resource=Bla...
Mailing List: signup.iamtimcorey.com
Purchase Courses: iamtimcorey.com
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
Chapter breakdown was user contributed!

Пікірлер: 198
@randomdevfromgermany1951
@randomdevfromgermany1951 3 жыл бұрын
I literally wasted an hour searching for two minor mistakes with my localization yesterday, and then you uploaded this video. Thank you!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad I could help! Timing is everything! LOL
@chilledwine4739
@chilledwine4739 2 жыл бұрын
Great tutorial, implemented it while watching almost without stopping! Excellent explained... Keep going!
@davidjnevin
@davidjnevin 2 жыл бұрын
Great stuff! We're branching out into two additional languages. Really useful. 👏👏
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Glad it was helpful!
@Hazuuur
@Hazuuur 2 жыл бұрын
Thanks Tim, you are always here when I need help :D
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@abdouldia1605
@abdouldia1605 3 жыл бұрын
Wonderfull video. Solved my problem at work. You are great Tim. Keep it up.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad to help.
@natalyalmassry6775
@natalyalmassry6775 3 жыл бұрын
Thank you for the video and detailed explanation! Your video helped me to finally figure out localization in blazor
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it helped!
@dyakobaram
@dyakobaram 3 жыл бұрын
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 3 жыл бұрын
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.
@shawnmofid7131
@shawnmofid7131 3 жыл бұрын
I am so glad I saw this. I really like the supped up layout of blazer pages.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
I'm so glad!
@stievenhultermans4559
@stievenhultermans4559 3 жыл бұрын
Super tutorial. Made me be able to change the language on my Blazor site!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it helped!
@bujin1977
@bujin1977 3 жыл бұрын
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 3 жыл бұрын
I'm glad it was enjoyable.
@user-sj4hi5iy1m
@user-sj4hi5iy1m 2 жыл бұрын
Thank you very much for your work, I will say that you are a great teacher and your actions inspire good work.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@zulhishamtan4308
@zulhishamtan4308 3 жыл бұрын
This is super awesome video. Thank you Tim for the precious information sharing. .Net is the best of the best ever.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad you enjoyed it!
@Dorsalwarrior0
@Dorsalwarrior0 3 жыл бұрын
Really helpful, works like a dream thank you sir.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Great to hear!
@troymitchel4790
@troymitchel4790 3 жыл бұрын
Hey, just stopped by to give you a thumbs up for all your contributions to the .net world.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks
@aog.tr.6828
@aog.tr.6828 Жыл бұрын
Great video! Thank you very much.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@casastreetview9856
@casastreetview9856 Жыл бұрын
Hi Tim, Great video thank you
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@maranb8
@maranb8 3 жыл бұрын
Thanks for this great one Tim, fan from India
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad you enjoyed it!
@MarioStaats
@MarioStaats 3 жыл бұрын
Great work as always @IAmTimCorey *ThumbUp
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks again!
@kctripathy
@kctripathy 2 жыл бұрын
Thank you so much for such a wonderful video. Kudous to your efforts
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@bigtech59
@bigtech59 10 ай бұрын
you introduced well . thanks alot from iran ❤
@IAmTimCorey
@IAmTimCorey 10 ай бұрын
You are welcome.
@emersonstori
@emersonstori Жыл бұрын
Congratulations, this is the best video on this subject on the entire internet.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@Foodies-pv7ih
@Foodies-pv7ih 3 жыл бұрын
much needed, thanks
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are welcome!
@salvatoreseverini9734
@salvatoreseverini9734 3 жыл бұрын
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?
@EpicBugHD
@EpicBugHD 3 жыл бұрын
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 3 жыл бұрын
If you just change the culture and not the cultureUI, you will change the data formats, money, etc. without needing the resource files.
@MarcR1v
@MarcR1v Жыл бұрын
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.
@sheikhbashar1
@sheikhbashar1 3 жыл бұрын
Thanks So much TimCory
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
My pleasure!
@Barto2You
@Barto2You 3 жыл бұрын
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 3 жыл бұрын
I wanted to show off mixing the two (plus, the foundation of it came from an example in the Microsoft docs).
@mahdyataey1051
@mahdyataey1051 3 жыл бұрын
Thank you dear teacher
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are very welcome
@99MrX99
@99MrX99 3 жыл бұрын
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 3 жыл бұрын
I haven't. I'll check it out. Thanks!
@mirragemelkyr
@mirragemelkyr 3 жыл бұрын
Great Video, thanks for covering this topic, for some reason this didn't work the same on firefox, but chrome sure works.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
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 11 ай бұрын
Were you able to find the answer to this problem?
@Folkert1975
@Folkert1975 2 жыл бұрын
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).
@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 жыл бұрын
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.
@c7e7c7g7
@c7e7c7g7 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
@DoronAviadEnduroKTM
@DoronAviadEnduroKTM 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
@ramioopgotoguy9642
@ramioopgotoguy9642 2 жыл бұрын
thank you man
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@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 2 жыл бұрын
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}"
@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.
@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.)?
@user-rl5li6oo7b
@user-rl5li6oo7b 8 ай бұрын
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???
@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
@gupsekobas2209
@gupsekobas2209 Жыл бұрын
great video indeed!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thank you!
@TechNobo
@TechNobo 3 жыл бұрын
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.
@marcusmaunula5018
@marcusmaunula5018 3 жыл бұрын
Appreciate the Localization clip. This is imho the least made course type for C# :)
@marcusmaunula5018
@marcusmaunula5018 3 жыл бұрын
Also. What is the difference with Client Blazor then?
@Baby4Ghost
@Baby4Ghost 3 жыл бұрын
​@@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 3 жыл бұрын
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 3 жыл бұрын
@@Baby4Ghost Thanx, sorry for the the late reply but appreciated nonetheless :).
@marcusmaunula5018
@marcusmaunula5018 3 жыл бұрын
@@IAmTimCorey Thank you.
@maacpiash
@maacpiash 3 жыл бұрын
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 3 жыл бұрын
Noted! Added to the list.
@carlosjosejimenezbermudez9255
@carlosjosejimenezbermudez9255 3 жыл бұрын
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 3 жыл бұрын
@@IAmTimCorey yes please!
@brirembillel1959
@brirembillel1959 3 жыл бұрын
thank you very much , Great video, but how we can use localization in Razor class Library!???
@jaywalks9918
@jaywalks9918 3 жыл бұрын
Where is the Time zone for the client/server set? Or maybe dates set on the client are always in UTC?
@michaelhochriegl9501
@michaelhochriegl9501 2 жыл бұрын
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?
@ideuterium
@ideuterium 2 жыл бұрын
so great...
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@AthulRajts
@AthulRajts 3 жыл бұрын
Is it possible to use IStringLocalizer in a WPF application ?
@the_real_daniel_weber
@the_real_daniel_weber 3 жыл бұрын
Hi, thx for this great tutorial, do you have made more tutorials about Blazor?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Yes I have. Go to my KZfaq channel page and use the search option under the subscribe/unsubscribe button - kzfaq.info/love/-ptWR16ITQyYOglXyQmpzw It will only show you videos from my channel
@the_real_daniel_weber
@the_real_daniel_weber 3 жыл бұрын
@@IAmTimCorey thx for the fast response
@maksy09
@maksy09 2 жыл бұрын
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 10 ай бұрын
I have this issue as well....
@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.
@chamir4614
@chamir4614 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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.
@randomdevfromgermany1951
@randomdevfromgermany1951 2 жыл бұрын
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?
@mastercompuk
@mastercompuk 3 жыл бұрын
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.
@CeranPOL
@CeranPOL Жыл бұрын
So how to change language in all of the components that use localization with single button?
@user-yl1un5pe4v
@user-yl1un5pe4v 5 ай бұрын
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?
@scwyldspirit
@scwyldspirit 3 жыл бұрын
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 3 жыл бұрын
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.
@scwyldspirit
@scwyldspirit 3 жыл бұрын
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 :)
@seenals7102
@seenals7102 3 жыл бұрын
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 3 жыл бұрын
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).
@TravelingGonad
@TravelingGonad 4 ай бұрын
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??
@seenals7102
@seenals7102 3 жыл бұрын
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 3 жыл бұрын
Noted and added to the list. Thanks!
@seenals7102
@seenals7102 3 жыл бұрын
@@IAmTimCorey thank you
@RalfsBalodis
@RalfsBalodis 3 жыл бұрын
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 жыл бұрын
Thanks! Are you saying 'Sveiki Pasaule' contributed this?
@RalfsBalodis
@RalfsBalodis 3 жыл бұрын
@@IAmTimCorey I'm saying "Hello World" :)
@RalfsBalodis
@RalfsBalodis 3 жыл бұрын
@@IAmTimCorey Sorry for confusion
@danieljohnson4462
@danieljohnson4462 3 жыл бұрын
Any plans of doing a tutorial on Razor Class Library? Would be a nice addition ;)
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
It is on the suggestion list.
@dyakobaram
@dyakobaram 3 жыл бұрын
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 3 жыл бұрын
Thanks, added to the suggestions list.
@ltacid
@ltacid 3 жыл бұрын
@@IAmTimCorey yes please, I need it. I am confused when people mention state in Blazor and talk about using things like Redux.
@SayWhaaaaaaaaaaaaaaaaaaaaaaat
@SayWhaaaaaaaaaaaaaaaaaaaaaaat 3 жыл бұрын
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.
@guntergottbrecht5915
@guntergottbrecht5915 2 жыл бұрын
Hi Tim, a great video, thanks so far. i couldn't make it run in .net 6.0 unlikely.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
It should work just the same in .NET 6.
@guntergottbrecht5915
@guntergottbrecht5915 2 жыл бұрын
@@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.
@klemen6961
@klemen6961 11 ай бұрын
This code works for chrome/edge but not for firefox/safari. Any idea why?
@aliascross
@aliascross 3 жыл бұрын
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 3 жыл бұрын
Thanks for sharing
@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.
@volibita8902
@volibita8902 8 ай бұрын
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?
@daten4705
@daten4705 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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.
@PowerSkor
@PowerSkor 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
I did find the solution. My default resource file was set to embedded but the others were not. Thanks for your response!
@norbertcsibi7720
@norbertcsibi7720 2 жыл бұрын
If we have a blazor server, and a webassembly under the same solution, on which project should we add the localization?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Both.
@norbertcsibi7720
@norbertcsibi7720 2 жыл бұрын
@@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?
@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(); } }
@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!
@randomdevfromgermany1951
@randomdevfromgermany1951 3 жыл бұрын
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 3 жыл бұрын
I'm looking into this. You aren't the only one to report it. Not sure what is going on yet.
@klemen6961
@klemen6961 11 ай бұрын
@@IAmTimCorey I'm using Firefox and I get the same problem. Where you able to resolve this issue?
@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/
@borislavnikolov1078
@borislavnikolov1078 3 жыл бұрын
How can I put my projects in a separate project library? And use it?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
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 3 жыл бұрын
@@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.
@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 жыл бұрын
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
@cryptodapps3340
@cryptodapps3340 3 жыл бұрын
Because you talked about browser cookie I got cookie ads below this video lol
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Mmmm, cookies.
@norbertcsibi7720
@norbertcsibi7720 2 жыл бұрын
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 2 жыл бұрын
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.
@giorgimgebrishvili4251
@giorgimgebrishvili4251 Жыл бұрын
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 Жыл бұрын
1) yes you can. 2) probably you missed something small.
@giorgimgebrishvili4251
@giorgimgebrishvili4251 Жыл бұрын
@@IAmTimCorey I used middleware in startup an set Thread.CurrentCulture. Otherwise setting culture only once doesnt help...
@giorgimgebrishvili4251
@giorgimgebrishvili4251 Жыл бұрын
@@IAmTimCorey Finally I used middleware and each time I set Thread.CurrentCultureUI
@majormartintibor
@majormartintibor 3 жыл бұрын
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 3 жыл бұрын
You can just assign the option value to an empty value. Here is the example : It will never get changes.
@akmalbukhariev7932
@akmalbukhariev7932 11 ай бұрын
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);
@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.
@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.
@salmamerieh5704
@salmamerieh5704 8 ай бұрын
we need translation using Json files
@IAmTimCorey
@IAmTimCorey 8 ай бұрын
Unfortunately, I don't see that on the roadmap.
@lordjim9971
@lordjim9971 2 жыл бұрын
Know everybody. :) How to do it without Controller?
@SayWhaaaaaaaaaaaaaaaaaaaaaaat
@SayWhaaaaaaaaaaaaaaaaaaaaaaat 3 жыл бұрын
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 3 жыл бұрын
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.
@zulhishamtan4263
@zulhishamtan4263 3 жыл бұрын
. Net is the best of the best
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
I am glad you enjoy it.
@denis.akopyan
@denis.akopyan 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
How can I get a job in Europe or USA as .NET developer? Share with links if you have any
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
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.
@deandre1988
@deandre1988 4 ай бұрын
2024 ? Dont waste your time watching this or programming it. No longer how things are done
@teckyify
@teckyify 10 ай бұрын
That's a loooooot of talking in the first 9 minutes, completely unnecessary
@IAmTimCorey
@IAmTimCorey 10 ай бұрын
👍
@charliersfrederic660
@charliersfrederic660 8 ай бұрын
Faaaaaaaaaaaaaaaaaaaaaaaaar tooo slooooow .. com'on guy we try to understand how work localization! not how work a dictionnary!
@IAmTimCorey
@IAmTimCorey 8 ай бұрын
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.
@SayWhaaaaaaaaaaaaaaaaaaaaaaat
@SayWhaaaaaaaaaaaaaaaaaaaaaaat 3 жыл бұрын
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.
@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.
Intro to Redis in C# - Caching Made Easy
1:27:29
IAmTimCorey
Рет қаралды 172 М.
Blazor Server Components - Making Razor Components Easy to Use
42:23
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 23 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 8 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 75 МЛН
Blazor Localization in .NET 8 & Blazor Server
13:58
Claudio Bernasconi
Рет қаралды 6 М.
Intro to Health Checks in .NET Core
1:13:53
IAmTimCorey
Рет қаралды 49 М.
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 204 М.
How To Create a Progressive Web App with Blazor WebAssembly
30:15
WebAPI Improvements in .NET 5 - OpenAPI, Better F5, and NSwag
46:48
Smart Sigma Kid #funny #sigma #comedy
00:19
CRAZY GREAPA
Рет қаралды 23 МЛН