Reputation: 60047
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!
Upvotes: 2
Views: 731
Reputation: 1137
Check out this answer:
Localization of DisplayNameAttribute
You would have to add attributes to your derived classes to override the ones on the base classes.
Upvotes: 1
Reputation: 122664
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.
Upvotes: 3