When you work on a multiple language website, you will have to enable/disable the languages that your website supports.  If you have read my guide on enabling languages within Episerver, How To Enable Multiple Languages In Your Episerver Website then you will know how to manually enable and disable the languages your website can support.

Some of the problems with developers manually configuring the supported languages include failing unit tests, odd bugs, inconsistent environments which can lead to inconsistent bugs throughout the value-stream. One developer might have their local site to support English and French, while another might use Swedish. If they try and import content using import/export then it's very common that one person's machine works, while another developer's website doesn't.  Trust me when I say this, it's a pain in the bum when things can't be done by simply running some code.  

These issues are the reason why I recommend, that on every Epsierver project you work on, you create some set-up code that will create some website pages for you, set some default project configuration settings so all developers, QA are all configured consistently.  Enabling/disabling languages is no different and luckily it's fairly simple to write some code to do everything for you.  In today's guide I'm going to cover all the code you'll need, so let's begin

The ILanguageBranchRepository

To get/set your website's language settings, you'll need to use the ILanguageBranchRepository. To get a complete list of all the languages defined in your site, you can use this snippet:

One thing you should notice about the language definitions returned is that they are all set as read-only. This means that if you want to modify it (like enabling/disabling), just like you would when you modify an existing Episerver page in code, you need to create a clone, modify that clone and then write it. Which looks like this:

After you clone your language you can then modify it, how you see fit and then save it.

Following this approach, you can then modify, create new market definitions, or, even delete markets. To delete a language you can use this snippet: