Welcome to MSDN Blogs Sign in | Join | Help

Localization in WebParts

Microsoft Sharepoint Portal Server doesn't have support of localization in multiple

Languages natively. The document at

http://www.microsoft.com/technet/prodtechnol/office/sps2003/maintain/spsinatl.mspx#E5F

 

Discusses this situation. It is clearly mentioned that

SharePoint Portal Server 2003 does not support a mixture of different localized portal servers on the server farm, nor does it support a mixture of different localized Windows Server 2003 servers. All servers running Windows Server 2003 in a farm topology must be in the same language, and all servers running SharePoint Portal Server 2003 in a server farm must be in the same language

 

Still, if you want to perform localization in webparts for whatever reasons, it is simple to do so.

We will create a simple MOSS 2007 webpart with localization support.

 

  • Create a simple class library project and reference to the sharepoint namespace.
  • Create a template of webpart
  • Now we will add a resource file to the project. Choose Add New file from the project menu
    And add a resource file for each of the languages. For example

Healthcare.resx

Healthcare.de.resx for German

Healthcare.fr.resx for French

 

Note that you cannot add App_GlobalResources to the project since it is only valid for the web sites

And not the class library projects.

 

  • Add the following reference to your webpart source file
    using System.Configuration;

using System.Globalization;

using System.Resources;

 

We will pick the language settings from the web.config file. Add the following tag to the

<appsettings> section of the web.config file of your sharepoint web site.

<add key=culture value="de-DE">

 

Add the following class variables to your webpart source file.

CultureInfo cult =  CultureInfo.CreateSpecificCulture(ConfigurationSettings.AppSettings["culture"]);

ResourceManager rm;

 

This will create a CultureInfo object based on the language settings in the web.config file.

 

In the constructor of your webpart add a line like this

rm = new ResourceManager("CustomWebParts.HealthCare", this.GetType().Assembly);

 

Where HealthCare is the name of your resource file ex HealthCare.resx and HealthCare.de.resx

And CustomWebParts is the namespace of your webpart.

 

Basically this line creates a resource manager for the specific resource file.

 

Now we will load all the strings which are used in the webpart source to the resource file.

This is fairly easy.

 

Now to load strings at any point in the webpart source we will use the GetString() method of

ResourceManager class. For Ex

 

protected override void CreateChildControls()

        {

            base.CreateChildControls();

            this.Title = rm.GetString("CarePlan", cult);

        }

 

This method sets the title of the webpart to the appropriate language based on the web.config file

 

The above localization is not specific to sharepoint instead it's an asp.net 2.0 feature.

I can mail the source code of the webpart to anyone if needed.

 

Send your suggestions and comments.

Published Monday, March 31, 2008 5:21 PM by Madhur

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# SharePoint 2007 Link Love: 03-06-2008 at Virtual Generations

# re: Localization in WebParts

pleaes can you send me source code

my email is

dream_177_33@yahoo.com

Thursday, July 24, 2008 5:12 AM by Shimaaa

# re: Localization in WebParts

Please send your source code to me!

My email is lingmu0108@hotmail.com

Thanks in advance!

---------------------------

Forest Ling

Tuesday, July 29, 2008 12:31 AM by Forest Ling

# re: Localization in WebParts

can u send me the code to sammeta.nsprasad@gmail.com

Thursday, February 19, 2009 6:04 AM by shivaprasad

# re: Localization in WebParts

pleaes can you send me source code

my email is

rajesh_singh81@rediffmail.com

Thursday, March 05, 2009 3:22 AM by Rajesh Kumar Singh

# re: Localization in WebParts

Can u please send me the entire source code to my mail ID i.e. urukundappa.g@mphasis.com

Tuesday, March 31, 2009 5:58 AM by urukundappa.g@mphasis.com

# re: Localization in WebParts

can u send me the source code

my email id is naveensingh222@gmail.com

Monday, April 27, 2009 6:48 AM by naveen singh

# re: Localization in WebParts

can you send me source code

my email is

garg_nirmit@yahoo.co.in

Monday, May 11, 2009 8:35 AM by Nirmit

# re: Localization in WebParts

Dear Friend,

Is it possible to implement a controll, to change language MOSS language.

In back end it should load a resource files based on choosen language.

Thank in advance (we are ready to pay for this solution)

Tuesday, November 03, 2009 10:12 AM by Habib

# re: Localization in WebParts

Will this code work for Sharepoint 2003 as well? I am trying to make my custom webpart read the value from appsettings of the web.config.

Thanks

edwin.mendoza@bmo.com

Monday, November 09, 2009 1:20 PM by edwin

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker