4

I have a site column in my site collection whose title I change / translate with following PowerShell statement:

$w = Get-SPWeb "URL to the site collection"
$f = $w.Fields.GetFieldByInternalName("InternalFieldName")
foreach ($c in $w.SupportedUICultures)
{
  $f.TitleResource.SetValueForUICulture($c, "Title for $($c.Name)")
}

$f.Update() /* or */ $f.TitleResource.Update()

That works pretty fine for all alternate languages but the default language.

Suppose there is a root web with a default language en-US and two alternate languages de-DE and tr-TR. Further suppose the field fhas a title of "Default Title" in all three languages. After running the script the field f has the title "Title for de-DE" when German is selected as the language in the UI. In analogy fhas the title "Title for tr-TR" when the user selects Turkish as the language. If the default language is selcted the title is shown as "Default Title".

Suppose that de-DE is the default language then the title of f is "Default Title", "Title for en-US", and "Title for tr-TR".

So the resource for the default language was not changed. Why?

1

As per this article and that one, it seems you cannot set the resource for the default language of the Web with SetValueForUICulture. So, now, my own code looks like:

    private void LocalizeDisplayName(SPField field, Dictionary<int, string> localizedDisplayNames)
    {
        if ((field == null) || (localizedDisplayNames == null) || (localizedDisplayNames.Count == 0))
            return;

        foreach (KeyValuePair<int, string> kvp in localizedDisplayNames)
        {
            field.TitleResource.SetValueForUICulture(new CultureInfo(kvp.Key), kvp.Value);
            if (field.ParentList.ParentWeb.Language == kvp.Key) // Default language cannot be set with SetValueForUICulture, see https://social.msdn.microsoft.com/Forums/sharepoint/en-US/6abbe88b-1111-4406-8716-d57b1600a687/titleresources-setvalueforuiculture-for-default-language?forum=sharepointdevelopmentlegacy
            {
                field.Title = kvp.Value;
                field.Update();
            }
        }

        field.TitleResource.Update();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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