Saturday, 26 January 2008

Change Page Language in EPiServer

After a previous post about changing an existing page's page type in EPiServer, I've now found out how to change an existing page's language.

At Esendex, we have different websites for each country in EPiServer. Originally, we started with a single UK website which was simply copied to create ones for Australia, France and Spain. This meant that all of the pages had been created in English (default) instead of the respective country languages. Instead of creating further instances of the pages, we wanted to change the existing ones to save time. This also helped us with the our content mirroring; we have servers in the respective countries to host our global sites. These servers should only have a copy of the website in the appropriate language. We found it difficult mirroring English pages into French copies and we didn't want multiple instances on these servers.

declare @PageID int
declare @OriginalLanguageBranchID int
declare @NewLanguageBranchID int
declare @NewLanguageID nvarchar( 3 )

set @PageID = X
set @OriginalLanguageBranchID = Y
set @NewLanguageBranchID = Z
set @NewLanguageID = '' -- e.g. 'FR'

update tblPageLanguage
set fkLanguageBranchID = @NewLanguageBranchID, fkLanguageID = @NewLanguageID
where fkPageID = @PageID

update tblPage
set fkMasterLanguageBranchID = @NewLanguageBranchID, fkLanguageID = @NewLanguageID
where pkID = @PageID

update tblProperty
set fkLanguageBranchID = @NewLanguageBranchID
where fkPageID = @PageID and fkLanguageBranchID = @OriginalLanguageBranchID

exec editPageVersionList @PageID = @PageID, @SID = NULL

Simply replace X with the page ID, Y with the original (current) language branch ID and Z with the new language branch ID. The new language ID is respective to the new language branch ID. These ID values can be found by querying the tblLanguage and tblLanguageBranch tables.

It might sound obvious, but before running this script on a page, make sure no instances for the new language already exist otherwise concurrency exceptions will be thrown.


Anonymous said...

Nice, but do you have the same script for EPiServer 6?

Andrew Gunn said...

No idea dude. I don't work with EPiServer anymore.