Multi - Language Application in Asp.net MVC3
In order to create multi-language application following are the requirements :
1. Resource files to store text for different languages. Each language will have its separate resource file.
2. A form to display text in different languages.
3. A custom abstract class which overrides ExecuteCore() method of controller class and inherits controller class.
4. Cookie, to store and pass language selected in dropdown from view to ExecuteCore() method.
Watch Video
Following are the steps explained :
First we are going to create a form and Register class file.
We are going to use the properties defined on the above image on the form. Lets see how view will look like.
The properties defined in register class are used in this form.
We are done with properties and form. Now we will se how to create resource files.
In order to hold resource files, we have created MultiResources Folder and added 4 resource files. One file is for english and other are for
Spanish, French and German. While naming these resource files, we need to follow naming convention as shown in the image. Lets see what these files will include.
The resource file above is for language english. It has xml tags. There is one data tag which holds key. This key is used to access the value mentioned in the value tag.
This key will be present in all the resource files, but with value in that particular language.
The above image is for french language resource file. As you can see it has same keys as mentioned in english resource file, but with different value.
We will see how to use these keys at view level.
In order to use resource keys, we need to add reference of Resource files. As shown in above image, we have to add reference of MultiResource folder. Then we can use those keys in our view as shown below.
As you can see in the above image we have use Multi keyword and accessed key from the resource files. The application depending on the current culture will pick the text from resource file matching the current culture. Lets see how we are going to store data in the cookie.
On Change event of Language dropdown, we are accessing the language selected and we create a cookie storing the language selected. The above code does the same. Now we will see how we gonna use this cookie on controller.
As shown in above image, we will create one helper folder and inside that folder will create one class. This class will hold the ExecuteCore() method as shown below.
We have to create an abstract class which will inherit controller class. Inside this class we will override ExecuteCore() virtual method. This method is called before any other ActionResult method.
As we can see in the above image, we are accessing the language value from cookie. Using switch loop, we are setting correct culture name depending upon language selected and retrieved from cookie.
And finally the current thread's culture is set. After execution of this method, our Index method is called as shown in image below.
As shown in above image the HomeController class inherits MultiBase class which we created and which inturn inherits controller class. After executing ExecuteCore() method Index() method is called and view is rendered wit current culture set to language selected in the dropdown.
You may also want to know :
Snapshots :
it will have been nice to have attach the project...
ReplyDeleteNice Tutorial with nice Video :)
ReplyDeletethis is tut very nice
ReplyDeleteyou can send this project source to my email
email: trinhxuantienvn@gmail.com
thanks for you.
i will be waiting your mail.
Thakns for the video and the article. Both are excellent. However one giant improvement would be to have the selected language parameter e.g us, es, de and so forth inserted into the url, in order to gain full SEO credits
ReplyDeleteyou can send me this project source to my email please
ReplyDeleteemail: greiman113@gmail.com
hi, your Tuto is very kool
ReplyDeleteI still try this.
Can you share me This Project
My email: juriyaro@gmail.com
Thank a lot .
Hoi, your tutorial is very good, can u share me this project ha15341@gmail.com , thnx for you
ReplyDeleteHello, I was also hoping you could email/share the project with me? Thanks for all your work! triggermouse@gmail.com
ReplyDeleteHi can you share the project with me?
ReplyDeleteholofracta@gmail.com
Hi can you share the project with me?
ReplyDeleteleocarminatti@gmail.com
thanks
Thanks for Tutorial!) Can You send us to me, please? My email is 291433@gmail.com
ReplyDeleteHi can you share the project with me?
ReplyDeleteMy email is huy.nguyen@gmail.com
Thanks! ^^
Best project for mutil language. thanks for sharing
ReplyDeletehi can you share me this project, my email is abdelcapone@hotmail.fr
Deletethanks
hi, your Tuto is very kool
ReplyDeleteI still try this.
Can you share me This Project
My email: emkoroglu@gmail.com
Thank a lot .
hi can you share me this project, my email is abdelcapone@hotmail.fr
ReplyDeletethanks
Hi, nice tutorial can you please share me this Project my email adityakumar.soma@gmsil.com
ReplyDeleteThank you