Change available languages in Episerver through code

High Score Labs News   •   Jan 19, 2022

If you’ve recently come across a bug in the “Language settings for page” interface, you’re not alone. If you haven’t, the bug reloads the pop up and returns an empty checkbox when you click “Inherit settings from parent page”. The bug happens when an active language is disabled in admin view.

To correct the situation, you need to change the settings straight in the database using SQL. However, messing with the database is risky business. Let us show you how to do it through code instead. It’s a lot safer and easier.

The Programmatic Method

To begin, load the repository and content you want to work on. Next, load the settings for that content, which includes a list of settings for each language. So, what we want to do is delete all posts in the list, which will force the page to inherit all the language settings from the parent page.

Use the code below to delete the language settings in a way that ensures the page will inherit the settings instead.

If you get an empty list, all the settings are inherited. If you’d like to set new settings yourself, now is the time to do it. Something like this;

So, there you have it. Now you can change available languages in Episerver using code. Remember to always favor API edits over database edits. They have less chances of blowing up in your face.

Contact us today!