Hi,
I have been tasked with duplicating newly created ‘News’ content to all other languages on the site.
The site owner wants to create a new News page in the default language (en-US) and instead of translating the page to all other languages, have the page
and all property values duplicated (yes, in english) to other languages. I’m guessing that they would rather have the pages available in english, rather than not having them at all in other languages… meh!
I’m attempting to do this using the ContentService component, but not having any luck.
Here is the basis of what I’ve got…
private void ContentService_Saving(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentSavingEventArgs e)
{
foreach (IContent content in e.SavedEntities)
{
// If this content is a new page AND is in the default language AND is either a newsArticle or event doctype
// then we want to copy it to other languages.
var isNew = content.HasIdentity == false;
var isDefaultLanguage = e.IsSavingCulture(content, defaultLanguage.IsoCode);
var isNewsOrEventType = (content.ContentType.Alias == "newsArticle" || content.ContentType.Alias == "event");
if (isNew && isDefaultLanguage && isNewsOrEventType && (!e.Cancel))
{
try
{
// How do I duplicate this page and all it's properties to all other languages?
}
catch (Exception ex)
{
e.Cancel = true;
e.Messages.Add(new Umbraco.Core.Events.EventMessage("Saving Cancelled", ex.Message, Umbraco.Core.Events.EventMessageType.Error));
}
}
}
}
Anyone know how to do this?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/108552-how-to-duplicate-new-page-to-all-other-languages-programmatically-using-contentservice