EPiServer  /  CMS March 01, 2012

Programmatically switching language branch in EPiServer

On the subject of “for future reference” and “note to self”, when needing to change language branch on the current context (HTTP request or in a scheduled job) in EPiServer:

EPiServer.BaseLibrary.Context.Current["EPiServer:ContentLanguage"] 
    = new CultureInfo("no");
In this case DataFactory methods such as GetPage will default to returning pages in Norwegian. These methods all have overloads with an ILanguageSelector as a parameter, but in case one for some reason don’t want to or is able to use them the above snippet seems to work well and comes in handy.

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

Comments

comments powered by Disqus

My book

Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!

More about EPiServer CMS