SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Archive

Kategorien

Links

Andere Blogs




ITaCS GmbH


HowTo use the resource files from SharePoint  

Oct 282007

How about using the available resources from SharePoint to translate some basic words and sentences? Well, it is quite easy to use the available resources. You need the Microsoft.SharePoint.Intl.dll and some lines of code to use the already translated resources:

   1: // define yourself variables
   2: private readonly CultureInfo _Cult;
   3: private readonly Assembly _SharePoint_Intl_Assembly;
   4: private readonly ResourceManager _SharePoint_RM;
   5: private readonly ResourceManager _SharePoint_WebPartPage_RM;
   6:  
   7: // initialize them in your constructor
   8: _SharePoint_Intl_Assembly = Assembly.Load("Microsoft.SharePoint.intl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
   9: _SharePoint_RM = new ResourceManager("Microsoft.SharePoint", _SharePoint_Intl_Assembly);
  10: _SharePoint_WebPartPage_RM = new ResourceManager("Microsoft.SharePoint.WebPartPages.strings", _SharePoint_Intl_Assembly);
  11:  
  12: // get the current culture
  13: internal static CultureInfo GetCultureInfo()
  14: {
  15:     CultureInfo newCultureInfo;
  16:     try
  17:     {
  18:         uint localeID = SPContext.Current.RegionalSettings.LocaleId;
  19:         newCultureInfo = new CultureInfo((int)localeID);
  20:     }
  21:     catch
  22:     {
  23:         newCultureInfo = new CultureInfo(1033);
  24:     }
  25:  
  26:     return newCultureInfo;
  27: }
  28:  
  29: // use the resources
  30: string test = _SharePoint_RM.GetString("ExpireDateInPast", _Cult);
  31: // will result in 'The Expire date is in the past.'

 

But how do you know how the resource name for your translated text might be? Your friend and helper is the Reflector. Open up the 'Microsoft.SharePoint.Intl.dll' from the 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint.intl\12.0.0.0__71e9bce111e9429__71e9bce111e9429c' folder (navigate to that path with cmd.exe and copy the dll to some safe place like c:\temp).

A big thanks goes to Janne Mattila for the information in the comment for this blog entry.

 
Posted by René Hézser | 0  Comments | Trackback Url  | 1  Links to this post | Bookmark this post with:        
Tags: Development, Reporting Services
Technorati Tags: ,

Links to this post

Comments

Name *:
URL:
Email:
Kommentar:


CAPTCHA Image Validation