Hi friends.
If you ever find yourself wanting to enable a particular language or set of languages on a site Collection and all subsites, and if you do NOT want to enable all languages installed but rather Control what gets enabled? Here is a scripot that will help you.
In my own scenario I had 4 site Collections, each tageted for a different nordic country, Sweden, Norway, Finland and Denmark. So, the need is to have enabled English for all and only the countrys language for the 4 site Collections.
Looking for an existing sample code to use, I found many that were copies of the MSDN sample, this is a good piece of code but it enables all languages installed.
So, trying to find a clever way of selecting what language got enabled, I found an old script I created for the same customer, the solution was so simple it works!
While iterating thru all the installed languages, site by site, I check the displayname of the Language and add criteria fro the languages to install. Beautifully simple 🙂
There is Little difference between this and the MSDN sample code, but is was an important difference to me.
This is what I used in the end:
# Enables SELECTED installed languages for each subsite in a site collection $spSiteURL = http://sharepoint.balkestahl.se/sites/subsitecountry $spSite = Get-SPSite -Identity $spSiteURL foreach ($spWeb in $spSite.AllWebs) { $spWeb.IsMultilingual = $true $WebRegionSettings = New-Object Microsoft.SharePoint.SPRegionalSettings($spWeb) foreach ($language in $WebRegionSettings.InstalledLanguages) { If ($language.DisplayName -eq "English" -or $language.DisplayName -eq "Swedish") # Add the displayname of any langauge you have installed: -or $language.DisplayName -eq "Norwegian" -or $language.DisplayName -eq "Finnish" -or $language.DisplayName -eq "Danish" { write-host -BackgroundColor Green -ForegroundColor Black "Update -" $spWeb "site with LCID:" $language.DisplayName $culture = New-Object System.Globalization.CultureInfo($language.LCID) $spWeb.AddSupportedUICulture($Culture) } else { Write-host " Language not activated: " $language.DisplayName " on site " $spWeb.Name } } $spWeb.Update() }
This saved me hours and hours…or made it possible 🙂
The running of the script looks something like this, in my case around 3000 times for the Swedish collection, all in all, 50.000 subsites!):
Before running the script, in each site, you have these settings:
(Accessed under: Site Settings/Language Settings, path: /_layouts/muisetng.aspx)
And what we want to do, is check the box for the selected language(s) and move on to the next.
When adding the criteria to the If statement, use the displaynames exactly like in the list in Site Settings/Language Settings:
This script saved me, I hope it can do the same for some of you.
_________________________________________________________
Enjoy!
Regards