Skip to content

Translations Alignment

The translations alignment app lets you align translations with source strings after export. It receives source strings and translations, and should return aligned translations mapped to source string IDs.

Sample

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',
fileTranslationsAlignmentExport: {
filesFolder: `${__dirname}/db`,
signaturePatterns: {
fileName: "^.+\\..+$",
fileContent: ".*"
},
fileProcess: async (req, content, client, context, projectId) => {
// content.sourceStrings and content.translationStrings can be arrays of strings objects or Buffers
// Example minimal response: alignments for a subset of source strings
return {
strings: [
{ sourceStringId: 1, text: 'Aligned translation for string #1' },
{ sourceStringId: 2, text: 'Aligned translation for string #2' }
]
};
}
}
};
crowdinModule.createApp(configuration);

Configuration

Parameter
Description
filesFolderFolder where large files are temporarily stored.
signaturePatternsContains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI or API.
storeFileOptional handler to store large responses and return a URL to download them.

fileProcess Function

This function is called for running translations alignment.

Parameters

  • req - Request object.
  • content - Object containing two fields: sourceStrings and translations (arrays or Buffers).
  • client - Crowdin API client.
  • context - Context object.
  • projectId - Crowdin project ID.

Return Value

Return an object with the following structure:

{
translations?: {
sourceStringId: number,
text: string | { one: string, other?: string, few?: string, many?: string }
}[],
error?: string
}

Description:

  • translations - aligned translations mapped to the source string IDs. If the response is large, the module will store it and return a URL internally.
  • error - optional, should contain an error message if the processor encounters an error.