Skip to main content
Glot supports inline comment directives to suppress specific issues and declare dynamic key usage. Use these when you intentionally want to keep hardcoded text, keep an identical translation value, or handle dynamic translation keys.

Available Directives

Line Suppression

Use glot-disable-next-line to suppress issues for the next line:
The comment must appear on the line immediately before the hardcoded text.

Block Suppression

Use glot-disable and glot-enable to suppress a section:
Everything between glot-disable and glot-enable is ignored.

File-Level Suppression

Place glot-disable on the first or second line to disable the entire file:
File-level suppression only works if glot-disable appears on line 1 or 2 of the file.

JSX Comments

In JSX context, use JSX comment syntax:

Mixed Contexts

You can mix JavaScript and JSX comments:

Block Behavior

Nesting

Blocks cannot be nested. The first glot-enable closes the block:

Same-Line Enable

Code on the same line as glot-enable is checked:

Unclosed Blocks

An unclosed glot-disable suppresses everything after it:

Dynamic Key Declaration

Use glot-message-keys to declare which translation keys are used dynamically. This is essential for dynamic keys that cannot be statically analyzed.

Why Use This?

When you use dynamic keys like t(`items.${type}`), glot cannot determine which keys are actually used. This causes two problems:
  1. The check command reports a dynamic key warning
  2. The clean command refuses to run (to prevent accidental key deletion)
Using glot-message-keys solves both problems by explicitly declaring which keys are used.
Instead of manually adding glot-message-keys comments, use the fix command to auto-insert them:
This is especially useful when you have many dynamic keys. See glot fix for details.

Syntax

JavaScript/TypeScript comments:
JSX comments:
Astro template comments:
The directive applies to the next line of code.

Pattern Types

Literal Keys

Declare exact key names:

Glob Patterns

Use * as a wildcard to match multiple keys:
Prefix wildcards like "*.title" are not supported. The wildcard must appear after at least one segment.

Dynamic Key Use Cases

Conditional Keys

Array Iteration

Object Property Access

How It Works with Clean

Keys declared via glot-message-keys are marked as “used” in glot’s analysis:
  • The check command no longer warns about the dynamic key
  • The clean command can run safely because it knows which keys are in use
  • Declared keys will not be accidentally deleted as “unused”
This is more precise than using glot-disable-next-line, which only suppresses the issue without telling glot which keys are actually used.

Use Cases

Third-Party Components

When using components that require hardcoded text:

Development Placeholders

Temporary text during development:
Text that shouldn’t be translated:

Legacy Code

Sections being migrated gradually:

Baseline Command

Instead of manually adding directives, use the baseline command:
This is useful when adopting glot in an existing project.

Fix Command

For dynamic translation keys, the fix command automatically inserts glot-message-keys comments:
This analyzes template literal keys like t(`${prefix}.label`) and inserts appropriate patterns.
See glot fix for more options and details.

Best Practices

Be Specific

Prefer glot-disable-next-line over blocks when possible

Add Context

Include a comment explaining why suppression is needed

Use glot-message-keys for Dynamic Keys

Prefer declaring keys over disabling checks for dynamic key usage

Review Regularly

Periodically check suppressed items to see if they can be fixed

Track in CI

Monitor the count of suppressed items over time

Example with Context

Fix Command

Auto-insert glot-message-keys comments

Clean Command

Remove unused translation keys safely

Baseline Command

Auto-insert suppression comments

Configuration

Global ignore patterns