473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Translation by Resources Files in MVC3

ParPar
6
Hello,
I have a view named Step_1
and two resources files:
  1. Step1.resx - which is in English, and default
  2. Step1.fr.resx - which is in French.

On the view there is a selectbox with two options as you guess what they are, (English and French).

Now is the big question:
How do i make the language change according to the selected value???

(meanwhile the view takes its text from the file 'Step1.resx'. I wrote it like this: @Step1.resx.Hello instead of Hello)

I'd like to get some help because I couldn't find any good explanation in the subject all over the web.

Thanks.
Sep 8 '11 #1

✓ answered by Frinavale

I found a lot of useful articles when I googled the topic of "ASP.NET MVC Localization"

Since I've never used localization in MVC before I tried out this article: ASP.NET MVC 2 Localization complete guide which was very straight forward and pretty easy to do.

I was able to create a localized MVC project fairly quickly. I have attached my project for demonstration purposes. My project is implemented in VB.NET using Visual Studio 2010 (the article is in C#)

To change the language for your website you need to set the current thread (the thread that the web application is running under) to use the specified culture. You need to do this at a particular time the life cycle of your web application...in the Application_AcquireRequestState event. You can handle this event in the Global.asax file.

When the user selects the language/culture that they would like to view the site in, you need handle the event and store this preferred setting somewhere. In the article and in my example project this value is stored in Session; however, you could also store this value in a cookie etc.

After you've saved the user's preferred language/culture you need to tell the website to refresh itself since the language/culture is only set in Application_AcquireRequestState event (which is very early in the request's life cyle). To do this you issue a Response Redirect to the rawURL the page was showing after you've stored the preferred language/culture.

I'm sure that article will help you to understand what you need to do to accomplish your task.

-Frinny

2 4043
Frinavale
9,735 Expert Mod 8TB
I found a lot of useful articles when I googled the topic of "ASP.NET MVC Localization"

Since I've never used localization in MVC before I tried out this article: ASP.NET MVC 2 Localization complete guide which was very straight forward and pretty easy to do.

I was able to create a localized MVC project fairly quickly. I have attached my project for demonstration purposes. My project is implemented in VB.NET using Visual Studio 2010 (the article is in C#)

To change the language for your website you need to set the current thread (the thread that the web application is running under) to use the specified culture. You need to do this at a particular time the life cycle of your web application...in the Application_AcquireRequestState event. You can handle this event in the Global.asax file.

When the user selects the language/culture that they would like to view the site in, you need handle the event and store this preferred setting somewhere. In the article and in my example project this value is stored in Session; however, you could also store this value in a cookie etc.

After you've saved the user's preferred language/culture you need to tell the website to refresh itself since the language/culture is only set in Application_AcquireRequestState event (which is very early in the request's life cyle). To do this you issue a Response Redirect to the rawURL the page was showing after you've stored the preferred language/culture.

I'm sure that article will help you to understand what you need to do to accomplish your task.

-Frinny
Attached Files
File Type: zip MVCResourcesProject.zip (377.7 KB, 281 views)
Sep 9 '11 #2
ParPar
6
Thank you especially for the link you sent to me.

And people, if you need to localize by resources files in MVC3, I strongly recommend on this site, and from my experiance you should use his other way of localization (by routing) that you find in this link:
http://adamyan.blogspot.com/2010/07/...alization.html

It works well. Good luck!
Sep 14 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jesse | last post by:
Hi together, I've a problem with compiling an application with a build-Script and run it after. Several resource-files I compile with resgen.exe and put the files into a folders of the...
0
by: Mullin Yu | last post by:
hi, my project has other files, e.g. xml files, ini files, image files. after i build the project, only the pdb files will be created to a specific/pre-defined folder, but none of those...
3
by: Gianmaria I. | last post by:
Hi, why if i modify a resx file from project file, a file that contains localization, the ones added by visual studio on multilanguage enablig, this files is automaticalli modified ad returns as...
0
by: amartos | last post by:
Hi, I am trying to create a dll file from several resources files. I am using visual studio .net and I have a c++ project which has included a file called "Resource.es-ES.resources", in the...
0
by: GT | last post by:
Hello I'm trying to embed .resource files into a Windows application in VS2005, and then compile and run the program from VS2005. This does not work because the debugger seems not find the...
0
by: Sami Rehman | last post by:
hi Has anyone experince this problem.? I have seen a lot of solutions for this problem. None of them have gotten rid of it. Error message is: Could not find any resources appropriate for the...
0
by: schaf | last post by:
Hi All! I would like to have additional information (ResourceBuildDate) in the *.resx and afterwards in the *.resources to ensure the right .resources would be used for the satellite assemblies. ...
2
by: schaf | last post by:
Hi NG ! I would like to add additional information to a .resources file. For instance the translation date, How can I add this information to the .resources file of a form? In the resheader, the...
5
Leito
by: Leito | last post by:
I have created an application with two resources files: - Localization.resx for the english language - Localization.fr-FR.resx for the french language I searched the web, but didn't find...
0
Leito
by: Leito | last post by:
Hello, I have a problem when accessing the resources files of my project after publishing it. As it is a bit complicated (at least I have already struggled to come to this point), I'll first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.