# Translation Alignment

The translation 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.

[Translation Alignment Processing Module](https://support.crowdin.com/developer/crowdin-apps-module-translation-alignment/)

## Sample

```js ins="fileTranslationsAlignmentExport" title="index.js"
    import crowdinModule from '@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: import.meta.dirname,
      imagePath: import.meta.dirname + '/logo.png',
      fileTranslationsAlignmentExport: [
        {
          filesFolder: `${import.meta.dirname}/db`,
          signaturePatterns: {
            fileName: "^.+\\..+$",
            fileContent: ".*"
          },
          fileProcess: async ({ request, content, client, context, projectId }) => {
            // content.sourceStrings and content.translations 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);
    ```
  ```ts ins="fileTranslationsAlignmentExport" title="index.ts"
    import crowdinModule from '@crowdin/app-project-module';
    import type { ClientConfig } from '@crowdin/app-project-module';

    const configuration: ClientConfig = {
      baseUrl: 'https://123.ngrok.io',
      clientId: 'clientId',
      clientSecret: 'clientSecret',
      name: 'Sample App',
      identifier: 'sample-app',
      description: 'Sample App description',
      dbFolder: import.meta.dirname,
      imagePath: import.meta.dirname + '/logo.png',
      fileTranslationsAlignmentExport: [
        {
          filesFolder: `${import.meta.dirname}/db`,
          signaturePatterns: {
            fileName: "^.+\\..+$",
            fileContent: ".*"
          },
          fileProcess: async ({ request, content, client, context, projectId }) => {
            // content.sourceStrings and content.translations 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<div class="w-40"/> | Description                                                                                                                           |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `filesFolder`                | Folder where large files are temporarily stored.                                                                                      |
| `signaturePatterns`          | Contains `fileName` and/or `fileContent` regular expressions used to detect file type when uploading a new source file via UI or API. |
| `storeFile`                  | Optional handler to store large responses and return a URL to download them.                                                          |

### `fileProcess` Function

This function is called for running translation alignment.

#### Parameters

- `request` - Request object.
- `content` - Object containing two fields: `sourceStrings` and `translations` (arrays or Buffers).
- `client` - Crowdin API client.
- `context` - [Context object](/app-project-module/reference/context/).
- `projectId` - Crowdin project ID.

#### Return Value

Return an object with the following structure:

```yml
{
  translations?: {
    sourceStringId: number,
    text: string | { zero?: string, one?: string, two?: string, few?: string, many?: string, other?: 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.