作成:2026-06-13最終更新:2026-06-13
このドキュメントをあなたの好きなAIアシスタントに参照してくださいChatGPTClaudeDeepSeekGoogle AI modeGeminiPerplexityMistralGrok
このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します
バージョン履歴
- "Init history"v9.0.02026/6/13
このページのコンテンツは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
React IntlからIntlayerへの移行
React アプリケーションが react-intl (FormatJS) を使用している場合、Intlayer への移行は簡単です。互換性レイヤーは ICU MessageFormat と既存のすべての Formatted* コンポーネントをシームレスに処理します。
やること
まずプロジェクトで初期化コマンドを実行します:
bash
コードをコピー
コードをクリップボードにコピー
npx intlayer init次に、設定で Intlayer Vite または Next.js プラグインをセットアップします。このプラグインは、react-intl のインポートを @intlayer/react-intl にリダイレクトするためのビルド時エイリアスを注入します。
vite.config.ts
コードをコピー
コードをクリップボードにコピー
import { defineConfig } from "vite";import react from "@vitejs/plugin-react";import reactIntlVitePlugin from "@intlayer/react-intl/plugin";export default defineConfig({ plugins: [react(), reactIntlVitePlugin()],});内部的な動作
bundler プラグインは react-intl を @intlayer/react-intl にエイリアスします。大きな JSON ファイルを手動でパースして IntlProvider でアプリをラップする代わりに、Intlayer プラグインは静的にキーを抽出し、実行時に Intlayer ディクショナリを使用します。
内部的には以下のように動作します:
- ICU MessageFormat: Intlayer は
resolveMessage(..., 'icu')リゾルバを使用しており、ICU の複数形化、選択、日付/数値フォーマット、リッチテキストタグをネイティブに完全にサポートしています。 - Method & JSX callers:
intl.formatMessage({ id: 'a.b' })と<FormattedMessage id="a.b">は Intlayer コンパイラプラグイン (@intlayer/babel/@intlayer/swc) によって識別され、フラットなドット記号キーを変換して最初のセグメントが Intlayer ディクショナリキーに正しく解決されるようにします。 - Formatters:
<FormattedNumber>、<FormattedDate>など、ネイティブなcore/formattersをIntlを使用してブリッジします。