AI OnAI Off
Danny
There is nothing out of the box to do this. Most people end up writing some code to copy a section of the page tree from one language to another.
The following class should allow you to do that:
public class CloneTree
{
private PageReference FirstClonedPage;
private LanguageBranch Language;
private int PageCount;
private LanguageBranch SourceLanguage;
private CloneTree()
{
}
public static int Execute(PageReference SourceRef, LanguageBranch sourceLanguage,
PageReference DestinationRef, LanguageBranch language)
{
var ct = new CloneTree();
ct.Language = language;
ct.SourceLanguage = sourceLanguage;
ct.CopyBranchToLanguage(SourceRef, DestinationRef);
return ct.PageCount;
}
private void CopyBranchToLanguage(PageReference SourceRef, PageReference DestinationRef)
{
if (HttpContext.Current != null)
{
HttpContext.Current.Server.ScriptTimeout = 300;
}
DeleteInvalidChildren(SourceRef);
var page = new PageData();
bool _languageExists = false;
PageDataCollection pdc = DataFactory.Instance.GetLanguageBranches(SourceRef);
foreach (PageData p in pdc)
{
if (p.LanguageID == SourceLanguage.LanguageID)
{
_languageExists = true;
}
}
if (_languageExists)
{
page = DataFactory.Instance.GetPage(SourceRef, new LanguageSelector(SourceLanguage.LanguageID));
}
else
{
page = DataFactory.Instance.GetPage(SourceRef);
}
PageData newPage = ClonePage(DestinationRef, page, Language);
DataFactory.Instance.Save(newPage, SaveAction.CheckIn);
if (CheckOldSelfReferences(page.PageLink, newPage))
{
DataFactory.Instance.Save(newPage, SaveAction.Save);
}
if (FirstClonedPage == null)
{
//never recurse this page.
FirstClonedPage = newPage.PageLink;
}
PageCount++;
PageDataCollection children = DataFactory.Instance.GetChildren(SourceRef,
LanguageSelector.AutoDetect(true));
if (children.Count > 0)
{
foreach (PageData child in children)
{
//stops an infinate recurstion loop.
if (child.PageLink.ID != FirstClonedPage.ID)
{
CopyBranchToLanguage(child.PageLink, newPage.PageLink);
}
}
}
}
private static bool CheckOldSelfReferences(PageReference OriginalRef, PageData page)
{
bool HasChanges = false;
foreach (PropertyData prop in page.Property)
{
if (!prop.IsReadOnly)
{
if ((prop.Type == PropertyDataType.PageReference) && ((PageReference)prop.Value == OriginalRef))
{
prop.Value = page.PageLink;
HasChanges = true;
}
}
}
return HasChanges;
}
public static PageData ClonePage(PageReference newPageParentRef, PageData page, LanguageBranch lang)
{
PageData newPage = DataFactory.Instance.GetDefaultPageData(newPageParentRef, page.PageTypeID,
new LanguageSelector(lang.LanguageID));
foreach (PropertyData prop in newPage.Property)
{
if (prop != null && (!prop.IsReadOnly) && (prop.Name != "PageLink") &&
(prop.Name != "PageParentLink")
&& (prop.Name != "PageMasterLanguageBranch") && (prop.Name != "PageLanguageBranch") &&
(prop.Name != "PageCategory") &&
(prop.Name != "PageLanguageID") && (prop.Name != "PageLinkURL") && (prop.Name != "PageGUID") &&
(prop.Name != "PageDeleted"))
{
prop.Value = page.Property[prop.Name].Value;
}
}
return newPage;
}
}
Is is possible to take a clone of the master branch content into a new language in one go?
At the moment each market has to go to the page, goto language overview, create that branch, and then copy and paste existing content ready for translation. I want to be able to do this for all pages, in one go?
If this could include the dynamic properties too, that would be great? (I assume it won't given the bugs in system which menat that multi-language dynamic properties were not fully supported/working)
Hope this makes sense.!