zoukankan      html  css  js  c++  java
  • sharepoint2010如何本地化WebPart的Category、WebDisplayName 和 WebDescription 属性

    在项目中经常需要实现多语言其中包括webpart的属性也需要。那么如何实现呢?

    首先需要资源文件,利用资源文件实现语言的翻译,如下图:

    image

    创建好资源后,下面我们来实现webpart属性的多语言。方法代码如下:

       1: using System;
       2: using System.Collections.Generic;
       3: using System.Text;
       4: using System.Globalization;
       5: using System.Web;
       6: using System.Web.UI.WebControls.WebParts;
       7: using System.ComponentModel;
       8: //****************************************************************
       9: //编制人:XX
      10: //编制作用:本地化WebPart的Category、WebDisplayName 和 WebDescription 属性
      11: //编制时间:2013-05-07
      12: //编制单位:XX
      13: //****************************************************************
      14: namespace TCL.EP.SPCommon
      15: {
      16:     #region//WebPart类别本地化
      17:     public sealed class LocalizedCategoryAttribute : CategoryAttribute
      18:     {
      19:         public LocalizedCategoryAttribute(string category)
      20:             : base(category)
      21:         { }
      22:  
      23:         // Override this method to return values from the webpart's resource file.
      24:         protected override string GetLocalizedString(string value)
      25:         {
      26:             return LocalizedUtility.GetLocalizedString(value, CultureInfo.CurrentUICulture.LCID);
      27:         }
      28:     }
      29:     #endregion
      30:  
      31:     #region//WebPart显示名称本地化
      32:     public sealed class LocalizedWebDisplayNameAttribute : WebDisplayNameAttribute
      33:     {
      34:         bool m_isLocalized;
      35:  
      36:         public LocalizedWebDisplayNameAttribute(string displayName)
      37:             : base(displayName)
      38:         { }
      39:  
      40:         // Override this property to return values from the webpart's resource file.
      41:         public override string DisplayName
      42:         {
      43:             get
      44:             {
      45:                 if (!m_isLocalized)
      46:                 {
      47:                     this.DisplayNameValue = LocalizedUtility.GetLocalizedString(base.DisplayName, CultureInfo.CurrentUICulture.LCID);
      48:                     m_isLocalized = true;
      49:                 }
      50:                 return base.DisplayName;
      51:             }
      52:         }
      53:     }
      54:     #endregion
      55:  
      56:     #region//WebPart描述本地化
      57:     public sealed class LocalizedWebDescriptionAttribute : WebDescriptionAttribute
      58:     {
      59:         bool m_isLocalized;
      60:  
      61:         public LocalizedWebDescriptionAttribute(string description)
      62:             : base(description)
      63:         { }
      64:  
      65:         // Override this property to return values from the webpart's resource file.
      66:         public override string Description
      67:         {
      68:             get
      69:             {
      70:                 if (!m_isLocalized)
      71:                 {
      72:                     this.DescriptionValue = LocalizedUtility.GetLocalizedString(base.Description, CultureInfo.CurrentUICulture.LCID);
      73:                     m_isLocalized = true;
      74:                 }
      75:                 return base.Description;
      76:             }
      77:         }
      78:     }
      79:     #endregion
      80: }

    调用例子如下:

     

       1: /// <summary>
       2:       /// 图片打开的URL
       3:       /// </summary>
       4:       [WebBrowsable(true)]
       5:       [LocalizedWebDisplayName("TCL.WebPartAttribute.PhotoImageUrl")]
       6:       [LocalizedWebDescription("TCL.WebPartAttribute.PhotoImageUrl")]
       7:       [Personalizable(PersonalizationScope.Shared)]
       8:       [LocalizedCategory("TCL.WebPartAttribute.SelfName")]
       9:       public string PhotoImageUrl { get; set; }
  • 相关阅读:
    代码重构技术方法
    《算法导论》为什么经典
    BeagleBone Black教训四局:简单LED对照实验
    linux(Ubuntu)安装QQ2013
    ubuntu卸载qq2012
    android弧形进度条,有详细注释的,比较简单
    Android自定义进度条
    AndroidのUI设计研究(一)——自定义ProgressBar
    介绍几个工作开发中封装的好用的android自定义控件
    android自定义viewgroup之我也玩瀑布流
  • 原文地址:https://www.cnblogs.com/love007/p/3294428.html
Copyright © 2011-2022 走看看