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 功能,您可以停用此規則。