Skip to content

Custom Spellchecker

This module allows you to add custom spellcheckers to verify translations against specific rules that are not supported by default.

index.js
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',
customSpellchecker: {
getSupportedLanguage: async ({ client, context }) => {
return [
{
code: 'en',
name: 'English'
},
{
code: 'uk',
name: 'Ukrainian'
}
];
},
runSpellCheck: async ({ client, context, language, texts }) => {
// language = 'en';
// texts = [ 'I have an appple', 'And many oranges' ];
// some spelling logic
return {
texts: [
{
text: 'I have an appple',
matches: [
{
category: 'typos',
message: 'Found a grammar error',
shortMessage: 'Grammar error',
offset: 10,
length: 6,
replacements: [
'apple'
]
}
]
},
{
text: 'And many oranges',
matches: []
}
]
}
}
}
};
crowdinModule.createApp(configuration);

The custom spellchecker application requires implementation of two functions to work properly.

Called when retrieving the list of languages supported by the custom spellchecker.

An array of objects with the following structure:

{
code: string,
name: string
}

Called when running the spellchecker against the provided texts.

  • client - Crowdin API client.
  • context - Context object.
  • language - Language code.
  • texts - Array of texts to check.

It should return an object with the following structure:

{
texts: [
{
text: string,
matches: [
{
category: string,
message: string,
shortMessage: string,
offset: number,
length: number,
replacements: string[]
}
]
}
]
}

Read more about available categories.