|
||
To develop a custom human translation service, you need to define a class that inherits from AbstractHumanTranslationService (found in the CMS.TranslationServices namespace).
The service class must override and implement the following abstract methods:
Method |
Description |
IsAvailable |
Checks whether the service is appropriately configured and ready to be used. For example, you can confirm that valid connection credentials are specified for the service in the website settings or check whether there is sufficient credit to perform translations.
When translating documents, users can only choose the service if the IsAvailable method returns a true value. |
IsLanguageSupported |
Checks whether the service supports translation to a specific language.
The system calls this method before creating new translation submissions for the service. Users can only create submissions if the IsLanguageSupported method of the selected service returns a true value for the target language. |
CreateSubmission |
Delivers the translation assignment to the translators. Called when creating new translation submissions for the service or resubmitting existing ones. |
CancelSubmission |
Executed when a user cancels a translation submission in CMS Desk -> Tools -> Translations.
Depending on the type of the service, you can delete the submission's physical file, call the appropriate service API or otherwise inform the translators that the submission has been canceled. |
DownloadCompletedTranslations |
Retrieves translated content from the service and imports it into the submission tickets.
The system automatically calls this method when updating the status of translation submissions, which can be triggered by:
•Users clicking Update statuses in CMS Desk -> Tools -> Translations •Execution of the Translation retrieval scheduled task
|
This example shows the implementation of a translation service that saves translation submissions into zip packages and exports them into a designated folder. It also provides a way to automatically load completed translations from an import folder. This sample service is a simplified version of the default Manual translation service.
1. Open your web project in Visual Studio and add a new class into the App_Code folder (or Old_App_Code if the project is installed as a web application). For example, name the class SampleTS.cs.
2. Change the class declaration and add references according to the following code:
[C#]
using System; |
3. Add the following properties into the class:
[C#]
/// <summary> |
The ExportFolder and ImportFolder properties load the translation folder paths from the website settings. If the setting values are not available, the properties return default folder paths. The SiteName property used to build the setting key names is inherited from the parent class. It gets the code name of the site from which the translation was submitted.
4. Define the required methods inside the class:
IsAvailable
[C#]
/// <summary> |
The sample service only needs to know the paths for its import and export folders, but it uses default paths if the values are not specified through the settings. The method returns a true value to indicate that the service is always ready.
IsLanguageSupported
[C#]
/// <summary> |
CreateSubmission
[C#]
/// <summary> |
The TranslationServiceHelper.WriteSubmissionInZip method creates the zip archive with the translation assignment. The archive contains the source text of the submitted documents in XLIFF format and an HTML instructions file with the details entered for the translation.
CancelSubmission
[C#]
/// <summary> /// Cancels the specified submission. /// </summary> /// <param name="submission">Info object representing the canceled submission</param> public override string CancelSubmission(TranslationSubmissionInfo submission) { try { if (submission != null) { // Tries to delete the assignment zip file (loads the file name from the submission ticket ID). string path = Path.Combine(this.ExportFolder, submission.SubmissionTicket); if (File.Exists(path)) { File.Delete(path); } } } catch (Exception ex) { TranslationServiceHelper.LogEvent(ex); return ex.Message; } return null; } |
DownloadCompletedTranslations
[C#]
/// <summary> |
The TranslationServiceHelper.ImportXLIFFfromZIP method loads the translated content from all XLIFF files in the zip package and saves it into the submission ticket.
5. Follow the instructions in the Loading service classes from App_Code topic to ensure that the application can access the custom class.
Once you have implemented the class with the required functionality, you need to register the translation service as an object in Kentico CMS:
1. Go to Site Manager -> Development -> Translation services and click New translation service.
2. Enter the following values into the service's properties:
•Display name: Sample translation service
•Service provider assembly name: App_Code
•Service provider class name: SampleTS
•Service is enabled: yes (checked)
•Service supports submitting instructions - yes
•Supports prioritizing of submissions - yes
•Supports submission deadlines - yes
Click Save.
The service is now ready to be used.
To allow administrators to configure the import and export folder paths of the service, you need to create custom settings:
1. Go to Site Manager -> Development -> Custom settings and click New settings group.
2. Enter the following names for the group:
•Display name: Sample translation paths
•Code name: SampleTranslationPaths
Click Save.
3. Click New settings key under the new Sample translation paths section and define two setting keys:
•Display name: Translation export folder
•Code name: SampleTranslationExportFolder (matches the name of the key loaded by the ExportFolder property in the code of the sample service class)
•Description: Sets the path of the folder where the system creates translation submissions. If empty, the ~/App_Data/Translations/Export/ folder is used.
•Type: String
•Display name: Translation import folder
•Code name: SampleTranslationImportFolder (matches the name of the key loaded by the ImportFolder property in the code of the sample service class)
•Description: Sets the path of the folder from which the system loads completed translation packages. If empty, the ~/App_Data/Translations/Import/ folder is used.
•Type: String
Click Save for each key.
You can now set the service's folder paths for specific websites in Site Manager -> Settings -> Custom settings.
When submitting documents for translation, the dialog offers the Sample translation service as one of the translation options.
Submitting a document for translation using the sample service
Try translating a document using the custom service:
1. Click Submit for translation in the New culture version dialog. The system creates a new submission and adds the translation zip package into the specified export folder.
2. Translate the content and add the modified .xlf file into a new zip package (with the same name as the export zip file). Place the zip package into the import folder.
3. Go to CMS Desk -> Tools -> Translations and click Update statuses. The service imports the translated content and switches the matching submission to the Translation ready status.
4. Click the Process submission action of the submission. The system transfers the translated content into the corresponding document and changes the submission status to Translation imported.
The document is now available in the target language.