Skip to main content
Version: 3.5.1

string-literal-i18n-messages

强制在纯文本标签上调用翻译 API。

¥Enforce translate APIs to be called on plain text labels.

Docusaurus 提供 docusaurus write-translations API,它可以静态提取标记为可翻译的文本标签。<Translate>translate() 调用中使用的动态值将无法提取。此规则将确保所有翻译调用都是静态可提取的。

¥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.

规则详情

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

何时不使用它

¥When Not To Use It

如果你不使用 国际化功能,则可以禁用此规则。

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

进一步阅读

¥Further Reading