A helper tool to sync translation messages with [Crowdin](https://crowdin.com/), using [`@formatjs/cli`](https://formatjs.io/docs/tooling/cli/) for message extraction.
npm install @mollie/crowdin-cliA helper tool to sync translation messages with Crowdin, using @formatjs/cli for message extraction.
``shell`
npm install @mollie/crowdin-clior
yarn add @mollie/crowdin-cli
The CLI now supports only three commands: sync, delete-branch, and delete-stale-branches.
Create a .env file in your project root and add your Crowdin personal access token:
`shell`
CROWDIN_PERSONAL_ACCESS_TOKEN=your-token
Add these scripts to your package.json (replace with your actual Crowdin project ID):
`json`
{
"crowdin:sync": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:upload": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:download": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:delete-branch": "mollie-crowdin delete-branch --project-id
"crowdin:delete-stale-branches": "mollie-crowdin delete-stale-branches --project-id
}
- Use --skip-download to only upload messages.--skip-upload
- Use to only download translations.
#### sync
Scan the directory for new messages and upload them to Crowdin, optionally downloading translations and running pre-translation.
Common options:
- --typescript — Write to TypeScript files (.ts)--skip-upload
- — Skip the upload step (download only)--skip-download
- — Skip the download step (upload only)--branch-name, -b
- — Crowdin branch name (defaults to current Git branch)--project-id, -pi
- — Required. Crowdin project ID--languages, -l
- — Comma-separated list of target languages (e.g. de,fr,nl). If not provided, all enabled languages are used (i.e., all languages enabled in your Crowdin project).--pre-translate, -pt
- — Whether to generate pre-translations for the uploaded files--pre-translate-languages, -ptl
- — Comma-separated list of languages to pre-translate. If not provided, all enabled languages are used (i.e., all languages enabled in your Crowdin project).--pre-translate-method, -ptm
- — Pre-translate method to use. Options: 'ai', 'mt', 'tm'--pre-translate-engine-id, -ptei
- — Engine ID for machine pre-translation--pre-translate-prompt-id, -ptpi
- — AI prompt ID for pre-translation--create-tasks, -t
- — Type of tasks to create
#### delete-branch
Delete a branch in Crowdin.
- --branch-name, -b — Crowdin branch to be deleted--delete-tasks, -dt
- — Whether to delete any associated tasks--project-id, -pi
- — Required. Crowdin project ID
#### delete-stale-branches
Delete branches in Crowdin older than a specified number of days.
- --days, -d — Number of days to consider a branch stale (required)--delete-tasks, -dt
- — Whether to delete any associated tasks--project-id, -pi
- — Required. Crowdin project ID
#### About --languages and --pre-translate-languages
- --languages / -l:
Controls which languages are downloaded from Crowdin or targeted for operations.
Example:
`shell`
mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
Only German and French translations will be processed.
- --pre-translate-languages / -ptl:
Controls which languages will receive pre-translation when uploading or syncing.
Example:
`shell`
mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
Only German and French will be pre-translated.
If not provided, both options default to all enabled languages in your Crowdin project.
By default, @mollie/crowdin-cli uses the current Git branch name for Crowdin. --branch-name
Override with or -b:
`shell`
mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
To write downloaded messages to TypeScript files, use the --typescript flag:
`shell`
mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
---
Version 4 of @mollie/crowdin-cli introduces a simplified CLI and changes to configuration and commands. Here’s what you need to know to upgrade:
- Commands:
Only three commands remain: sync, delete-branch, and delete-stale-branches. upload
The previous , download, and collect commands are now handled by sync with flags.
- Environment Variables:
- You no longer need to set CROWDIN_PROJECT_ID or CROWDIN_LANGUAGES in your .env file.--project-id
- Always provide the project ID via the or -pi option.--languages
- Use the /-l and --pre-translate-languages/-ptl flags for language selection.
- Scripts:
Replace old scripts with the new unified sync command and flags:
`json`
{
"crowdin:sync": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:upload": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:download": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:delete-branch": "mollie-crowdin delete-branch --project-id
"crowdin:delete-stale-branches": "mollie-crowdin delete-stale-branches --project-id
}
- Use --skip-download to only upload messages.--skip-upload
- Use to only download translations.
- Branch Name:
The CLI now defaults to the current Git branch name.
Override with --branch-name or -b.
- TypeScript Output:
To write downloaded messages to TypeScript files, use the --typescript flag with sync.
Old v3 scripts:
`json`
{
"crowdin:download": "mollie-crowdin download",
"crowdin:upload": "mollie-crowdin upload './src/*/!(.{d,test}).ts'",
"crowdin:delete-branch": "mollie-crowdin delete-branch"
}
New v4 scripts:
`json`
{
"crowdin:sync": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:upload": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:download": "mollie-crowdin sync './src/*/!(.{d,test}).ts' --project-id
"crowdin:delete-branch": "mollie-crowdin delete-branch --project-id
}
Old environment variables:
`shell`
CROWDIN_PERSONAL_ACCESS_TOKEN=your-token
CROWDIN_PROJECT_ID=your-project-id
CROWDIN_LANGUAGES=nl,en-US,fr,fr-BE
New environment variables:
`shell`
CROWDIN_PERSONAL_ACCESS_TOKEN=your-token
(Provide project ID and languages via CLI options.)
---
Install dependencies and set up your environment:
`shell``
nvm install