# string-literal-i18n-messages

Enforce translate APIs to be called on plain text labels.

Docusaurus offers the [`docusaurus write-translations`](/guides/cli#docusaurus-write-translations-sitedir) API, which statically extracts the text labels marked as translatable. Dynamic values used in `<Translate>` or `translate()` calls will fail to be extracted. This rule will ensure that all translate calls are statically extractable.

## Rule Details

Examples of **incorrect** code for this rule:

```js
const text = 'Some text to be translated'

// Invalid <Translate> child
<Translate>{text}</Translate>

// Invalid message attribute
translate({message: text})
```

Examples of **correct** code for this rule:

```js
// Valid <Translate> child
<Translate>Some text to be translated</Translate>

// Valid message attribute
translate({message: 'Some text to be translated'})

// Valid <Translate> child using values object as prop
<Translate values={{firstName: 'Sébastien'}}>
  {'Welcome, {firstName}! How are you?'}
</Translate>

// Valid message attribute using values object as second argument
translate({message: 'The logo of site {siteName}'}, {siteName: 'Docusaurus'})
```

## When Not To Use It

If you're not using the [i18n feature](/guides/i18n-i18n-introduction), you can disable this rule.

## Further Reading

- https://docusaurus.io/docs/docusaurus-core#translate
- https://docusaurus.io/docs/docusaurus-core#translate-imperative

## Related pages

- [no-html-links](./api-misc-eslint-plugin-no-html-links.md)
- [no-untranslated-text](./api-misc-eslint-plugin-no-untranslated-text.md)
- [prefer-docusaurus-heading](./api-misc-eslint-plugin-prefer-docusaurus-heading.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
