2009-07-03 42 views
1

我正在處理一些SharePoint Web部件,並試圖儘可能使它們作爲區域獨立。我有在資源文件中的所有最文字,我看我的Web部件的屬性:國際化和C#方法屬性?

[WebBrowsable(true), 
Category("My Category"), 
WebDisplayName("Display Name here"), 
WebDescription("Tells you all about it"), 
Personalizable(PersonalizationScope.Shared)] 
public string SomeProperty { get; set; } 

這將是很好,以取代用戶更有用的東西硬編碼的字符串(的SharePoint這種情況下的管理員)誰不使用英語。

我有什麼選擇,如果有的話?

回答

2

您在尋找Microsoft.SharePoint.WebPartPages.ResourcesAttribute的分類。

This blog post有一個它的使用和一個簡單的例子的描述。

//RESOURCES LOCALIZATION 
//Property that is localized. Use the ResourceAttibute. 
//[ResourcesAttribute (PropertyNameID=1, CategoryID=2, DescriptionID=3)] 
[Resources("PropNameResID", "PropCategoryResID", "PropDescriptionResID")] 
+0

非常感謝 - 我實現你的答案如下。 – user132710 2009-07-03 10:57:46

1

這是我實現spoon16的回答:

[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; 
    } 

注屬性名稱的變化,它們在屬性塊順序。

我還必須更改我的WebPart,以便從Microsoft.SharePoint.WebPartPages.WebPart派生出來,其中伴隨着如何處理WebPart寬度和高度的更改。

1

您可以從普通的ASP.NET屬性中創建子類並對其進行本地化。這種方法是遺留的,不應該用於新的Web部件。當不需要時,不要從SP Web部件派生。

http://forums.asp.net/t/937207.aspx

+0

注意。謝謝Wouter! – user132710 2009-09-10 11:45:14