# react-core-linter: 静态字符串 URL: https://generaltranslation.com/zh/docs/react-core-linter/rules/static-string.mdx --- title: 静态字符串 description: 要求在翻译函数中使用静态字符串 --- ## 概述 确保 [`gt`](/docs/react/api/strings/use-gt) 和 [`msg`](/docs/react/api/strings/msg) 等翻译函数只接受静态字符串。 ## 参考 ### 选项 | 选项 | 类型 | 默认值 | 描述 | | ------ | ---------- | ----------------------------------------------------------------------------------------- | --------------- | | `libs` | `string[]` | `["gt-react", "gt-next", "gt-react-native", "gt-i18n", "@generaltranslation/react-core"]` | 要检查其中翻译函数的库模块数组 | *** ## 示例 ### staticStringRequired 注册函数仅接受静态字符串。 #### ❌ 错误 ```jsx const gt = useGT(); const dynamicKey = 'Hello'; gt(dynamicKey); ``` #### ✅ 正确 ```jsx const gt = useGT(); gt('Hello'); ``` ### variableInterpolationRequired 不允许动态拼接字符串。请改用 ICU 风格的变量插值。 #### ❌ 错误 ```jsx const gt = useGT(); gt(`Hello ${name}!`); gt('Hello ' + name); ``` #### ✅ 正确 ```jsx const gt = useGT(); gt('Hello {name}!', { name }); ``` *** ## 设置 ```json { "@generaltranslation/react-core-linter/static-string": ["error", { "libs": ["gt-react", "gt-next", "gt-react-native"] }] } ```