November Happy Hour will be moved to Thursday December 5th.

Translate page programatically

Vote:
 

Hi!

I am currently creating a new page from code to use as my startpage for a sitedefinition which I also create from code..however.. even if I publish the newly created startpage I always end up with the following message in the CMS UI:

"This content is in English. It does not exist in svenska. Would you like to translate it now?"

How can I "Translate" the page from programatically and then publish it as well? I havent been able to find anything related to this here or while googling it..

Any ideas?

Thanks in advance!

#186614
Dec 27, 2017 10:22
Vote:
 

Hi Mattias,

Assuming I understand your question correctly it should just be case of using:

IContentRepository.CreateLanguageBranch

To translate into Swedish and publish you'd want something like (untested):

var translatedContent = _contentRepository.CreateLanguageBranch<IContent>(contentLink, CultureInfo.GetCultureInfo("sv"));
_contentRepository.Save(translatedContent, SaveAction.Publish | SaveAction.SkipValidation , AccessLevel.NoAccess);

Hope that helps,

/Jake

#186638
Edited, Dec 28, 2017 17:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.