Sort Languages In Content Editor Language Gallery
One of our clients had a requirement where they wanted to see a sorted list of languages in the Content Editor which have versions created. This post outlines the approach I have taken in order to address it.
In a multisite environment, there is a possibility of having different languages configured for each website. It becomes hard to identify the languages configured for a particular site in the Content Editor.
I have applied the following customization in order to sort the languages to show the versioned languages as the first ones in the Content Editor Language Gallery Form list.
As you can see below, currently we have two languages configured for countries United States(US), Canada(CA) and Mexico(MX). If you consider US site,The only languages that will be versioned are en-US i.e., English (United States) : English (United States) and es-US i.e., Spanish (United States) : Spanish (United States).
- I used dotPeek decomplier and made a copy of the class GalleryLanguagesForm located in the Sitecore.Client assembly
- Named my class as SortedGalleryLanguagesForm which inherits from GalleryForm
namespace SitecoreHelpers.SitecoreClientExtensions
{
public class SortedGalleryLanguagesForm : GalleryForm
{
...
}
-
I have created a custom sitecore setting SortLanguagesBasedOnVersionsAvailable
-
Update the OnLoad event by adding the following lines of code
protected override void OnLoad(EventArgs e)
{
...
using (new ThreadCultureSwitcher(Context.Language.CultureInfo))
{
...
//sort languages based on versions available for the site
if (System.Convert.ToBoolean(Settings.GetSetting("SortLanguagesBasedOnVersionsAvailable")))
{
source = SortLanguages(currentItem);
}
...
}
}
- This private method returns a sorted list of languages
private IEnumerable
- Replace the CodeBeside in Gallery Languages.xml file located at Website\sitecore\shell\Applications\Content Manager\Galleries\Languages
from
to
- Once all the changes are done, recycle your application pool and go to content editor and select one of the items under the US site
- As shown below, you will notice that the languages are sorted showing en-US and es-US as the first ones in the list compared to the previous view.
- This functionality can be turned off anytime by setting the configuration setting value to false, which will fallback to the default behavior provided by Sitecore.
- The complete class for the SortedGalleryLanguagesForm can be downloaded here
This custom feature has been developed and tested against Sitecore 8.1 Update-3.
As always, please test these changes on your development environment before applying it on Production.