Skip to main content
The 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

boolean
default:"false"
Actually insert comments. Without this flag, glot runs in dry-run mode and only shows what would be changed.
string
Override the source code root directory. Defaults to the value from configuration file.
string
Override the messages directory path. Defaults to the value from configuration file.
string
Override the primary locale. Defaults to the value from configuration file.
boolean
default:"false"
Enable verbose output for debugging.

Why Use Fix?

When you use dynamic translation keys like t(`${prefix}.label`), glot cannot determine which keys are used at build time. This causes two problems:
  1. Dynamic key warnings - The check command reports these as warnings
  2. Clean refuses to run - The clean command won’t run to prevent accidental key deletion
The solution is to add glot-message-keys comments that declare which keys are expected. The fix command automates this by:
  1. Analyzing your template literal keys
  2. Inferring appropriate glob patterns
  3. Inserting the correct comment syntax (JSX, HTML, or JS depending on context)

What Gets Fixed

Keys using template literals with dynamic parts:
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:
Output:
If there are unfixable variable keys, they are reported separately:

Apply Changes

Insert the declaration comments:
Output:

Result

Before:
After:

JSX vs Non-JSX Context

Glot automatically detects the context and uses the appropriate comment syntax: JSX context (inside JSX children):
Non-JSX context (regular JavaScript):
Astro template context:

Pattern Inference

Glot infers patterns based on the template literal structure:
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

1

Run Fix (Dry-Run)

Preview what comments would be inserted:
2

Review Changes

Check that the inferred patterns make sense for your use case.
3

Apply Changes

Insert the comments:
4

Handle Unfixable Keys

For any reported variable keys that couldn’t be fixed, manually add glot-message-keys comments:
5

Commit Changes

Commit the changes to your repository:

Directives

Learn about glot-message-keys syntax and patterns

Missing Keys

Understanding dynamic key detection

Check Command

Run i18n checks

Clean Command

Remove unused translation keys