Re-creating Multilanguage Links: A Step-by-Step Guide

A How-to guide to re-creating multilanguage links for Pages in your SitePages library.

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.

Prerequisites

  • You need to have the PnP.PowerShell module installed.
  • You need the necessary permissions to run the script.

Step-by-Step Documentation

1. Set Up Variables

  • TenantName: Use your tenant name.
  • SiteName: Define the name of the site collection to be flagged as a Corporate News Site.
1 $TenantName = 'yourtenantname'
2 $SiteName = 'YourSiteName'

2. Connect to SharePoint Online

  • Use PnP-PowerShell to connect to the SharePoint Online site.
1 Connect-PnPOnline -Url "https://$($TenantName).sharepoint.com/sites/$SiteName" -interactive

3. Retrieve Language Folders

  • 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.
1 $LanguageFolders = Get-PnPFolderInFolder -Identity 'SitePages' | Where-Object { $_.Name -match '^[a-z]{2}$' }

4. Process Each Language Folder

  • the script looks in each language folder, to retrieve all pages.
foreach ($LanguageFolder in $LanguageFolders) {
    $Pages = Get-PnPListItem -List 'SitePages' -FolderServerRelativeUrl "/sites/$SiteName/SitePages/$($LanguageFolder.Name)"

5. Retrieve and Update Default Pages

  • 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.
    foreach ($Page in $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 linked
        if ($DefaultPage) {
            if ($DefaultPage.FieldValues._SPTranslatedLanguages -cnotcontains $Page.FieldValues._SPTranslationLanguage) {
                $OldLanguages = $DefaultPage.FieldValues._SPTranslatedLanguages
                $NewLanguages = $OldLanguages + $Page.FieldValues._SPTranslationLanguage
                Set-PnPListItem -List 'SitePages' -Identity $DefaultPage.Id -Values @{'_SPTranslatedLanguages' = $NewLanguages } -UpdateType SystemUpdate
            }
        }
    }
}


Full Script

$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 ($LanguageFolder in $LanguageFolders) {
    $Pages = Get-PnPListItem -List 'SitePages' -FolderServerRelativeUrl "/sites/$SiteName/SitePages/$($LanguageFolder.Name)"

    foreach ($Page in $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 linked
        if ($DefaultPage) {
            if ($DefaultPage.FieldValues._SPTranslatedLanguages -cnotcontains $Page.FieldValues._SPTranslationLanguage) {
                $OldLanguages = $DefaultPage.FieldValues._SPTranslatedLanguages
                $NewLanguages = $OldLanguages + $Page.FieldValues._SPTranslationLanguage
                Set-PnPListItem -List 'SitePages' -Identity $DefaultPage.Id -Values @{'_SPTranslatedLanguages' = $NewLanguages } -UpdateType SystemUpdate
            }
        }
    }
}

Disconnect-PnPOnline

I hope this script helps you to re-create the missing multilanguage links in your SitePages library.

About the Author:

Pause
Oliver Menzel

As an IT Solution Architect Collaboration with over 10 years of experience in M365, I help departments optimize their communication and collaboration. I design and implement customized solutions with the following focuses:

🌎 Achieving More Together with SharePoint
I create user-friendly and powerful portals that meet the requirements and needs of the departments. I utilize SharePoint features such as web parts, workflows, forms, search functions, and security settings.

💬 Always Connected and Productive with Teams
As part of Microsoft’s Tap100 program, which gives me early access to new Teams features, I support departments in introducing and using Teams as a central platform for internal and external communication and collaboration. I integrate Teams with other Microsoft products like Outlook, OneDrive, Planner, and Power Platform.

🚀 Making Everything Possible with Power Platform
I create customized applications and automations with Powerapps and Power Automate that improve and simplify the business processes of the departments. I connect PowerApps with various data sources like SharePoint, Excel, and Dataverse. I create Power Automate flows to automate recurring tasks and send notifications. Sometimes I also use PowerShell scripts that I run in Azure Runbooks.

🔧 Keeping Everything Under Control with PowerShell
I use PowerShell to automate and simplify administrative tasks. I write PowerShell scripts to manage, monitor, and optimize SharePoint and Teams environments. I use PowerShell cmdlets to extract, analyze, and manipulate data.

I always try to stay up to date with the latest technological trends and developments in the M365 area. I enjoy working in a team and communicate effectively with all stakeholders. I take pride in my ability to deliver creative and sustainable solutions that create value for the departments.

Reference:

Menzel, O (2024). Re-creating Multilanguage Links: A Step-by-Step Guide. Available at: Re-creating Multilanguage Links: A Step-by-Step Guide (menzel.it) [Accessed: 26th September 2024].

Share this on...

Rate this Post:

Share: