filmov
tv
Blazor (ASP.NET Core) - Localization | Globalization

Показать описание
Localization in Blazor WebAssembly Applications.
In this video , we are going to learn how to implement localization in Blazor WebAssembly applications.
Steps:
- Create a new Blazor WebAssembly application.
- The first thing we have to do is to install the Microsoft.Extensions.Localization package.
- We are going to register services for application localization. To do that, we are going to modify the
Program class
- We need a place to store our localization resources. You can do that in different ways, but in this
video , we are going to use resource (.resx) files.
- Create a new ResourceFiles folder under the Shared folder, and let’s create two resource files inside
German translations.
- We inject the IStringLocalizer service to provide localized strings. As you can see, we provide the
Resource class for the type because this is the class that contains localized strings. Then, instead of the hard-coded strings, we use the localizer variable and provide a key, which is a key
from the resource file. Of course, this will return a value from the same resource file.
- We create a select element and bind it to the Culture property and also for each supported culture,
we create a select option. Of course, we are missing the Culture property and the cultures
- Then, we create a cultures array with two supported cultures – en-US and de-DE. Also, we create a
missing Culture property of the CultureInfo type. This property returns the current culture used in
the application. Also, when we select a new culture in our drop-down list, this property does some
logic in the set part. We first check if the current culture is different than a selected one. If it is, we
use JSInterop to invoke the Javascript’s blazorCulture object with a set accessor that sets the
culture name in the local storage. Finally, we use the NavigationManager to navigate the user to
the requested URI and use the forceLoad parameter to reload the page. We do that because once
default one.
- Create a new Extensions folder and inside it a new WebAssemblyHostExtension class.
this extension method, we extend the WebAssemblyHost type and use JSInterop to call the get
accessor from the blazorCulture Javascript object. This get accessor will return the culture name
from the locale storage. If the name is returned, we create a new CultureInfo object with that
name, otherwise, we create a new CultureInfo object with the en-US as a parameter. Finally, we set
the DefaultThreadCurrentCulture and the DefaultThreadCurrentUICulture properties to the created
culture.
blazor localization resx
blazor localization wasm
blazor webassembly localization
blazor language switch
blazor multi language
#blazortrain
#blazortraining
In this video , we are going to learn how to implement localization in Blazor WebAssembly applications.
Steps:
- Create a new Blazor WebAssembly application.
- The first thing we have to do is to install the Microsoft.Extensions.Localization package.
- We are going to register services for application localization. To do that, we are going to modify the
Program class
- We need a place to store our localization resources. You can do that in different ways, but in this
video , we are going to use resource (.resx) files.
- Create a new ResourceFiles folder under the Shared folder, and let’s create two resource files inside
German translations.
- We inject the IStringLocalizer service to provide localized strings. As you can see, we provide the
Resource class for the type because this is the class that contains localized strings. Then, instead of the hard-coded strings, we use the localizer variable and provide a key, which is a key
from the resource file. Of course, this will return a value from the same resource file.
- We create a select element and bind it to the Culture property and also for each supported culture,
we create a select option. Of course, we are missing the Culture property and the cultures
- Then, we create a cultures array with two supported cultures – en-US and de-DE. Also, we create a
missing Culture property of the CultureInfo type. This property returns the current culture used in
the application. Also, when we select a new culture in our drop-down list, this property does some
logic in the set part. We first check if the current culture is different than a selected one. If it is, we
use JSInterop to invoke the Javascript’s blazorCulture object with a set accessor that sets the
culture name in the local storage. Finally, we use the NavigationManager to navigate the user to
the requested URI and use the forceLoad parameter to reload the page. We do that because once
default one.
- Create a new Extensions folder and inside it a new WebAssemblyHostExtension class.
this extension method, we extend the WebAssemblyHost type and use JSInterop to call the get
accessor from the blazorCulture Javascript object. This get accessor will return the culture name
from the locale storage. If the name is returned, we create a new CultureInfo object with that
name, otherwise, we create a new CultureInfo object with the en-US as a parameter. Finally, we set
the DefaultThreadCurrentCulture and the DefaultThreadCurrentUICulture properties to the created
culture.
blazor localization resx
blazor localization wasm
blazor webassembly localization
blazor language switch
blazor multi language
#blazortrain
#blazortraining
Комментарии