From the course: ASP.NET Core: Internationalization
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Creating a custom localizer - ASP.NET Core Tutorial
From the course: ASP.NET Core: Internationalization
Creating a custom localizer
- [Instructor] So let's finish up our CustomLocalizer. I'm going to go into MyStringLocalizer. And I need two properties in this for it to work. The first one is a public property, it will return a LocalizedString. It will use the same name as the class for the property. And we are going to send in a name. And this will only have a get on the property, it won't have a set. So I need to say var, and I need to get the culture of the application. So I'm going to check to see if _culture is filled in. If it's not, then I'm going to go out to CultureInfo and get the Current UICulture. I'm also going to get the translation string that we get back from our strings that we populated. So in this FirstOrDefault, I'm going to do a search on both the culture and the name. And I'm also going to do a search on the name passed into the property. Then I'm going to return that as a LocalizedString, with one caveat. If the translation came back with nothing, meaning an empty string, I'm going to send…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.