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
Sometimes we get the request to create a menu item that works as a signout button. There are of course several ways to do this. For instance you could create a web part/widget and place it on the page which automatically signs the user out. In this post I will show you a different approach using a custom signout macro.
Filed under: Macro, API
I have been doing some Kentico API coding lately and I thought that it would be good to share some code which I recently used to create documents in multiple cultures. I will start with a brief overview of the needed steps followed with some example code.
Filed under: Culture, API
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