views:

196

answers:

2

How can I localize/internationalize attribute values in .NET?

My specific example is for ASP.NET web parts such as WebDisplayName, WebDescription, etc. where I inherit from the base class that uses these attributes.

Also, is there any difference to doing this with attributes declared in my own classes?

Thanks!

+2  A: 

Have you had a look at Localizing the Property Grid?

This seems pretty much the same thing, except you're inheriting from WebDescriptionAttribute (et al) instead of DescriptionAttribute. All of the important properties in the Web classes, like Description, are still overridable.

The example on that page calls out to a static SR class, which retrieves string resources from a specific type. If you need to support multiple languages at the same time - and obviously take a minor performance hit in the process - then you would have to adjust the attribute itself to take the Type of the resource you expect, and use the appropriate constructor for the ResourceManager class.

I can go into more detail if you want to expand a little on the intended uses.

Aaronaught
+1  A: 

Check out this answer:

http://stackoverflow.com/questions/356464/localization-of-displaynameattribute/357008#357008

You would have to add attributes to your derived classes to override the ones on the base classes.

bbudge