# react-core-linter: static-string URL: https://generaltranslation.com/ja/docs/react-core-linter/rules/static-string.mdx --- title: static-string 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"] }] } ```