SharePoint Online: Change Site Language using PowerShell

SharePoint Online: Change Default Language using PowerShell
Multi-lingual sites are ideal for global organizations that operate in different regions of the world. Let's see how to change the default language settings on SharePoint Online sites.

What decides in which language the site is displayed? Well, It depends on whether a particular language has added to the site's alternate languages list and the user has that particular language in his user profile language preferences! So, If you want your site to appear in the Arabic language, your site must have "Arabic" under the alternate language section and the user must have "Arabic" at the top of the preferred language settings!

The default Language of the SharePoint Online Site
The language you select during a site collection or subsite creation will become the "Default" language of the site. The default language of the site will remain the same - we can't change it! But if the users visiting the site have one of the alternate languages of the site added in their personal Office 365 language settings then the site will be displayed in that language.
sharepoint online powershell language settings
So, you need to make sure your SharePoint site supports the language in which you want the site to appear is under "Alternate language"!

Add alternate language in SharePoint online
To add alternate languages to the SharePoint Online site, follow these steps:
  • Click on Settings gear Icon >> Click on Site Information >> View All Site Settings
  • On the site settings page, click on "Language Settings" under the Site Administration section.
    sharepoint online change default language Powershell
  • In the Alternate Language(s) section, check the checkbox for the languages you want users to be able to use to display their user interfaces.
  • Click OK to save your changes.

SharePoint Online: Add Alternate Language using PowerShell
To get all available languages in the site, run:
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/It"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Get the Web
$Web = Get-PnPWeb -Includes RegionalSettings.InstalledLanguages

#Get Available Languages
$Web.RegionalSettings.InstalledLanguages
This PowerShell script gives you all available languages and their shortcode and ID. You can add alternate language to the site as:
#Set variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$LanguageID = 1025 #Arabic

#Connect to PnP Online
#Connect-PnPOnline -Url $SiteURL -UseWebLogin 

#Get the Web
$Web = Get-PnPWeb

#Add Alternate Language
$Web.IsMultilingual = $True
$Web.AddSupportedUILanguage($LanguageID)
$Web.Update()
Invoke-PnPQuery
Similarly, we can add alternate language to all site collections (so that subsites inherit this setting) using CSOM PowerShell as:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to add alternate language
Function Add-SPOAlternateLanguage
{  
   param (
        [Parameter(Mandatory=$true,Position=1)]
  [string]$SiteURL,
        [Parameter(Mandatory=$true,Position=2)]
  [Int]$LanguageID
  )
    Try {
        #Set the Context 
        $Ctx=New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    
        #Get the Web
        $Web = $Ctx.Web
        $Ctx.Load($Web)
        $Ctx.ExecuteQuery()

        Write-Host "Adding Alternate Language on Site:"$Web.Url
        $Web.IsMultilingual=$true
        $Web.AddSupportedUILanguage($LanguageID)
        $Web.Update()
        $Ctx.ExecuteQuery()    
    }
    Catch {
        write-host -f Red "Error Setting Alternate Language:" $_.Exception.Message
    }
}

#Config Parameters
$AdminCenterUrl = "https://crescent-admin.sharepoint.com"
$LanguagID = 1025

#Connect to SharePoint Online
$Cred = Get-Credential
Connect-SPOService $AdminCenterUrl -Credential $Cred

#Get All Site Collection URLs
$Sites= (Get-SPOSite).Url

#Loop through Each site collection
ForEach($SiteURL in $Sites)
{
    #Call the Function to Add Alternate Language
    Add-SPOAlternateLanguage $SiteURL $LanguagID
}

Change User Language Preference of a User from Admin Center:
The language of the site is not just based on default language or alternate language, but it's based on the user's preferred language settings. As an administrator, You can set the preferred language of the user through the user profile service.
  • Login to SharePoint Online Admin Center at https://tenant-admin.sharepoint.com >> Click on "More Features" link in the left navigation
  • In "More Features" page, click on "Open" button under "User Profiles"
  • In the User Profiles page, click on the "Manage User Profiles" link.
    sharepoint online change default language powershell
  • Search and find the user profile >> Click on the "Edit My Profile" link from the desired user profile's context menu.
    sharepoint online change default language site collection
  • Scroll down and under the "Language Preferences", Add desired languages to the list, set the order of preference. 
    sharepoint online change language for user
  • Once completed, click on "Save and Close" from the bottom of the page.

Set Preferred Language in User Profile using PowerShell
Let's add "Arabic" and "English" Languages to the user's profile using PnP PowerShell
#Set variables
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
$UserAccount = "[email protected]"

#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -UseWebLogin 

#Update User Profile Property
Set-PnPUserProfileProperty -Account $UserAccount -PropertyName "SPS-MUILanguages" -Values "ar-SA,en-US"

Set Language Preference for a User: Self-Service
End-users can set their language preferences in SharePoint. Here is how:
  • Login to SharePoint Online Site >> Click on your name icon from the top-right corner of the screen. Click on the "My Office Profile" link from the menu.  
  • This takes you to your delve profile. Click on the "Update Profile" button on the page.
  • On the Update your profile page, Expand "How can I change language and regional settings" link and click on click "Here" link.
    sharepoint online change language on site
  • In the "Edit Details" page of your user profile, click on the ellipsis and choose "language and regional"
    sharepoint online change language settings
  • Under My Display Languages, Pick a new language from the drop-down menu, then click Add.
    sharepoint online change personal language
  • Click Save all and close. You'll get a dialog with the message "Your changes have been saved, but they may take some time to take effect. Don't worry if you don't see them right away".
This changes the UI to Arabic for selected user:
sharepoint online change language on site

2 comments:

  1. What is the command to identify the site default language

    ReplyDelete
    Replies
    1. Use:
      $Web = Get-PnPWeb -Includes Language
      $Web.Language
      This gets you the language code for the web!

      Delete

Please Login and comment to get your questions answered!

Powered by Blogger.