Sitecore 8.1 Language Dropdown Sorting in Content Editor

If you have any little experience with Sitecore, you know that the languages available for the website can be maintained under System->Languages, and that they can be seen in the Content Editor, in a dropdown on the right side. But in what order are they displayed in the dropdown and how to change this if we want? My project is built on Sitecore XP 8.1 rev. 160302, and this is actually the first version where Sitecore provides an easy way to change the language ordering.

Below I have the language dropdown with the initial order:

LanguageDropdownUnsorted

There is a setting in Sitecore.config, suggestively called ContentEditor.SortLanguages, which by default is set to false. This means that by default, the dropdown displays the languages in the order they were created. If I change this setting to true, the display order in the dropdown will be the same as the order from System->Languages, which is controlled by the Sort Order field of each Language item.

SortOrder

If you somehow don’t see the setting in Sitecore.config, this is how you define it:

<!--  CONTENT EDITOR SORT LANGUAGES
      Indicates whether the Content Editor show languages in the language selection dropdown
      in the same order as /sitecore/system/Languages child items.
      Default value: false
-->
<setting name="ContentEditor.SortLanguages" value="true"/>

Using a decompiler, you can see that this setting is checked in the OnLoad() method from Sitecore.Shell.Applications.ContentManager.Galleries.Languages.GalleryLanguagesForm (Sitecore.Client.dll):

if (Settings.ContentEditor.get_SortLanguages())
{
    languages = languages.OrderBy<Language, Language>(delegate(Language x)
    {
        return x;
    }, new LanguageComparer(currentItem.Database));
}

After changing the setting, I can see the languages in the dropdown ordered as in System->Languages:

LanguageDropdownSorted

If you want even more language dropdown customization, you could do this by opening the file ”<website>\sitecore\shell\Applications\Content Manager\Galleries\Languages\Gallery Languages.xml” and replacing the call to GalleryLanguagesForm (Sitecore.Client.dll) in the CodeBeside tag with your own class containing the custom code.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s