Take the community feedback survey now.
AI OnAI Off
Take the community feedback survey now.
Hi,
It is possible to create a new language branch with a contentrepository in a scheduled job. See http://world.episerver.com/documentation/Class-library/?documentId=cms/9/7001E7FF
Jari
Hi,
Below you could find a code snippet (I didn't test it):
[ScheduledPlugIn(DisplayName = "Automatic content translation")]
public class RoomTypeImportJob : ScheduledJobBase
{
private readonly IContentRepository contentRepository;
public readonly CultureInfo sourceCulture;
public readonly CultureInfo targetCulture;
public RoomTypeImportJob()
{
this.contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
this.sourceCulture = new CultureInfo("en");
this.targetCulture = new CultureInfo("sv");
}
public override string Execute()
{
AddAllTranslations(ContentReference.RootPage);
return "Job completed";
}
private void AddAllTranslations(ContentReference parentPage)
{
var languageBranches = contentRepository.GetLanguageBranches<IContent>(parentPage).ToList();
var targetLanguageBranch = languageBranches.FirstOrDefault(lb => ((ILocalizable)lb).Language.Name == this.targetCulture.Name);
if (targetLanguageBranch == null)
{
var sourceContent = contentRepository.Get<IContent>(parentPage, this.sourceCulture);
targetLanguageBranch = contentRepository.CreateLanguageBranch<IContent>(parentPage.ToReferenceWithoutVersion(), this.targetCulture);
targetLanguageBranch.Name = sourceContent.Name;
//
// here need to handle all required fields
// targetLanguageBranch.RequiredField = ...
//
contentRepository.Save(targetLanguageBranch, SaveAction.Publish | SaveAction.SkipValidation);
}
var children = contentRepository.GetChildren<IContent>(parentPage, this.sourceCulture);
foreach (var content in children)
{
this.AddAllTranslations(content.ContentLink);
}
}
}
I think that you could combine this snipet together with automatic properties copying (to copy all required properties):
I have a bunch of pages in english for country 1, and I want to create the same pages in arabic for the same country 1.
I want to translate all the content from english to arabic, for the same country. I can do it page by page, with option translate.
Is it possible to code a scheduled job (or something else....) to translate all pages (or selected pages by criteria) from one language to another one ???
Regards