GitHub Icon Image
GitHub

Testing user preferred language of SharePoint site

Summary

Are you testing SharePoint multi-lingual features? And want a quick way to switch languages on a site for a particular user or yourself; this can be useful when testing the modern multi-lingual features in SharePoint if you want to check the quality of the pages translated.

This script changes the MUI setting for a user within the User Information List to update the user with the appropriate language tag.

Example Screenshot

  • PnP PowerShell
  • CLI for Microsoft 365

# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/electronics"

# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive

# Get user details from User Information List to check what is my current language
$item = Get-PnPListItem -List "User Information List" -Id 7 # 7 is Me

# -OR- #

$userEmail = "paul.bullock@mytenant.co.uk"
$CamlQuery = @"
<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name='EMail' />
                <Value Type='Text'>$userEmail</Value>
            </Eq>
        </Where>
    </Query>
</View>
"@

$item = Get-PnPListItem -List "User Information List" -Query $CamlQuery

# Language Reference: https://capacreative.co.uk/resources/reference-sharepoint-online-languages-ids/
$newLang = "cy-GB" #"en-GB"

# Making the language change
Set-PnPListItem -List "User Information List" -Id 7 -Values @{"MUILanguages" = $newLang}

# Disconnect SharePoint online connection
Disconnect-PnPOnline

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?


# SharePoint online site URL
$siteURL = "https://tenanttocheck.sharepoint.com/sites/hr-life"

$userInformationList = "User Information List"

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
    m365 login
}

# Get user details from User Information List to check what is my current language
m365 spo listitem get --listTitle $userInformationList --id 7 --webUrl $siteURL --properties "MUILanguages" # 7 is Me

# -OR- #

$userEmail = "Adam@tenanttocheck.onmicrosoft.com"
$camlQuery = @"
<View>
    <Query>
        <Where>
            <Eq>
                <FieldRef Name='EMail' />
                <Value Type='Text'>$userEmail</Value>
            </Eq>
        </Where>
    </Query>
</View>
"@

m365 spo listitem list --listTitle $userInformationList --webUrl $siteURL --camlQuery $camlQuery

# Making the language change
$newLang = "cy-GB" #"en-GB"
m365 spo listitem set --listTitle $userInformationList --id 7 --webUrl $siteURL --MUILanguages $newLang

# Disconnect SharePoint online connection
m365 logout

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Important changes coming to the way you login into CLI for Microsoft 365 (effective 9th September 2024) see Changes in PnP Management Shell registration in Microsoft 365

Source Credit

Article first appeared on Testing user preferred language of SharePoint site | CaPa Creative Ltd

Contributors

Author(s)
Paul Bullock
Adam Wójcik
Ganesh Sanap

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI