Learn how to re-create missing multilanguage links for all translation languages used in your SitePages library in SharePoint Online using PnP.PowerShell.
Maybe you’ve also stumbled upon the issue of missing multilanguage links in your SitePages library in SharePoint Online. This can happen if you create translations in an unsaved default language Post / News Article.
Since the Column Translation languages (_SPTranslatedLanguages) is read-only, you can’t simply add the missing language tags to the existing pages. Instead, you need for example PowerShell to re-create the entries for each page.
This is where my new PowerShell script comes into play. It helps you to re-create all missing multilanguage links in your SitePages library by checking if the existing translations are correctly linked to the default language page.
If not, it updates the _SPTranslatedLanguages field accordingly.
Retrieve all folders from the SitePages library where the folder name contains exactly two letters. This “trick” I use to identify the language folders. So if you have also other folders in your SitePages library, with only two letters, you should adjust the script.
For each translated page, we now have to retrieve the corresponding default language page (in the root directory).
Then we need to check if the column _SPTranslatedLanguages already contains this language.
If not, we add it to the _SPTranslatedLanguages field. We use the SystemUpdate method to update the field without changing the modified date. If you want / have to to update the modified date, you can remove the -UpdateType.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
foreach($Pagein$Pages){# Retrieve the default page in the root directory$DefaultPage=Get-PnPListItem-List'SitePages'-Query"<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>$($Page.FieldValues.FileLeafRef)</Value></Eq></Where></Query></View>"# Check if the default page exists and if the translation language is already linkedif($DefaultPage){if($DefaultPage.FieldValues._SPTranslatedLanguages-cnotcontains$Page.FieldValues._SPTranslationLanguage){$OldLanguages=$DefaultPage.FieldValues._SPTranslatedLanguages$NewLanguages=$OldLanguages+$Page.FieldValues._SPTranslationLanguageSet-PnPListItem-List'SitePages'-Identity$DefaultPage.Id-Values@{'_SPTranslatedLanguages'=$NewLanguages}-UpdateTypeSystemUpdate}}}}
$TenantName='yourtenantname'$SiteName='YourSiteName'Connect-PnPOnline-Url"https://$($TenantName).sharepoint.com/sites/$SiteName"-interactive$LanguageFolders=Get-PnPFolderInFolder-Identity'SitePages'|Where-Object{$_.Name-match'^[a-z]{2}$'}foreach($LanguageFolderin$LanguageFolders){$Pages=Get-PnPListItem-List'SitePages'-FolderServerRelativeUrl"/sites/$SiteName/SitePages/$($LanguageFolder.Name)"foreach($Pagein$Pages){# Retrieve the default page in the root directory$DefaultPage=Get-PnPListItem-List'SitePages'-Query"<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>$($Page.FieldValues.FileLeafRef)</Value></Eq></Where></Query></View>"# Check if the default page exists and if the translation language is already linkedif($DefaultPage){if($DefaultPage.FieldValues._SPTranslatedLanguages-cnotcontains$Page.FieldValues._SPTranslationLanguage){$OldLanguages=$DefaultPage.FieldValues._SPTranslatedLanguages$NewLanguages=$OldLanguages+$Page.FieldValues._SPTranslationLanguageSet-PnPListItem-List'SitePages'-Identity$DefaultPage.Id-Values@{'_SPTranslatedLanguages'=$NewLanguages}-UpdateTypeSystemUpdate}}}}Disconnect-PnPOnline
I hope this script helps you to re-create the missing multilanguage links in your SitePages library. If you have any questions or feedback, feel free to leave a comment below.
Comments
You can use your Bluesky account to
reply
to this post. Learn how this is implemented
here.