Question

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? :)

Was it helpful?

Solution 2

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);

OTHER TIPS

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

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()

}

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top