Available Languages in SharePoint Programmatically

Today I was searching for a way to retrieve the installed language packs in the SharePoint farm programmatically, and I was not able to find any good resources about the way to do it programmatically, most of the blogs are talking about browsing the directories of the installed language and listing them based on the LCID of each language, or doing the same technique with the SharePoint Windows Registry entries.

The need of such functionality arise when you are developing a global solution that must deal with Multi-Languages SharePoint environment, such as a friendly user interface for creating site collections, or when you need to check if your SharePoint artifact is compatible with the installed language packs.

For more details about the instructions of language packs deployment check the following:

SharePoint Foundation 2010 Language Packs Deployment

SharePoint Server 2010 Language Packs Deployment

SharePoint Server 2010 Supported Languages

When you install any language pack, the installer will create a folder named with the Locale ID (LCID) number inside the folder %COMMONPROGRAMFILES%\Microsoft Shared\Web server extensions\14\template\ such as 1033 for the English language

image

It will also add the installed language information entries to the registry under the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\InstalledLanguages

image

For the complete list of Languages IDs Click Here.

Here is a simple console application that list the installed languages:

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Linq;
   4:  using System.Text;
   5:  using Microsoft.SharePoint;
   6:  using Microsoft.SharePoint.Administration;
   7:   
   8:  namespace SPLanguagesDemo
   9:  {
  10:  class Program
  11:  {
  12:  static void Main(string[] args)
  13:  {
  14:      SPFarm thisFarm = SPFarm.Local;
  15:      if (thisFarm != null)
  16:      {
  17:          SPLanguageCollection installedLanguages = 
  18:              SPRegionalSettings.GlobalInstalledLanguages;
  19:          Console.WriteLine("SharePoint Farm Name: {0}", 
  20:              thisFarm.DisplayName);
  21:          Console.WriteLine("{0} Installed Languages", 
  22:              installedLanguages.Count.ToString());
  23:          Console.WriteLine("Installed Languages:");
  24:          foreach (SPLanguage lang in installedLanguages)
  25:          {
  26:              Console.WriteLine("Language: {0}\nLanguage ID: {1}\n",
  27:                  lang.DisplayName, lang.LCID.ToString());
  28:          }
  29:          Console.ReadLine();
  30:      }
  31:  }
  32:  }
  33:  }

Just don’t forget to add Microsoft.SharePoint.DLL as an assembly reference to the project.

One Response to Available Languages in SharePoint Programmatically

  1. Chris says:

    That’s what I’m looking for
    Thanks!
    Chris

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: