Loading...

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

Re-creating Multilanguage Links: A Step-by-Step Guide
Featured image of post Re-creating Multilanguage Links: A Step-by-Step Guide

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
2
$TenantName = 'yourtenantname'
$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.
1
2
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.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$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. If you have any questions or feedback, feel free to leave a comment below.

Published on:

Learn more
Need help with this product?

We can help you with Re-creating Multilanguage Links: A Step-by-Step Guide

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

The State of the Microsoft 365 Nation
The State of the Microsoft 365 Nation

Recent content on The State of the Microsoft 365 Nation

Share post:

Related posts

Creating Copilot Studio Agents Without an M365 Copilot Premium License

A common assumption when getting started with Copilot Studio is that you need a full Microsoft 365 Copilot Premium license. That assumption is...

5 months ago

Power Automate: Get events (V4) shared mailbox fix

When your flow reads a shared mailbox calendar using the Office 365 Outlook → Get events (V4) connector, it can fail in a way that looks like...

6 months ago

Using Managed Identity with Azure Automation & PnP.PowerShell

How to Set Up a Managed Identity for Azure Automation Runbooks and Use It in PowerShell Scripts with PnP.PowerShell This guide walks you throu...

1 year ago

UPDATED - Set Up Pay-as-you-go M365 Chat & SharePoint Agents

Introduction to Pay-as-You-Go Agents in Microsoft 365 Microsoft has introduced a flexible way for organizations to leverage AI capabilities wi...

1 year ago

How to Use Flexible Sections in SharePoint Pages and News

If you’ve been using SharePoint Online to build pages or share news, you know how important it is to have a layout that works for your c...

1 year ago

What's New in SharePoint Pages

1. New Carousel Layout in the Hero Web Part The Hero Web Part has always been a fundamental element of SharePoint pages. The new Carousel Layo...

1 year ago

Power Platform Solutions Made Simple

Introduction to Power Platform Solutions Power Platform Solutions offer many benefits, especially when moving from standalone flows and apps t...

1 year ago

Use your Bluesky post for comments on your Hugo Blog

Since Bluesky is getting really popular by people I interact with, I decided to switch my blog comments to Bluesky posts. In this blog post, I...

1 year ago

Exploring SharePoint Online's SiteAssets Library

The SiteAssets library in SharePoint Online often seems like a mystery to a lot of users I talk to, but it’s important to understand it ...

1 year ago

Step-by-Step Guide to Copy Pages between SharePoint Online

Unfortunately you can’t copy pages in SharePoint through the UI. But sometimes you may need to copy pages and their associated SiteAsset...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.