Note - Please do not create your resource files under specialized folders App_Local Resources or App_Global Resources folder for Asp. You can specify a namespace for resource file from the property window of the added resource files.Net MVC application since they are compiled by Asp. The below image shows “Resources” namespace added to the resx file.
For simplicity, we will just add a Tamil language support in addition to the default English locale.
Once built, the application will support both English and Tamil language as seen in the below screen shots.
_Layout.cshtml This is the final step where the application need to know which resource file (or language) it has to choose when rendering the view.
This can be done by setting current request’s thread culture to user preferred locale.
This step is where we will replace the hard coded texts in the view files to resource file keys for fetching the texts based on the locale.
The _Layout.cshtml file has some application wide mark-ups which will be available across application.For employee maintenance application, I have created one resource file for each controller in addition to a file for storing application wide texts, Error for storing error messages and a file to store any common text that can be shared in multiple views.The final list of resource files including Tamil is as seen below in solution explorer under Resources folder.Assuming, you have the project created with all the necessary Nuget packages required to run Asp.Net MVC 5.0 and Entity Framework, let’s go ahead and add multi-language support to Employee Maintenance application.We need to create a custom controller activator and configure the MVC to use it when creating controller instance. System Web Nuget package already added for the above code to work. In my next article, we will see some advanced scenarios like giving user the option to change language on the site and sending the user preferred locale as a route parameter, etc.