Reputation: 916
I used this great guide to localize my ASP.NET MVC 2 application, which I followed almost to the letter. The app is mainly form based.
I was wondering if there was an easy way to be able to switch between languages in the middle of filling out a form without clearing the whole form, and having to start over? If not, could you suggest a way of localizing an application that would support this?
Maybe that's not a thing...
Upvotes: 1
Views: 202
Reputation: 24088
The approach used in the article is not the best one to keep the localisation I guess.
But what you can do is the following:
JavaScript pseudocode:
var submitCurrentForm = function() {
$("form:last").submit({
data { dontSave: "True"} // this is just meta, you can use QueryString or hidden input
});
}
var switchLanguage = function(href, done) {
$.post(href).success(done); // using jQuery deferred
}
$("a.lang").click(function(e) {
e.preventDefault();
switchLanguage(this.href, submitCurrentForm);
});
Controller pseudocode:
public ActionResult Create(YourStuff stuff, bool dontSave = false) {
if (!dontSave)
ProcessTheStuff();
return View(stuff);
}
Not the best solution, but the easiest one you can go with ATM.
Upvotes: 1