0

Is it possible in ASP.NET MVC to use 2 different languages on a single page, each with it's own resource file?

So for example I want the header of the page to be in english and the content in german. Now there should be two dropdowns to change the language, one for the header and one for the content. If I change the header language to french the content should still stay german and vice versa.

Is this possible or not?

kufi
  • 2,418
  • 19
  • 14
  • You need some sort of localization framework. See a [previous question][1] on the topic. [1]: http://stackoverflow.com/questions/192465/how-to-localize-asp-net-mvc-application – SliverNinja - MSFT Oct 27 '11 at 06:15
  • Ok thanks. I found those parts too, but they all deal with one language on a page, not multiple languages on a single page which can be interchanged dynamically. – kufi Oct 28 '11 at 18:16

1 Answers1

0

Just an update if anyone is interested.

There is a way to solve this problem. In the example below the culture initially is set to german, then changed to english for the partial, and in the end, reset to german again.

This results in the partial being rendered with the english language, whereas the rest of the page is rendered in german.

@{
    var culture = Resources.Resources.Culture;
    Resources.Resources.Culture = new System.Globalization.CultureInfo("en");
}
@Html.Partial("Control")
@{Resources.Resources.Culture = culture;}
@Resources.Resources.welcome

With a custom helper method this would certainly look a bit more elegant.

kufi
  • 2,418
  • 19
  • 14