Adding Multiple Languages ​​with ASP.NET Core MVC

Murat Süzen
3 min readMay 9, 2022
Photo by Rohit Tandon on Unsplash

Hello, in this article we will examine how we can add multiple language support to ASP.NET Core MVC application. First of all, since we will keep the language definitions in resource files, we will create the Resources folder in the application’s directory. Then we will add two Resource files named SharedResource.tr-TR.resx and SharedResource.en-US.resx.

Resources File

We will create a class named SharedResource in the application directory.

We were creating the Languages ​​class, which we created in the application directory in previous versions, into the Resources folder.

We will create the Utilities folder in the application directory and add the SharedViewLocalizer class.

We will add Localization settings to the ConfigureServices and Configure methods in the Startup.cs file.

After completing the service settings, we will create the ExtensionMethods folder and the HtmlHelperExtensionMethods extension class in the application directory in order to extend the IHtmlHelper that we will use in the Views.

Then, we add a list of CultureInfo values ​​that we can use in the services settings as ViewData to the Index method in the HomeController class.

We fill a section with the CultureInfo list we send with ViewData and add an Action to change the Cookie structure according to the selected Culture value.

Then we modify the Index.cshtml file.

Index.cshtml

We add LB_WELCOME name values ​​to the resource files. In this way, we can use any tag we add to the resource files like @Html.Translate(“LB_WELCOME”).

SharedResource.tr-TR.resx
SharedResource.en-US.resx
Index Page

You can download the project here. Please let me know if there are typos in my post.

--

--