CLI tool for extracting, managing, and optionally syncing translation keys with Lynguist.com.
Scans your source code for translation function calls using AST parsing, merges new keys into your JSON translation files, and syncs with the Lynguist API.
npm install @vixen-tech/lynguist-cli --save-devpnpm add -D @vixen-tech/lynguist-cliyarn add -D @vixen-tech/lynguist-cliCreate a lynguist.config.js (or .json) in your project root:
export default {
sourceDir: './src',
translationsDir: './lang',
locales: ['en', 'fr'],
preset: 'next-intl',
lynguist: {
apiKey: process.env.LYNGUIST_API_TOKEN,
},
}The API token can also be set via the LYNGUIST_API_TOKEN environment variable in a .env or .env.local file.
| Option | Description | Default |
|---|---|---|
sourceDir |
Directory to scan for translation keys | — (required) |
translationsDir |
Directory for translation JSON files | lang |
locales |
Array of locale codes | — (required) |
preset |
Framework preset to use | — (required) |
extensions |
File extensions to scan (overrides preset) | — |
excludedDirs |
Directories to skip during scan | ['node_modules'] |
functions |
Custom translation function names (overrides preset) | — |
fileStrategy |
Override preset file layout (single-file or namespace-files) |
preset default |
lynguist.apiKey |
API token for Lynguist.com | — |
| Preset | Framework | Translation functions | Namespace source |
|---|---|---|---|
next-intl |
Next.js |
t(), useTranslations(), getTranslations()
|
useTranslations('Ns') / getTranslations('Ns')
|
react-i18next |
React / React Native |
t(), useTranslation()
|
useTranslation('ns') |
react-intl |
React |
formatMessage(), intl.formatMessage(), <FormattedMessage>
|
id prefix |
vue-i18n |
Vue / Nuxt |
$t(), t()
|
useI18n() scope |
svelte-i18n |
Svelte / SvelteKit |
$_(), $t(), $format()
|
flat keys |
Extract translation keys from source files.
npx lynguist scan # print found keys
npx lynguist scan --write # write keys to translation files
npx lynguist scan --write --prune # also remove unused keysScan and write keys to translation files (shortcut for scan --write).
npx lynguist merge
npx lynguist merge --pruneUpload local translation files to Lynguist.com.
npx lynguist uploadDownload translations from Lynguist.com and write them to disk, overwriting local files.
npx lynguist downloadScan, merge, and upload in one step.
npx lynguist sync
npx lynguist sync --prune| Variable | Description | Default |
|---|---|---|
LYNGUIST_API_TOKEN |
API token (fallback if not in config) | — |
LYNGUIST_TIMEOUT |
Request timeout in ms | 120000 |
import { scan, merge, upload, download, getPreset } from '@vixen-tech/lynguist-cli'MIT