+1-888-365-2779
Try Now
More in this section
Categories
Bloggers
Blogs RSS feed

Sitefinity 4.0: Automate Translations with Custom Workflows and Google Translate

by Pavel Skvirski

Recently one of our customers asked us for a solution to automatically translate news, blog posts and other content-based items in Sitefinity using Google Translate.

The main idea behind the solution depicted in this article is to automatically create and populate missing language versions using Google Translate once a content-based item is saved as a draft. The content editors can thereafter review and improve the newly generated translations.

Custom workflows provide the means to modify and extend the processes behind the lifecycle of content-based items (as well as pages, media items, etc.) with user-specific logic, which perfectly suits this task.

NOTE:

  • The following sample demonstrates the implementation of user-specific scenarios using custom workflows in Sitefinity 4.0 – a Professional or Enterprise license is required to use this sample.
  • Workflow (.xamlx) files are updated frequently; make sure to keep your modified custom workflow file up-to-date.
  • You will need the Telerik.Samples.GoogleTranslateWorkflow project files which you can find here.
  • You can get the latest default workflow files from your client account.
    Where to find the default workflow files


The following section offers step-by-step instructions on how to extend the workflow file; if you want to skip it you can use the CompleteGoogleTranslateWorkflow.xamlx file from the archive instead.

Create the .xaml workflow file

  1. Copy the unmodified AnyContentApprovalWorkflow.xamlx workflow file to the Workflows directory inside your Sitefinity project folder.
  2. Open the Sitefinity project file in Visual Studio.
  3. Add a reference to the Telerik.Samples.GoogleTranslateWorkflow project.
  4. Build the solution.
  5. Open the AnyContentApprovalWorkflow.xamlx file inside Visual Studio and locate the ContentApproval Flowchart.
  6. Double click the ContentApproval Flowchart and locate the ClearScheduledOperationsActivity.
  7. Create a new Flowchart and name it “Google Translate Flowchart”.
  8. Set the “Google Translate Flowchart” as the last step by dragging an arrow from ClearScheduledOperationsActivity and dropping it on the newly created Flowchart.
  9. Double click the “Google Translate Flowchart”.
  10. Open the Variables tab and create a new variable by clicking the bottom table row.
  11. Name the variable translateItem and set its type to IAnyTempDraftFacade
  12. Inside the Default field paste: App.Prepare().SetContentProvider(providerName).WorkWith().AnyContentItem(contextBag("ContentType"), itemId).GetTemp()
  13. To create custom translations when the item is saved as a draft add a FlowDecision element from the toolbox.
  14. Set operationName.Equals("SaveDraft") as the condition.
  15. Add a ForEach element to the Flowchart.
  16. Set it as the step which is executed if the FlowDecision returns true by dragging an arrow from the FlowDecision element.
  17. Set System.Globalization.CultureInfo as the TypeArgument
  18. Set New Telerik.Sitefinity.Abstractions.AppSettings().DefinedFrontendLanguages as Values.
  19. Double click the newly added ForEach element.
  20. Add the GoogleTranslateActivity from the toolbox.
    NOTE: If you cannot find the GoogleTranslateActivity in your toolbox make sure that you executed steps 3&4.
  21. Select the GoogleTranslateActivity element and set the following parameters
    1. OnbehalfOfIp as: contextBag("userHostAddress")
    2. TranslateTo as: item
    3. WorkflowItem as: translateItem.GetAs(Of IWorkflowItem)()
      GoogleTranslateActivity properties
  22. In the breadcrumb on top click “Google Translate Flowchart” to get back to the “Google Translate Flowchart”.
  23. From the toolbox add an ExecuteCodeActivity and set its CodeExecutionResult property to translateItem.SaveChanges()
  24. Save the workflow file.
  25. Build the solution.

Flowchart

The Google Translate Flowchart in its complete state.

Register the workflow

The only thing left to do is to register the custom workflow:

In the backend, go to Administration > Settings > Advanced > Workflows.


The Settings view lists workflow associations by model type.

 

Change the workflow ServiceUrl to point at the GoogleTranslateAnyContentApproval.xamlx workflow, for each model you want to apply automatic translation to.

Final comments

The whole procedure described above could have been implemented entirely inside the GoogleTranslateActivity. However, having only the actual translation logic encapsulated as an activity allows it to be reused in completely different scenarios.

This is where the power of Sitefinity’s workflows comes into play, which allows you to model your own unique business processes using convenient enterprise-grade WF4 technology.

7 comments

Leave a comment
  1. ramesh Jan 23, 2011
    nice article... i am in the Microsoft Workflow Foundation team and would be interested in chatting about how you use WF.
  2. Michael Russell May 30, 2011
    Unfortunately, this API is deprecated and won't be available as of December 1.

    http://code.google.com/apis/language/translate/overview.html
  3. Jeff Waggoner Aug 04, 2011
    Is this availible yet?
  4. Dan Jordan May 15, 2012
    I've tried the Google Translate tool referenced here. It doesn't work. While I'd prefer doing translations properly (i.e., have a live expert do it) at least a canned translation would give the reader some sense of what's on the page. Any ideas for making this work? 
  5. Nick Jan 10, 2013
    I can't find any information about translation vendor plug-ins. Are these available? In other words, can translation vendor(s) receive electronic notifications of new items to translate, controlled by workflow? We don't want to extract content from the CMS and send to them manually, and then paste back into the CMS once translation and review is completed.  
  6. sports psychology degrees Apr 22, 2013
    I've tried the Google Translate tool referenced here. It doesn't work.
    While I'd prefer doing translations properly (i.e., have a live expert
    do it) at least a canned translation would give the reader some sense of
    what's on the page. Any ideas for making this work? 
  7. online sports psychology degree Apr 22, 2013

    I can't find any information about translation vendor
    plug-ins. Are these available? In other words, can translation vendor(s)
    receive electronic notifications of new items to translate, controlled
    by workflow? We don't want to extract content from the CMS and send to
    them manually, and then paste back into the CMS once translation and
    review is completed.  

    Leave a comment