Wednesday, 28 August 2013

ASP.NET MVC 4 switch resource file via url parameter

ASP.NET MVC 4 switch resource file via url parameter

I am new at working with resource files and I haven't quite got how it
works yet. Now I need to have my application's text available in English
and in Chinese. I will receive a get parameter (e.g. lang) and from there
I will need to decide whether to use Language.zh.resx or my default
Language.resx - That's what I understood from articles that I have been
reading. Now I have my View Title for example:
@{
ViewBag.Title =
MyApplication.App_GlobalResources.Language.MyPage_Title;
}
I can't figure out where to check the parameter lang and apply it. I saw
articles where people say I should create an action filter and they add
stuff to cookies and they were confusing. In my case it might not be
necessary as it just has one request, there is no requirement for
preserving the state as once the page is loaded that's it.
If someone could also give some brief explanation of how resources work
that would be nice, thanks!

No comments:

Post a Comment