I want to change master language on a page, the code bellow works of i jsut change name or some other property but master language doesnt change. Is this possible and if so how can it be solved?
var writablePage = _contentRepository.Get(page).CreateWritableClone();writablePage.MasterLanguage = new CultureInfo(masterLanguageToSet); _contentRepository.Save(writablePage, SaveAction.Publish);
/Thx in advance, Pär
As far as I'm aware, this isn't something you can officially set through code. If you need to change the master language of an individual content item you would need to make the change in the database but I'd always warn against making changes in the DB if at all possible as you can seriously damage your site if it all goes wrong. I'd also advise against doing this on a production site/database.
With the warning out of the way, the master language is set on the record in the tblContent table using the fkMasterLanguageBranchID field. The value in this field must match the ID of one of the active language branches in the tblLanguageBranch table and your content will need to already exist in that language.
One of the perils of making changes in this way is that the content data will be cached and so you won't see this change until your application pool next restarts (or the cache expires). The other point to consider is that this approach will only change which version is considered the master version, it won't take across content that had been entered in the previous master version so, as a minimum, you'll need to fill in any properties that aren't culture specific.
Hi Paul, thx for quick reply
Our customer wants to use a template structure, currently they have done it in en-gb but it should be in en, and there is some other cases as well. The problem is that Episervers versioning of content is based on the master language, you cant delete the master language version even though you might have copied the page from another site to a site with another main language.
We had a meeting with Episerver discussing this and the were the ones speaking about changing this through code, ill add a ticket to the support. Ill put the awnser here as well when i get this figured out.
Have you found a solution, for changing the MasterLanguage through code?
We need to change it, before removing the Culterspecific attribute from multiple blocks and pages.
We tried to change the MasterLanguage in the database with succes, however we do not wish to do this in production database if we can do it through the code.
Yes and no :) You cant change the master language through code when the page is created. Episerver helped us looking in to this. The solution was to create a fucntion that created new pages and copied all the properties. For exmaple if we had en-en and wanted to change to ca-en, we created a new page ca-en and copied all properties that. It was a bit of a hassle since we had to do this in live environment as well.¨