Programmatically changing default culture for a site

Ozgur Ozguven asked on July 22, 2015 18:22

Hi

I can't find/see how I can programmatically change a site's default content culture. In Admin UI, there is a "Default content culture" field but I need to do this programmatically via the API. Is this possible?

Many thanks

Ozgur

Correct Answer

Petr Jiroušek answered on July 23, 2015 11:07

Hi Ozgur, this might look a bit confusing as it is not part of the site object. However there is a simple way. You just need to update settings value. Please see code below how to achieve this >

var siteInfo = new SiteInfoIdentifier(1);
var setting = SettingsKeyInfoProvider.GetSettingsKeyInfo("CMSDefaultCultureCode", siteInfo);
setting.KeyValue = "en-US";
setting.Update();
0 votesVote for this answer Unmark Correct answer

Recent Answers


Ozgur Ozguven answered on July 23, 2015 11:30 (last edited on July 23, 2015 11:30)

Thanks Petr. Due to settings inheritance I actually ended up doing an insert as below:

var siteInfo = new SiteInfoIdentifier(1); var setting = SettingsKeyInfoProvider.GetSettingsKeyInfo("CMSDefaultCultureCode", siteInfo); setting.KeyValue = "en-US"; setting.Insert();

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.