Visual

Blog post

Last week we visited the HartmanEVENT 2011 in the Netherlands. This is were my boss attended the "Content Tool Idol 2011" contest and informed me about a nice little feature he had seen in one of the vendor sessions. The feature allowed the editor to easily translate texts using Google's translate service.

Because I like challenges and love the flexibility of Kentico CMS, I decided to create my own Google translate implementation. One day later I got the following result:

When you have setup a website using multiple cultures you get a third option when creating a new culture version of the document. The option allows you to translate the document using the Google translate service based on a version of the document in another language.

select_google_translate_option.png

When you hit the "Create document" button, the Google translate service will check all the "String" fields and translates them using the Google API for dotnet. This results in the following:

translated_form.png

Pretty nice and simple right? If you would like to integrate this in your own Kentico CMS installation, then the following steps will show you how it's done:

Step 1: Download the Google API for dotnet and it to the Bin folder of your Kentico CMS installation.
Note: I have used the 3.5 .NET Framework version of the API. For other versions please go to the following location.

Step 2: Make adjustments in the following files (line numbers are included). 
Note: The code changes and line numbers apply to a clean installation of version 5.5R2.

CMSModules\Content\CMSDesk\New\NewCultureVersion.aspx

line 25:
<tr>
    <td>
        <asp:RadioButton ID="radGoogleTranslate" runat="server" GroupName="NewVersion" EnableViewState="false" />
    </td>
</tr>
line 58:
if (radCopyElem.checked || radGoogleTranslateElem.checked) {
line 71:
else if (radGoogleTranslateElem.checked) {
    document.location.replace("../documentframeset.aspx?action=newculture&nodeid=" + nodeId + "&sourcedocumentid=" + lstCulturesElem.options[lstCulturesElem.selectedIndex].value + "&translate=google");
}
CMSModules\Content\CMSDesk\New\NewCultureVersion.aspx.cs

line 25:
"var radGoogleTranslateElem = document.getElementById('" + radGoogleTranslate.ClientID + "');\n" +
line 36:
radGoogleTranslate.Text = ResHelper.GetString("ContentNewCultureVersion.GoogleTranslate");
line 40:
radGoogleTranslate.Attributes.Add("onclick", "ShowSelection();");
CMSModules\Content\CMSDesk\Edit\Edit.aspx.cs

line 297:
// Check for the translation option
if (QueryHelper.GetString("translate", "").Equals("google"))
{
    // Setup the from and to cultures
    string fromCulture = CultureHelper.GetCultureInfo(node.DocumentCulture).TwoLetterISOLanguageName;
    string toCulture = CultureHelper.GetCultureInfo(formElem.CultureCode).TwoLetterISOLanguageName;

    // Initiate the Google translate client using the current domain
    Google.API.Translate.TranslateClient client = new Google.API.Translate.TranslateClient(UrlHelper.GetCurrentDomain());

    // Get the class of the new document
    CMS.DataEngine.IDataClass treeClass = CMS.DataEngine.DataClassFactory.NewDataClass(node.NodeClassName, node.TreeProvider.Connection);

    // Loop through the column names
    foreach (string col in treeClass.StructureInfo.ColumnNames)
    {
        // Check if the column is of type string
        if (treeClass.StructureInfo.GetColumnType(col).Name == "String")
        {
            // Update the value of the field using Google's translating service
            DataHelper.SetDataRowValue(formElem.BasicForm.DataRow, col, client.Translate(ValidationHelper.GetString(node.GetValue(col), ""), fromCulture, toCulture));
        }
    }
}

Step 3: Add the following (English) localization string using the UI Cultures module:

Key: ContentNewCultureVersion.GoogleTranslate
Text: Translate using the Google translate service based on another language

And you're done! Feel free to tweak the code and happy translating!
Filed under: API, Google, Tweaks, UI, 55R2
In this post I will show you the needed steps to easily provide your own custom E-commerce provider from App_Code. This applies to Kentico CMS version 5.5 or newer.
Filed under: API, Ecommerce, 55
With version 5.5R2 it will be possible to modify documents via the WebDAV protocol. I have been playing around with this feature and wanted to share some experiences that I have come across.
Filed under: WebDAV, 55R2
A couple of days ago some more information about the R2 release of Kentico CMS 5.5 was posted on the Kentico Partner Portal. The release includes: SharePoint 2010 support Intranet Starter Site Template Document library (integration with Microsoft Office) Project Management Support for WebDAV Kentico CMS 5.5 with all...
Filed under: News, 55 R2
This post covers a tweak which I find useful when working with multiple cultures. The tweak does not add documents which are not translated in the content tree. This can be usefull when you are working with a lot of documents/cultures or when you simply want to keep a clean content tree per culture.
Filed under: Culture, Tweaks, UI, 55

Have you ever worked in the content tree and felt that the maximum number of displayed documents were not enough? By default this happens when a parent document contains more than 100 child documen...
Just when you think you got 5.0 figured out, Kentico drops an early beta version of the upcoming 5.5 release. The beta version, which has been made available via the Kentico Partner Portal, allows us to learn and play with the new features and provide feedback for a even better Kentico CMS release.

Search