Code Snippet for Custom QA Checks

The custom quality assurance (QA) checks help customers and translators to correct errors in spelling, punctuation, terminology, formatting, and more. Code Snippet is a piece of code that helps to create custom QA checks and integrate them to Crowdin.

Code Snippet Parameters

Code Snippet is Javascript-based. It Includes a crowdin object and a number of properties. To create the code snippet, use this object template for code input:

object crowdin {
 object file {
   string name,
   string fullName,
   string branch,
   string type
 }
 string sourceLanguage,
 string targetLanguage,
 object context {
   ?int maxLength,
   ?string pluralForm
 },
 string contentType,
 string source,
 string translation
}

Find the example of a custom QA check code snippet in Crowdin Script Editor. Use the link to see the structure of code snippet, edit it with your data and verify your code is correct.

Code Snippet Request

The code snippet request includes the keys listed below:

  1. file.name – source file name
  2. file.fullName – full path to the source file in the project (excluding branch if any)
  3. file.branch – branch name the source file is stored in
  4. file.type – source file type
  5. sourceLanguageCrowdin’s code for the project source language
  6. targetLanguageCrowdin’s code for the project target language
  7. source – source text
  8. translation – translated string
  9. context.maxLength – maximum length of the translated string
  10. context.pluralForm – pluralForm indicates which plural form is being translated right now
  11. contentType – string can include one of the 3 types:

    • text/plain
    • application/vnd.crowdin.text+plural
    • application/vnd.crowdin.text+icu

Check out the example of code snippet request:

{
   "file": {
     "name": "strings.json",
     "fullName": "backend/strings.json",
     "branch": "master",
     "type": "json"
   }
   "sourceLanguage": 'en',
   "targetLanguage": 'de',
   "context": {
       "pluralForm": 'one',
   },
   "contentType": 'application/vnd.crowdin.text+plural',
   "source": '{"one":"Password", "other":"Passwords"}',
   "translation": 'das Passwort '
}

Code Snippet Response

After running the code snippet, it should return the response whether the custom QA checks have passed successfully or failed:

  • The response object should contain boolean success property indicating whether QA checks have passed. For instance:
{
  "success": true
}
  • In case the QA checks failed, the property “message” will be displayed to the translator. For example:
{
  "success": false,
  "message": "The sentence starts with space, please remove 1 space at the beginning of the translation.",
  "fixes": [
     {
          "from_pos": 0,
          "to_pos": 1,
          "replacement": ""
     }
  ]
} 
  • Crowdin QA checks can also return the mistakes and automatic fix instructions to the editor. If possible, it is recommended to include fixes property (an array of objects) since it can save a lot of time and effort for translators.
{
     "from_pos": 0,
     "to_pos": 1,
     "replacement": ""
}

The from_pos is a character position in the translation string where the replacement starts. The to_pos is the end of character position. The replacement property is the text that should be placed between from_pos and to_pos.

See Also

Was this article helpful?