Home > SharePoint > SharePoint Localization, Multi Lingual Messages using Resource files.

SharePoint Localization, Multi Lingual Messages using Resource files.

SharePoint is complete portal which covers all the basic and extensive needs for business, it’s one of the best content management tool of the era. One of its amazing functionality is SharePoint’s localization.

Let’s start with creating new sample project in VS2008.

1. Sample WSP Project named as Localization is created, I am using WSP Builder Extension provided by Microsoft for SharePoint development. Into it Resource folder is created which will contain clip_image002[4]resource files used for this project, and when it will be deployed they will be added into Resource folder of 12 hives.

2. Adding Resource file into Resource folder created. Two resource files have been added and for them Name and value have also been added to them, Names of resource files are Resource_EN and Resource_AR.

clip_image002[6]

3. Name column of resource files should comprise similar values in all resource files and Value column would be changed as per language.

clip_image002[8]

clip_image004[4]

clip_image006[4]

4. Sample web part has been created which would just display the text “This is an example of localization”.

5. If site is in English then message would be in English, if site is in Arabic then message would be in Arabic.

6. Code to get the current culture and resource file is as follow.

protected override void CreateChildControls()
{
if (!_error)
     {
   try
        {
             base.CreateChildControls();
           //Getting the current culture [Locale ID].
            int intLCID = System.Threading.Thread.CurrentThread.CurrentUICulture.LCID;

Label lblWelcomeText = new Label();

//General_Text is the name of value which is similar in both resource files

//Calling function getLocalizedValue()

lblWelcomeText.Text = getLocalizedValue(“General_Text”, intLCID);

this.Controls.Add(lblWelcomeText);

}
catch (Exception ex)
{
HandleException(ex);

}

}

}

public string getLocalizedValue(string strInput, int intLCID)

{
// Function to retreive specified Language Variation Value

string strLocalizedValue = “”;
if (intLCID == 1033) { // Locale for English.

LocalizedValue = Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString(“$Resources: ” + strInput, “Resource_EN”, (uint)intLCID);

}

else if (intLCID == 1025) // Locale for Arabic.
{

strLocalizedValue = Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString(“$Resources: ” + strInput, “Resource_AR”, (uint)intLCID);

}
return strLocalizedValue;
}

Note: – I have Arabic and English language packs installed in my machine, that’s why representing their locales. This blog helped me a lot to perform this localization work.

English – Locale 1033
clip_image012

Arabic – Locale 1025
clip_image014

Hope this would help you too, Stay blessed.

Advertisements
  1. Muhammad Abbas
    June 21, 2011 at 12:14 pm

    Nice post Kazim…keep it up i like it.

  2. June 21, 2011 at 1:28 pm

    Nice Article, great as u have it with the screen shots. But i have few questions,
    – In SharePoint we have our own Language code folders like we have 1033 for english in our 12 hive, isn’t it better to use specific folders?
    – In what manner ts better to use resourse files instead of using SharePoint language packs?

    Any way good example for a multilingual website (Y) 🙂

    • June 21, 2011 at 9:45 pm

      Hi Shoaib , Thank you so much for writing.
      As per my knowledge 1033 folder is its locale folder , which is for english , but resource files which are used by SharePoint itself are into Resources folder in hive. purpose to create that folder is to place our custom resource files into the same folder after deployment.
      My project requirement enforces me to do so , as i would be using custom strings into that , Language packs are applicable to translabe SharePoint specific strings , controls , Like SPGridView default messages would be automatically translated into the language as per culture.

      Hope i make my self clear on that.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: