首页 技术 正文
技术 2022年11月8日
0 收藏 771 点赞 1,930 浏览 2414 个字

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

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

sharepoint2010如何本地化WebPart的Category、WebDisplayName 和 WebDescription 属性

创建好资源后,下面我们来实现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; }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848