I've got a website which needs localizing, I have successfully achieved that automatically, by setting the culture to auto in the Web.Config and using my resx files for translation, However I'd also like a customer to be able to change the website's translation manually as a backup.
I have a form on my textbox with multiple language choices, this choice is POSTed to a controller as per the following code
[AllowAnonymous]
[HttpPost]
public ActionResult SelectLanguage(LoginViewModel model)
{
switch (Request["lang"])
{
case "English":
CultureInfo.CurrentCulture=new CultureInfo("en-GB");
CultureInfo.CurrentUICulture = new CultureInfo("en-GB");
break;
case "French":
CultureInfo.CurrentCulture = new CultureInfo("fr-FR");
CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
break;
}
var currentCulture = CultureInfo.CurrentCulture;
return RedirectToAction("Index");
}
the problem is that while my currentCulture and CurrentUICulture do change, the pages remain untranslated however,If I change this manually in the Web.config, my site translates perfectly!
Is there something I'm missing here?
Thanks in advance =]
UPDATE existing answers involving the use of InitializeCulture aren't valid AFAIK as the events in WebPages naturally aren't available in MVC