Error when deleting a language in Sitecore: “Could not parse the language”

While decommissioning a section of a website in a language that we no longer support, I found myself in need of removing the language altogether; trying to delete the item, however, resulted in the following error:

Could not parse the language
Note that a custom language name must be on the form

A brief headscratch and search ensued, and eventually I found the problem – somehow, in order for Sitecore to delete a language, that language must be registered in the local machine.

The following code ended up doing the trick:

using System.Globalization;

namespace DotNetCustomCulture
{
  class Program
  {
       static void Main(string[] args) {
           string culture = "en-PL";
          string name = "English Polish";

          CultureInfo cultureInfo = new CultureInfo("en");
          RegionInfo regionInfo = new RegionInfo("PL");

          CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder(culture, CultureAndRegionModifiers.None);

          cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
          cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);

          // Custom Changes
          cultureAndRegionInfoBuilder.CultureEnglishName = name;
          cultureAndRegionInfoBuilder.CultureNativeName = name;

          cultureAndRegionInfoBuilder.Register();
      }
   }
}

I created a new .Net Console Application with this code, and after running it and recycling the Application Pool I was able to delete the language in question.

Leave Comment

Your email address will not be published. Required fields are marked *