Reputation: 83
I'm working on some SharePoint web parts and I'm trying to make them as locale-independent as possible. I've got all most text in resource files, and I'm looking at the attributes on my Web Part:
[WebBrowsable(true),
Category("My Category"),
WebDisplayName("Display Name here"),
WebDescription("Tells you all about it"),
Personalizable(PersonalizationScope.Shared)]
public string SomeProperty { get; set; }
It would be nice to replace those hard-coded strings with something more useful to users (SharePoint administrators in this case) who don't use English.
What are my options, if any?
Upvotes: 1
Views: 1202
Reputation:
You can just create subclasses from the normal ASP.NET attributes and localize those. THis approach is legacy and should not be used for your new web parts. Do not derive from the SP Web Part when there is no need.
http://forums.asp.net/t/937207.aspx
Upvotes: 1
Reputation: 83
Here's my implementation of spoon16's answer:
[WebBrowsable(true),
Resources("SearchWebPartWebDisplayName",
"SearchWebPartCategory",
"SearchWebPartWebDescription"),
FriendlyName("Display Name here"),
Description("Tells you all about it"),
Category("My Category"),
Personalizable(PersonalizationScope.Shared)]
public string SomeProperty { get; set; }
public override string LoadResource(string id)
{
string result = Properties.Resources.ResourceManager.GetString(id);
return result;
}
Note the change of property names and their order in the attributes block.
I also had to change my WebPart to derive from Microsoft.SharePoint.WebPartPages.WebPart, with the attendant changes to how I handle the Width and Height of my WebPart.
Upvotes: 1
Reputation: 48412
You are looking for the Microsoft.SharePoint.WebPartPages.ResourcesAttribute
class.
This blog post has a description of it's use and a simple example.
//RESOURCES LOCALIZATION
//Property that is localized. Use the ResourceAttibute.
//[ResourcesAttribute (PropertyNameID=1, CategoryID=2, DescriptionID=3)]
[Resources("PropNameResID", "PropCategoryResID", "PropDescriptionResID")]
Upvotes: 2