string-literal-i18n-messages
要求在纯文本标签上调用翻译API。
Docusaurus 提供了 docusaurus write-translations
API,它静态地提取标记为可翻译的文本标签。在 <Translate>
或 translate()
调用中使用的动态值将无法提取。此规则将确保所有翻译调用都是可静态提取的。
规则详情
此规则的错误代码示例
const text = 'Some text to be translated'
// Invalid <Translate> child
<Translate>{text}</Translate>
// Invalid message attribute
translate({message: text})
此规则的正确代码示例
// 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'})
何时不使用它
如果您不使用 i18n 功能,您可以禁用此规则。