Localisation on a SAAS application

↘锁芯ラ 提交于 2020-01-16 01:04:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!