0

I currently have all static text in my website using the resource files to serve up english or spanish text depending on the users browser settings. This is easy. What I would like to do now is serve up content in my views that is coming from the database depending on the UI Culture. I have structured my database so that I have both english and spanish descriptions for products etc.. But I don't know how to serve one or the other based on UI Culture.

I would also like the ability to have a toggle button somewhere on the site so that a user can switch the language setting to spanish if english is showing or other way around.

I have this piece of code that can change the UI Culture on a single page/view.

    System.Threading.Thread.CurrentThread.CurrentUICulture = 
    new System.Globalization.CultureInfo("es");

I'm sure that storing that in a cookie or session is a step in the right direction of making a toggle button. But what about serving the content from the database based on UI Culture. I was thinking I could base each view by determining what the UI Culture is set to and then serving either the SPanish or the English content. But is there a tutorial or something I could find to help me do this with MVC 4.

Any help would be greatly appreciated. I have heard of using Action Filters, but when I read up on it, there was no clear way of doing it that I could find. My site only needs to support for 2 languages.

Eric Bishard
  • 5,201
  • 7
  • 51
  • 75
  • What part causes you a problem? Is it "how to store user's language choice" (cookie/session state/url/something else) OR "how to pass current culture name to database query"? – Alexei Levenkov Nov 25 '13 at 00:26
  • Both. Less about the cookie/session because that is something I would like but do not need. I need to serve content based on UI Culture from my database queries, etc.. – Eric Bishard Nov 25 '13 at 00:37
  • How is your DB structured? – Remy Nov 25 '13 at 13:47
  • I have an English and Spanish version of each name and description of every product in my database. . the rest of my database is similarly structured that way. – Eric Bishard Nov 25 '13 at 15:30
  • This question can't be that hard can it? I have since found some articles on it, but Im still in the weeds. – Eric Bishard Nov 27 '13 at 22:31

0 Answers0