Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 1.21 KB

no-dynamic-i18n-messages.md

File metadata and controls

42 lines (28 loc) · 1.21 KB

enforce translate calls to be plain text labels (no-dynamic-i18n-messages)

Ensures that <Translate> children and the message attribute of translate function calls are hardcoded strings.

This is to ensure that static extraction of the text will work so it can be translatable. In-string dynamic placeholders are also possible using the values object.

Rule Details

Examples of incorrect code for this rule:

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:

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

Further Reading