Overview
The extraction process:- Scans your source files for
sayfunction calls - Extracts message IDs, default text, and context
- Generates or updates translation files in your specified format
- Preserves existing translations when re-running extraction
Configuration
Define Buckets
Buckets determine which files to scan and where to output translation files. Configure them in yoursaykit.config.ts:
saykit.config.ts
Bucket Properties
include
include
Array of glob patterns for files to scan. Supports standard glob syntax:
**matches any number of directories*matches any characters except/{ts,tsx}matches multiple extensions
exclude (optional)
exclude (optional)
Array of glob patterns to exclude from scanning:
output
output
Path template for generated files. Must include:
{locale}placeholder for the locale code{extension}placeholder for the file extension
src/locales/{locale}/messages.{extension}i18n/{locale}.{extension}translations/{locale}/LC_MESSAGES/messages.{extension}
formatter (optional)
formatter (optional)
Custom formatter for translation files. Defaults to the PO format.See Custom Formatters for details.
Running Extraction
Run the Extract Command
Extract messages from your configured buckets:Add flags for more control:
--verboseor-v: Show detailed extraction information--quietor-q: Suppress all output except errors
Output Format
The default PO format includes:- msgid: The source message text
- msgstr: The translated text (empty for new messages)
- msgctxt: Context to disambiguate identical strings
- Extracted comments: Custom ID or translator notes
- References: Source file locations where the message is used
Example with Context
Example with Custom ID
Workflow Tips
Re-running extraction is safe and non-destructive. Existing translations are preserved, and only new or changed messages are updated.
Development Workflow
- Write code using
sayfunctions - Run
npx saykit extractto generate/update translation files - Commit both source code and extracted files
- Translators work on the generated files
- Repeat as you add more messages
CI/CD Integration
Add extraction to your CI pipeline to catch missing translations:Multiple Buckets
Use multiple buckets to organize translations by feature or module:saykit.config.ts
Next Steps
- Learn about Custom Formatters for alternative file formats
- Explore Pluralization for handling countable messages
- See TypeScript for type-safe configuration