Custom File Format
Custom File Format Apps allow you to add support for new custom file formats. It’s implemented by delegating a source file parsing to an app with a custom file format module.
Custom File Format Module Read more on the Crowdin Developer Portal.
Sample
Section titled “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', customFileFormat: { filesFolder: __dirname, type: 'type-xyz', signaturePatterns: { fileName: '^.+\.xml$' }, parseFile: async (file, req, client, context, projectId) => { // parse logic
return { strings: [], previewFile: generatePreviewFile(req.file, strings), }; }, buildFile: async (file, req, strings, client, context, projectId) => { // build logic
const contentFile = '<content>'; return { contentFile } } }};
crowdinModule.createApp(configuration);Also, the custom file format module can support string export:
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', customFileFormat: { filesFolder: __dirname, type: 'type-xyz', stringsExport: true, multilingualExport: true, extensions: [ '.resx' ], exportStrings: async (req, strings, client, context, projectId) => { const file = req.file; // export logic return { contentFile: '' } } }};
crowdinModule.createApp(configuration);Read more about Strings Array Structure.
Configuration
Section titled “Configuration”| Parameter | Description | Default value |
|---|---|---|
type | The type parameter value for a custom file format. Used for a custom format file upload via API. | - |
filesFolder | Folder where large files are temporarily stored. | - |
multilingual | Used to combine the content of multiple languages into one request when uploading and downloading translations in your Crowdin project. | false |
autoUploadTranslations | Defines whether to upload translations automatically. | false |
signaturePatterns | Contains fileName and/or fileContent regular expressions used to detect file type when uploading a new source file via UI or API. | - |
customSrxSupported | Enable custom SRX segmentation. | false |
stringsExport | Enable strings export. | false |
extensions | File extensions (used for strings export). | [] |
multilingualExport | enable multi-language strings export (for file formats that support multiple languages in one file). | false |
parseFile Function
Section titled “parseFile Function”This function is used to parse the content of the source file.
Parameters
Section titled “Parameters”file- File object.req- Request object.client- Crowdin API client.context- Context object.projectId- Crowdin project ID.
Return Value
Section titled “Return Value”Returns an object with the following structure:
{ strings: [], previewFile?: string, error: 'Some error message'}Description:
strings- the processed strings.previewFile- optional, content that will be displayed as a preview in the Crowdin Editor.error- optional, and if it’s present, the file will be marked as failed.
buildFile Function
Section titled “buildFile Function”This function is used to build the content of the translation file.
Parameters
Section titled “Parameters”file- File object.req- Request object.strings- Strings array.client- Crowdin API client.context- Context object.projectId- Crowdin project ID.
Return Value
Section titled “Return Value”Returns an object with the following structure:
{ contentFile: '<content>'}exportStrings Function
Section titled “exportStrings Function”This function is used to export string translations in a format different from the source file format.
Parameters
Section titled “Parameters”req- the request object.strings- the strings array.client- the Crowdin API client.context- the context object.
Return Value
Section titled “Return Value”Returns an object with the following structure:
{ contentFile: '<content>'}