Skip to main content
Docusaurus

Search documentation

Type to search this documentation.

On this pageOverview

string-literal-i18n-messages

Enforce translate APIs to be called on plain text labels.

Docusaurus offers the docusaurus write-translations 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.

Examples of incorrect code for this rule:

JavaScript
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:

JavaScript
// 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'})

If you're not using the i18n feature, you can disable this rule.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu