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!
Best Answer
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 ofDescriptionAttribute
. All of the important properties in theWeb
classes, likeDescription
, 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 theType
of the resource you expect, and use the appropriate constructor for theResourceManager
class.I can go into more detail if you want to expand a little on the intended uses.