跳到主要内容

字符串字面量国际化消息

强制在纯文本标签上调用翻译 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'})

何时不使用

如果您没有使用 国际化功能,可以禁用此规则。

进一步阅读