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
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: [] }; }, buildFile: async (file, req, strings, client, context, projectId) => { // build logic
const contentFile = '<content>'; return { contentFile } } }};
crowdinModule.createApp(configuration);
Also, custom file format module can support strings 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
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 automatically upload translations. | 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
This function is used to parse the source file content.
Parameters
file
- File object.req
- Request object.client
- Crowdin API client.context
- Context object.projectId
- Crowdin project ID.
Return Value
Returns an object with the following structure:
{ strings: [], error: 'Some error message'}
The error
field is optional. If it’s present, the file will be marked as failed.
buildFile
Function
This function is used to build the translation file content.
Parameters
file
- File object.req
- Request object.strings
- Strings array.client
- Crowdin API client.context
- Context object.projectId
- Crowdin project ID.
Return Value
Returns an object with the following structure:
{ contentFile: '<content>'}
exportStrings
Function
This function is used to export string translations in format different from the source file format.
Parameters
req
- the request object.strings
- the strings array.client
- the Crowdin API client.context
- the context object.
Return Value
Returns an object with the following structure:
{ contentFile: '<content>'}