Kentico CMS 7: Custom Translation Service Providers

   —   
Do you have a local translation service provider that you use for creating your multilingual websites? Do you like our new Translation services functionality in v7 and want to use it with your translation service provider? Read further :)
As the architecture of the translation services feature is robust and extensible you can define your custom service providers as with all other out-of-the-box providers. Implementing your custom translation service provider is pretty simple task, as most of the work is done automatically by the system.

As mentioned in the introductory blog post (http://devnet.kentico.com/Blogs/Stepan-Kozak/March-2012/Kentico-CMS-7-Translation-services.aspx), there are two types of services – machine and classic which differ in their interface. In this article I'll show you how to create both.

Custom machine translation service provider

To register your custom service, you need to take the following steps:
  • Create your own class that inherits from AbstractMachineTranslationService
  • Override and implement the following abstract methods
    • IsAvailable – A method which checks whether the provider is ready to use (e.g. that credentials to the target service are provided, that target service is on-line, etc.).
    • Translate – The main method which calls the base service (Google / Bing / ...) and translates given text from the source language to the target language.
    • Detect – A method which can detect the language of the given text.
    • Speak – A method which provides a stream with sound from a text-to-speech engine (doesn’t have to be implemented, throw an exception if your service does not support text-to-speech).
  • Register the provider in CMS Site Manager / Development / Translation Services

  • Add an icon of your service to the following location: ~/App_Themes/Default/Images/CMSModules/CMS_TranslationServices/<ServiceProviderCodeName>.png
After this process your service will be displayed among all the other services and can used immediately.



Above is a sample machine translation service implementation which just transfroms the given text to upper case.


Custom classic translation service provider

To register your custom classic service, the process is very similar to that of machine translation services:
  • Create your own class that inherits from AbstractHumanTranslationService
  • Override and implement the following abstract methods
    • IsAvailable – A method which checks whether the provider is ready to use (e.g. that credentials to the target service are provided, that target service is on-line, etc.)
    • IsLanguageSupported – Returns whether the service supports the given language
    • CreateSubmission – Creates a new submission (or resubmits an existing one)
    • CancelSubmission – Cancels given submission
    • DownloadCompletedTranslations - Retrieves completed XLIFF files from the service and processes them (imports them into the system).
  • Register the provider in CMS Site Manager / Development / Translation Services
  • Register your custom settings for the service (credentials, export/import folders, etc.) using CMS Site Manager / Development / Custom settings
After this process you can start using your service as well as the other services:



For illustration purposes, a sample provider has been implemented. This provider is manual translation provider which saves the submission (XLIFF files + instructions) as a zip file to a shared Export folder (via the CreateSubmission method). Once translators have translated given submissions they can upload the files to a shared Import folder and the system automatically imports those translations from their zip files using DownloadCompletedTranslations method. This provider is bit more complex than the example machine translator, so I won't copy&paste the code here; instead you can download both examples from the zip archive.

If you have any questions regarding customization of translation services, let me know via the comment section below.
Share this article on   LinkedIn

Comments