How do I update automatically the alternate site languages via PowerShell?

In one of the SharePoint development projects that I am following we are working with multilingual sites in a SharePoint 2010 Foundation environment. As you probably already know, SharePoint 2010 allows to install language packs to provide the UI in different languages. If you want to enable multilingual UI on your site, you have to do this in SharePoint 2010 Foundation by changing these settings under Site-Settings –> Languages of every Team site.

Therefore, I wanted to write a PowerShell script that automates this manual process.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$siteUrl = "http://foundation"
$uiCulture = 1040;

$rootSite = Get-SPSite $siteUrl
$allWebs = $rootSite.AllWebs

foreach ($web in $allWebs) {
  Write-Host "Updating " + $web.Title + " " + $web.Url
  if ($web.IsMultilingual -eq $false) {
    $web.IsMultilingual = $true;
  }
    
  $web.AddSupportedUICulture($uiCulture);
  $web.Update()
}

The script above simply loops through the site collection defined in “$siteUrl” and loops through all sub-sites. It enables Multilanguage support if it was not already done and assigns by using the “AddSupportedUICulture” method the desired language.

This script works only if you have some language packs installed in your environment. The 1040 UI code defined in “$uiCulture” stands for the Italian language. Every language has its own unique identifier. Find here more information about localization in ASP.NET applications.

Use the script in a testing/dev environment before executing it somewhere else

 

Hope this helps,

Patrick

This entry was posted in Developers by Patrick Lamber. Bookmark the permalink.
Patrick Lamber

About Patrick Lamber

Patrick Lamber is a long-standing .NET Developer and has offered SharePoint consulting, development, and training services to customers since the launch of SharePoint 2007. He is a both a Microsoft Certified Trainer and a Microsoft Certified IT Professional, and holds Microsoft Certified Professional Development certifications for SharePoint. Patrick founded NUBO with the aim of developing a team of specialized SharePoint professionals delivering great solutions. Furthermore, in his role as SharePoint Competence Manager Patrick is also responsible for building up the SharePoint team for the company Blu Systems GmbH in Munich. Patrick speaks three languages (German, Italian, and English), meaning most of his work is focused on Italy, Germany, Austria, and Switzerland.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by Sweet Captcha
Verify your real existence,
Drag the glass to make a toast
  • captcha
  • captcha
  • captcha
  • captcha