Β· 2 min read
How to enable Alternate Languages for all subwebs programmatically
Hi guys! Sometimes happened that we need to enable Alternate Language on already existing websites, maybe after a language pack installation or just simply after an Information Architecture creation.
You can do it manually from Site Settings page
/_layouts/15/regionalsetng.aspx
But, what happened if you have a lot of sites and nested websites? Here you can find a short snippet could you help you
function EnableAlternateLanguageForAllSubWebs($web) {
Write-Host "Enable alternate language started $web" -ForegroundColor Green Write-Progress -Activity "setting alternate language " -Status "Enable alternate language is starting" try{
$spWeb = Get-SPWeb $web if($spWeb -ne $null) {
$installed = [Microsoft.SharePoint.SPRegionalSettings]::GlobalInstalledLanguages #region set language in sitecollection-root $spWeb.IsMultiLingual = $true;
$supportedCultures = $spWeb.SupportedUICultures;
foreach ($lang in $installed) {
$cultureinfo = [System.Globalization.CultureInfo]::GetCultureInfo($lang.LCID);
$exists = $supportedCultures | Where-Object{
$_.LCID -eq $lang.LCID
}
if ($exists -eq $null) {
$spWeb.AddSupportedUICulture($cultureinfo) Write-Host "Added" $cultureinfo.Name "to URL" $spWeb.Url
}
}
$spWeb.Update() #endregion $subwebs = $spWeb.GetSubwebsForCurrentUser() #region set language in subWebs of sitecollection-root foreach($subweb in $subwebs) {
$subweb.IsMultiLingual = $true;
$supportedCultures = $subweb.SupportedUICultures;
foreach ($lang in $installed) {
$cultureinfo = [System.Globalization.CultureInfo]::GetCultureInfo($lang.LCID);
$exists = $supportedCultures | Where-Object{
$_.LCID -eq $lang.LCID
}
if ($exists -eq $null) {
$subweb.AddSupportedUICulture($cultureinfo) Write-Host "Added" $cultureinfo.Name "to URL" $subweb.Url
}
}
#set language in news subsites $subSubwebs = $subweb.GetSubwebsForCurrentUser() foreach($subSubweb in $subSubwebs) {
$subSubweb.IsMultiLingual = $true;
$SWsupportedCultures = $subSubweb.SupportedUICultures;
foreach ($lang in $installed) {
$SWcultureinfo = [System.Globalization.CultureInfo]::GetCultureInfo($lang.LCID);
$SWexists = $SWsupportedCultures | Where-Object{
$_.LCID -eq $lang.LCID
}
if ($SWexists -eq $null) {
$subSubweb.AddSupportedUICulture($SWcultureinfo) Write-Host "Added" $SWcultureinfo.Name "to URL" $subSubweb.Url
}
}
$subSubweb.Update()
}
$subweb.Update()
}
#endregion Write-Host "Enable alternate language finished $web" -ForegroundColor Green Write-Progress -Activity "setting alternate language" -Status "Enable alternate language is finished"
}
}
catch [System.Exception] {
throw $_.Exception;
}
}
Β
You can run it using SharePoint Powershell or importing SharePoint PS Snapin (donβt forget it)
# All scripts need to initiate SharePoint Snapin if not done
$spInstalled = Get-PSSnapin | Select-String Sharepoint
if (!$spInstalled)
{
Add-PSSnapin Microsoft.Sharepoint.PowerShell
}
Β
Have a nice day ;)
Note: C# code for adding alternate language support is illustrated in the MSDN in article: Understandingthe Multilingual User Interface here.