views:

543

answers:

1

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 dropdown 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?

A: 

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

Tom S.
That works great, thanks.Still fighting with the GetLocalResourceObject() because the first parameter is the "virtualPath" and I can't seem to get it right.
Farinha