0

I have an odd scenario. When I change the Language Preferences of a User using the Edit Profile Properties Page in the User Profile Service Application (SPS-MUILanguages ans SPS-ContentLanguages) the changes are not updated in the Users MySite. The settings are, however, correctly updated in the User Profile Service Application.

Now, the weird thing is, if the user goes to it's my site and just clicks save on it's user profile, then the languages appear. After that updates through the Service Application also work.

Anyway, I need to set the languages for a lot of users using powershell, and I am unable to let every user click save on their mysite. Any ideas? :)

4 Answers 4

1

We can using the PowerShell below to update the SPS-MUILanguages and SPS-ContentLanguages properties of user profile.

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server")           
$site=new-object Microsoft.SharePoint.SPSite("http://sp2013/sites/team")         
$serviceContext = Get-SPServiceContext $site
$site.Dispose()           
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext)
$userProfile = $upm.GetUserProfile("lz\test1")
$userProfile["SPS-MUILanguages"].Value = "en-GB,en-US"
$userProfile["SPS-ContentLanguages"].Value="en-US"      
$userProfile.Commit()

enter image description here

2
  • As I said, I tried this before and this is indeed working as intended. However, the changes made in the User Profile Service Application using PowerShell will not be reflected in the users MySite. So the changes really don't have an effect until the user explicitly clicks on 'Save my Profile' on his MySite.
    – Ben Lime
    Commented Oct 22, 2018 at 6:20
  • It's not working for everyone, because the code is missing the crucial $userProfile["SPS-RegionalSettings-Initialized"].Value = $true. Without that the timer will not do anything.
    – Nils
    Commented Oct 25, 2019 at 9:50
0

Well, I finally figured it out. There is another class which is called SPUserSettingsProviderManager. It has methods to set the User's display and content languages.

string language = "en-GB,de-DE";
SPWeb web = SPContext.Current.Web;
SPUser user = web.CurrentUser;

var usp = SPUserSettingsProviderManager.Local.UserSettingsProviders.FirstOrDefault();
var uspCtx = userSettingsProvider.GetProviderContext(user);

usp.UpdateUserLanguageSettings(uspCtx, web.CurrentUser, language, language);
usp.UpdateUserDisplayLanguageSettings(uspCtx, user, language);
usp.UpdateUserContentLanguageSettings(uspCtx, user, language);
0

I have created a script for SharePoint 2016 on premise: I used it to receive the users Organization Unit from its SPS-Distinguished Name property and depending on it I have set his preferred display language order. For example if a user is spanisch I try to use first Spanish, than englisch, than german as default fallback language "es-ES,en-US,de-DE". So this might be a good start for all users to use a mulitlanguage SharePoint Farm. After this basic configuration they might update the preferred userlanguage in ther user profile if they want to, but they do not have to do it, because this script provides a default configuration for all.

cls 
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction
SilentlyContinue
$url = "https://URLOFMYSITES/";
$site = Get-SPSite $url;
$web = $site.RootWeb;
$context = Get-SPServiceContext $site;
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
$profiles = $profileManager.GetEnumerator();
while ($profiles.MoveNext())
{
$userProfile = $profiles.Current;
$accname = $userProfile.AccountName; 
$up = $profileManager.GetUserProfile($accname);
$organizationUnit = $up["SPS-DistinguishedName"].split(',')[1].split('=')[1]  
$preferredLanguages = "";
switch($organizationUnit)
{
    DE   {$preferredLanguages = "de-DE,en-US";break;}
    CN   {$preferredLanguages = "zh-CN,en-US,de-DE";break;}
    US   {$preferredLanguages = "en-US,de-DE";break;}
    default {$preferredLanguages = "en-US,de-DE";break;} 
}

$up["SPS-MUILanguages"].Value = $preferredLanguages #for example "en-US,de-DE,it-it"
$up.Commit()

}

2
  • One more thing... -> It is important to use "en-US" instead of "en-us", otherwise it wont work. -> Use "de-DE,en-US" instead of "de-DE, en-US" so don't use any whitespace.
    – sustimus
    Commented May 7, 2019 at 13:39
  • The changes will be visible in the Central Administration immediately and some more seconds later in the user profile of the mysite.
    – sustimus
    Commented May 7, 2019 at 13:41
0

Partially related to this post. You can achieve the same using Power Automate and in SharePoint Online.

http://fixingsharepoint.blogspot.com/2022/02/how-to-update-preferred-language.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.