Create a bunch of pages, translate from another language

Vote:
 

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

#141314
Nov 11, 2015 19:32
Vote:
 

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

#141320
Edited, Nov 11, 2015 21:41
Vote:
 

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):

http://cjsharp.com/blog/2013/04/19/automatically-populating-page-or-block-type-properties-for-a-language-branch-in-episerver-7/

#141325
Nov 12, 2015 7:39
* 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.