Creation:2026-01-21Last update:2026-01-21
このドキュメントをあなたの好きなAIアシスタントに参照してくださいChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
バージョン履歴
- "Init doc"v8.0.02026/1/21
このページのコンテンツはAIを使用して翻訳されました。
英語の元のコンテンツの最新バージョンを見るEdit this doc
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy
Copy doc Markdown to clipboard
intlayer Fastify プラグインドキュメント
Fastify 用の intlayer プラグインは、ユーザーのロケールを検出し、Intlayer の関数を含むプロパティでリクエストオブジェクトを装飾します。また、リクエストコンテキスト内でグローバルな翻訳関数を使用できるようにします。
使用方法
ts
コードをコピー
コードをクリップボードにコピー
import Fastify from "fastify";import { intlayer } from "fastify-intlayer";const fastify = Fastify();fastify.register(intlayer);fastify.get("/", async (req, reply) => { const content = req.intlayer.t({ ja: "こんにちは", en: "Hello", fr: "Bonjour", }); return content;});説明
プラグインは次のタスクを実行します:
- ロケール検出: リクエスト(ヘッダー、クッキーなど)を分析して、ユーザーの優先ロケールを判定します。
- Request Decoration:
FastifyRequestオブジェクトにintlayerプロパティを追加します。含まれるもの:locale: 検出されたロケール。t: 翻訳関数。getIntlayer: 辞書を取得する関数。
- コンテキスト管理: 非同期コンテキストを管理するために
cls-hookedを使用し、グローバルな Intlayer 関数がリクエスト固有のロケールにアクセスできるようにします。