Overview
Theextract command scans your source files for translatable messages and generates translation files in your configured format. It analyzes all files matching your bucket patterns, extracts message definitions, and writes them to locale-specific files.
Syntax
Options
Enable verbose logging to see detailed extraction progress, including each file processed and the number of messages found.
Suppress all logging output. Only errors will be displayed.
How It Works
1. Scanning Phase
The extract command uses theBucketExtractWorker to:
- Glob source files: Scans all files matching the
includepatterns in each bucket configuration - Parse with Babel: Analyzes each file to identify message definitions using the
@saykit/babel-plugin - Index messages: Collects all messages with their metadata (ID, context, comments, references)
2. Writing Phase
For each configured locale:- Source locale: Writes all extracted messages directly
- Other locales: Reconciles with existing translations to preserve translated content
- Merges duplicates: Combines messages with the same ID or hash, merging comments and file references
- Outputs files: Writes to the location specified in your bucket’s
outputpattern
Message Format
Extracted messages include:- message: The ICU-formatted source string
- translation: The translated string (preserved from existing files)
- id: Optional explicit message ID
- context: Optional context for disambiguation
- comments: Translator notes and comments from code
- references: Source file paths where the message appears
Examples
Basic extraction
Verbose extraction
Quiet extraction
Output Files
The command writes files according to your bucket configuration:locales/en.polocales/es.polocales/fr.po
Configuration
The extract command reads yoursaykit.config.ts file to determine:
- Buckets: Which files to scan (
include/excludepatterns) - Locales: Which locale files to generate
- Formatter: Output format (defaults to
.poformat via@saykit/format-po) - Source locale: The primary language of your messages
Existing translations are preserved when you re-run extract. Only new messages are added, and removed messages are excluded from the output.