Custom MT
This module helps you connect machine translation engines not yet supported by Crowdin.
Custom MT Module Read more on the Crowdin Developer Portal.
Sample
const crowdinModule = require('@crowdin/app-project-module');
const configuration = { baseUrl: 'https://123.ngrok.io', clientId: 'clientId', clientSecret: 'clientSecret', name: 'Sample App', identifier: 'sample-app', description: 'Sample App description', dbFolder: __dirname, imagePath: __dirname + '/' + 'logo.png', customMT: { withContext: true, translate: async (client, context, projectId, source, target, strings) => { const translations = ['hello', 'world'];
if (source === 'fr') { throw 'Source language is not supported by the model'; }
return translations; }, validate: (client) => { console.log('validate'); } }};
crowdinModule.createApp(configuration);
Configuration
Parameter | Description | Allowed values | Default value |
---|---|---|---|
withContext | If true , strings will be received as objects. | true , false | false |
translate
Function
Called when the module is requested to translate strings.
Parameters
client
- Crowdin API client.context
- Context object.projectId
- Crowdin project ID.source
- Source language.target
- Target language.strings
- Array of strings to translate.
Return Value
The function must return an array of translated strings.
validate
Function
This function is optional. It is called when the module is initialized to validate if the module is correctly configured.
Parameters
client
- Crowdin API client.
Return Value
The function must return nothing.
Error Handling
In case of an error, the function must throw an error with a message. The message will be displayed in the Crowdin UI.