开发者

Override culture when using GetGlobalResourceObject or GetLocalResourceObject in ASP.NET

I've implemented localization in this ASP.NET project using resource files and that's working as expected. But there is one situation where I have to display the whole page in one language and then a section of it in some other language based on the selection from a dropdo开发者_StackOverflow社区wn list.

From what I can see, the GetGlobalResourceObject() and GetLocalResourceObject() methods work from the page culture, but I need to adjust the language programmatically. Is there a way to override those methods' behaviour so that I can specify the language?


I believe you can access a specific resx file by using this method:

   value = HttpContext.GetGlobalResourceObject(classKey, resourceKey, culture)

You can initialize your culture like this:

Culture culture = CultureInfo.CreateSpecificCulture("pt-PT");

Just pick up your value from the dropdown and switch the culture in the CreateSpecificCulture method.

I havent tested it, let me know if that doesnt work.

EDIT: its the same for GetLocalResourceObject

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜