问题
Scenario
We have a SAAS product that has an Admin back-end with a public front-end. We want to give the user the option to change what language their front-end displays. There will be the option of 7+ different languages. Our product is built on C# and MVC3. The front-end only contains about 400 words. What is the best way to handle this? Could I store the different languages in resx files and have a flag in the DB to say which language the admin has chosen?
So the admin selects his language from a dropdown list and then all his public facing side will convert to that language.
I have never done anything like this before so any advice on potential pitfalls would be greatly appreciated.
Thanks
回答1:
Resource files are the most common way to solve it. And storing the language choice in a database is a good idea.
I would use OnActionExecuting
in your base controller to set the current language (Thread.CurrentUICulture
)
Update
Specify the correct culture in the beginning of each request (in your base controller)
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var cultureId = ((YourUserObj)Session["CurrentUser"]).PreferedLanguage;
var userCulture = new CultureInfo(cultureId);
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = userCulture;
}
Then let .NET load the correct resource files.
来源:https://stackoverflow.com/questions/7629612/localisation-on-a-saas-application