Recently I came across a task, to provide Spanish version of a page. The website which needs this change is designed in asp.net 4.7.
After working many years in asp.net I knew asp.net has localization feature which is pretty easy to implement. But I never got chance to work on it.
I thought of writing this post so that if in future I forgot how to do it I can use it. Also it is help to someone who is trying to achieve similar goal for first time.
Prerequisite:
You have your asp.net MVC 4.5+ website application. If you don't have it, create a new application using visual studio template. Use visual studio 2017 or 2019.
Steps:

After working many years in asp.net I knew asp.net has localization feature which is pretty easy to implement. But I never got chance to work on it.
I thought of writing this post so that if in future I forgot how to do it I can use it. Also it is help to someone who is trying to achieve similar goal for first time.
Prerequisite:
You have your asp.net MVC 4.5+ website application. If you don't have it, create a new application using visual studio template. Use visual studio 2017 or 2019.
Steps:
- Add a new folder, give it any meaningful name. For my convenience I will name it as "Localization". It is not mandatory to create a new folder.
- Right click on newly created folder, click on 'add new item'. Select Resource file. Give it meaningful name. I am giving it name as "Resource.resx"
- Resource file is XML file having key value pair. This file will contain all label and text messages in English language.

- Similarly you need to create a new resource file for Spanish version. You have to name this file as Resource.es.resx. Note file name format is important here <filename>.<locale-code>.resx
- Set culture locale in view or code behind file.
- I am passing language / Locale using query string. Again this is not mandatory. You can set locale using cookie, session or any other technique.


No comments:
Post a Comment