fix command automatically inserts glot-message-keys comments for dynamic translation keys that cannot be statically analyzed. This declares expected keys so that glot can track them properly.
Usage
Options
Actually insert comments. Without this flag, glot runs in dry-run mode and
only shows what would be changed.
Override the source code root directory. Defaults to the value from configuration file.
Override the messages directory path. Defaults to the value from configuration file.
Override the primary locale. Defaults to the value from configuration file.
Enable verbose output for debugging.
Why Use Fix?
When you use dynamic translation keys liket(`${prefix}.label`), glot cannot determine which keys are used at build time. This causes two problems:
- Dynamic key warnings - The
checkcommand reports these as warnings - Clean refuses to run - The
cleancommand won’t run to prevent accidental key deletion
glot-message-keys comments that declare which keys are expected. The fix command automates this by:
- Analyzing your template literal keys
- Inferring appropriate glob patterns
- Inserting the correct comment syntax (JSX or JS)
What Gets Fixed
Template literals with expressions
Template literals with expressions
Keys using template literals with dynamic parts:
What cannot be fixed
What cannot be fixed
Pure variable keys cannot have patterns inferred:For these, you must manually add
glot-message-keys comments.Dry-Run Mode (Default)
Preview what comments would be inserted:Apply Changes
Insert the declaration comments:Result
Before:JSX vs Non-JSX Context
Glot automatically detects the context and uses the appropriate comment syntax: JSX context (inside JSX children):Pattern Inference
Glot infers patterns based on the template literal structure:| Template | Inferred Pattern |
|---|---|
`${var}.key` | Namespace.*.key |
`prefix.${var}` | Namespace.prefix.* |
`${a}.${b}.suffix` | Cannot infer (multiple expressions) |
Templates with multiple dynamic expressions cannot be automatically fixed because the pattern would be too broad. Add
glot-message-keys manually for these cases.Workflow
Handle Unfixable Keys
For any reported variable keys that couldn’t be fixed, manually add
glot-message-keys comments: