Why does using the PnP.PowerShell cmdlet Enable-PnPFeature to enable multilingual support add all languages on a SharePoint site?

267 views Asked by At

So this is driving me crazy! Please help :)

I'm using the PnP.PowerShell module to enable multi-lingual support on a SharePoint Online site. I'm taking the following steps.

  1. Create a communication site through the SharePoint admin centre
  2. Run the following PowerShell script:
$SiteURL = 'https://tenant.sharepoint.com/sites/test'
$SiteConnection = Connect-PnPOnline -Url $SiteURL -Interactive
Enable-PnPFeature -Identity 24611c05-ee19-45da-955f-6602264abaf8 -Connection $SiteConnection -Scope Web

This toggles the 'Enable translation into multiple languages' setting at the following URL 'https://tenant.sharepoint.com/sites/test/_layouts/15/muisetng.aspx' which is great and exactly what I want. However, it also enables every site language. I only want to enable a couple of languages.

Has anyone else tried the above? Not sure why this is happening.

I'm using PnP.PowerShell version 2.2.0

2

There are 2 answers

0
dev123 On BEST ANSWER

Not sure why but the following continues to enable all languages.

Enable-PnPFeature -Identity 24611c05-ee19-45da-955f-6602264abaf8 -Connection $SiteConnection -Scope Web

So I've just implemented a workaround to loop through all the added languages and if the language is not in the array of languages I need, then I remove it.

My script has been extensively used, and has been working fine with no issues.

1
Martin Laplante On

The Multilingual Page Publishing feature does not enable or disable alternate site languages. By default, Communication sites are created with all 50 languages enabled. Some other site types have no alternate languages enabled. When you add the feature using the "Enable translation into multiple languages" slider, it is not just adding the feature, it is actually deleting all the alternate languages, as you can see by clicking on "show advanced settings" before and after you enable it. You must add and delete the alternate languages that you want using Web.AddSupportedUILanguage or Web.RemoveSupportedUILanguage, for example:

#Set variables
$SiteURL = "https://mytenant.sharepoint.com/sites/mysite"
$LanguageID = 1036 #French
 
#Get the web
Connect-PnPOnline -Url $SiteURL -Interactive
$Web = Get-PnPWeb
 
#Add Alternate Language
$Web.AddSupportedUILanguage($LanguageID)
$Web.Update()
Invoke-PnPQuery