string-literal-i18n-messages
Require Docusaurus translation APIs to receive hardcoded message strings.
Targeted pattern scopeโ
This rule checks the imported default Translate component, the named translate function, their aliases, and equivalent namespace-member usages from @docusaurus/Translate.
What this rule reportsโ
This rule checks actual imports from @docusaurus/Translate and reports:
- dynamic children inside the imported
Translatecomponent - calls to the imported
translatefunction whose first argument is not an object - explicit
messageproperties that are not string literals or substitution-free template literals
It recognizes aliases and namespace imports and ignores shadowed identifiers. Object arguments without a message property remain valid because other translation API fields can be composed separately.
Why this rule existsโ
Docusaurus extracts hardcoded messages and treats runtime values as placeholders. Dynamic message definitions cannot be extracted reliably and make translation catalogs unstable.
โ Incorrectโ
import Translate, { translate } from "@docusaurus/Translate";
const title = translate({ message: pageTitle });
const greeting = <Translate>Hello {name}</Translate>;
โ Correctโ
import Translate, { translate } from "@docusaurus/Translate";
const title = translate(
{ message: "Documentation for {product}" },
{ product: productName }
);
const greeting = <Translate values={{ name }}>{"Hello {name}"}</Translate>;
Behavior and migration notesโ
This rule is diagnostic-only. Moving dynamic values into values changes the translation contract and requires a deliberate message-placeholder choice.
The rule is enabled by recommended, strict, all, and experimental, and is also available through docusaurus2.configs.i18n.
ESLint flat config exampleโ
import docusaurus2 from "eslint-plugin-docusaurus-2";
export default [docusaurus2.configs.i18n];
When not to use itโ
Do not use this rule when a custom wrapper intentionally accepts runtime-computed messages instead of Docusaurus message extraction.
Rule catalog ID: R126