ホームサンドボックスショーケースアプリ文書ブログ
    • English英語
      EN
    • русскийロシア語
      RU
    • 日本語日本語
      JA
    • françaisフランス語
      FR
    • 한국어韓国語
      KO
    • 中文中国語
      ZH
    • españolスペイン語
      ES
    • Deutschドイツ語
      DE
    • العربيةアラビア語
      AR
    • italianoイタリア語
      IT
    • British Englishイギリス英語
      EN-GB
    • portuguêsポルトガル語
      PT
    • हिन्दीヒンディー語
      HI
    • Türkçeトルコ語
      TR
    • polskiポーランド語
      PL
    • Indonesiaインドネシア語
      ID
    • Tiếng Việtベトナム語
      VI
    • українськаウクライナ語
      UK
    /
    フレームワークでドキュメントをフィルター
    Alt+←
    なぜIntlayer?
    始める
    コンセプト
    • Intlayerの仕組み
    • 設定
    • TestFillBuildWatchExtractLoginPushPullConfigurationListVersionEditorLiveDebugDoc ReviewDoc TranslateSDK
    • ビジュアルエディター
    • CMS
    • CI/CD統合
    • 翻訳複数形列挙条件性別挿入ファイルネスティングMarkdownHTML関数取得
    • ロケールごとのファイル
    • コンパイラー
    • 自動入力
    • テスト
    • バンドル最適化
    環境
    • Next.js 14とApp Router
      Next.js 15
      Next.js ロケールなし URL
      Next.jsとページルーター
      コンパイラ
    • Tanstack Start Solid
    • AstroおよびReact
      AstroおよびSvelte
      AstroおよびVue
      AstroおよびSolid
      AstroおよびPreact
      AstroおよびLit
      AstroおよびVanilla JS
    • React Router v7
      React Router v7 (fs-routes)
      Compiler
    • NuxtおよびVue
    • ViteおよびSolid
    • SvelteKit
    • ViteおよびPreact
    • ViteおよびVanilla JS
    • ViteおよびLit
    • Angular 19 (Webpack)
      Analog
    • React CRA
    • React NativeとExpo
    • Express.js
      NestJS
      Fastify
      Hono
      Adonis
    • LynxおよびReact
    Plugins
    • JSON
    • gettext (.po)
    VS Code拡張機能
    エージェント
    • MCPサーバー
    • エージェントのスキル
    リリース
    • v8
    • v7
    • v6
    ベンチマーク
    • Next.js
    • TanStack
    • Vue
    • Solid
    • Svelte
    ブログ
    質問をする
    1. Documentation
    2. コンセプト
    3. 自動入力
    作成:2025-03-13最終更新:2025-09-20
    このドキュメントをあなたの好きなAIアシスタントに参照してください
    ChatGPT
    Claude
    DeepSeek
    Google AI mode
    Gemini
    Perplexity
    Mistral
    Grok

    このページとあなたの好きなAIアシスタントを使ってドキュメントを要約します

    バージョン履歴

    1. "グローバル設定の追加"
      v6.0.02025/9/20
    2. "`{{fileName}}` 変数の追加"
      v6.0.02025/9/17
    3. "履歴の初期化"
      v5.5.102025/6/29

    このページのコンテンツはAIを使用して翻訳されました。

    英語の元のコンテンツの最新バージョンを見る
    このドキュメントを編集

    このドキュメントを改善するアイデアがある場合は、GitHubでプルリクエストを送信することで自由に貢献してください。

    ドキュメントへのGitHubリンク
    コピー

    ドキュメントのMarkdownをクリップボードにコピー

    自動入力コンテンツ宣言ファイルの翻訳

    自動入力コンテンツ宣言ファイルは、開発ワークフローを高速化する方法です。

    自動入力メカニズムは、コンテンツ宣言ファイル間の マスター・スレーブ 関係を通じて機能します。メイン(マスター)ファイルが更新されると、Intlayerはその変更を派生(自動入力された)宣言ファイルに自動的に適用します。

    src/components/example/example.content.ts
    コードをコピー

    コードをクリップボードにコピー

    import { Locales, type Dictionary } from "intlayer";const exampleContent = {  key: "example",  locale: Locales.ENGLISH,  autoFill: "./example.content.json",  content: {    contentExample: "これはコンテンツの例です", // コンテンツの例  },} satisfies Dictionary;export default exampleContent;

    こちらは autoFill 指示を使用したロケール別コンテンツ宣言ファイルです。

    次に、以下のコマンドを実行すると:

    bash
    コードをコピー

    コードをクリップボードにコピー

    npx intlayer fill --file 'src/components/example/example.content.ts'

    Intlayer は、メインファイルにまだ宣言されていないすべてのロケールを埋めて、派生した宣言ファイルを src/components/example/example.content.json に自動生成します。

    src/components/example/example.content.json
    コードをコピー

    コードをクリップボードにコピー

    {  "key": "example",  "content": {    "contentExample": {      "nodeType": "translation",      "translation": {        "fr": "Ceci est un exemple de contenu",        "es": "Este es un ejemplo de contenido",      },    },  },}

    その後、両方の宣言ファイルは単一の辞書にマージされ、標準の useIntlayer("example") フック(React)/ コンポーザブル(Vue)を使ってアクセス可能になります。

    自動補完されたファイル形式

    自動補完された宣言ファイルに推奨される形式は JSON であり、これによりフォーマットの制約を回避できます。ただし、Intlayer は .ts、.js、.mjs、.cjs などの他の形式もサポートしています。

    src/components/example/example.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: "./example.filled.content.ts",  content: {    // あなたのコンテンツ  },};

    これにより、以下のファイルが生成されます:

    plaintext
    コードをコピー

    コードをクリップボードにコピー

    src/components/example/example.filled.content.ts

    .js、.ts、および類似のファイルの生成は以下のように動作します:

    • ファイルがすでに存在する場合、Intlayer は AST(抽象構文木)を使用して各フィールドを特定し、欠落している翻訳を挿入します。
    • ファイルが存在しない場合、Intlayerはデフォルトのコンテンツ宣言ファイルテンプレートを使用して生成します。

    絶対パス

    autoFill フィールドは絶対パスもサポートしています。

    src/components/example/example.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: "/messages/example.content.json",  content: {    // あなたのコンテンツ  },};

    これにより、以下のファイルが生成されます:

    plaintext
    コードをコピー

    コードをクリップボードにコピー

    /messages/example.content.json

    ロケール別コンテンツ宣言ファイルの自動生成

    autoFill フィールドは、ロケール別のコンテンツ宣言ファイルの生成もサポートしています。

    src/components/example/example.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: {    fr: "./example.fr.content.json",    es: "./example.es.content.json",  },  content: {    // あなたのコンテンツ  },};

    これにより、2つの別々のファイルが生成されます:

    • src/components/example/example.fr.content.json
    • src/components/example/example.es.content.json
    この場合、オブジェクトにすべてのロケールが含まれていない場合、Intlayerは残りのロケールの生成をスキップします。

    特定のロケールの自動入力をフィルタリングする

    autoFill フィールドにオブジェクトを使用すると、フィルターを適用して特定のロケールファイルのみを生成できます。

    src/components/example/example.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: {    fr: "./example.fr.content.json",  },  content: {    // あなたのコンテンツ  },};

    これにより、フランス語の翻訳ファイルのみが生成されます。

    パス変数

    autoFill パス内で変数を使用して、生成されるファイルのターゲットパスを動的に解決することができます。

    使用可能な変数:

    • {{locale}} – ロケールコード(例: fr, es)
    • {{fileName}} – ファイル名(例: index)
    • {{key}} – 辞書キー(例: example)
    src/components/example/index.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: "/messages/{{locale}}/{{key}}.content.json",  content: {    // あなたのコンテンツ  },};

    これにより、以下のファイルが生成されます:

    • /messages/fr/example.content.json
    • /messages/es/example.content.json
    src/components/example/index.content.ts
    コードをコピー

    コードをクリップボードにコピー

    const exampleContent = {  key: "example",  autoFill: "./{{fileName}}.content.json",  content: {    // あなたのコンテンツ  },};

    これにより、以下のファイルが生成されます:

    • ./index.content.json
    • ./index.content.json
    コンパイラー
    テスト
    Alt+→

    このページについて

      ディスカッションは匿名で、よくある問題に対処するために定期的に確認されます。機能のアイデア、ドキュメントへのフィードバック、Intlayerに関することなど、お気軽にお聞かせください, このフィードバックをロードマップの作成と製品の改善に活用しています。

      import { Locales, type Dictionary } from "intlayer";const exampleContent = {  key: "example",  locale: Locales.ENGLISH,  autoFill: "./example.content.json",  content: {    contentExample: "これはコンテンツの例です", // コンテンツの例  },} satisfies Dictionary;export default exampleContent;
      npx intlayer fill --file 'src/components/example/example.content.ts'
      {  "key": "example",  "content": {    "contentExample": {      "nodeType": "translation",      "translation": {        "fr": "Ceci est un exemple de contenu",        "es": "Este es un ejemplo de contenido",      },    },  },}
      const exampleContent = {  key: "example",  autoFill: "./example.filled.content.ts",  content: {    // あなたのコンテンツ  },};
      src/components/example/example.filled.content.ts
      const exampleContent = {  key: "example",  autoFill: "/messages/example.content.json",  content: {    // あなたのコンテンツ  },};
      /messages/example.content.json
      const exampleContent = {  key: "example",  autoFill: {    fr: "./example.fr.content.json",    es: "./example.es.content.json",  },  content: {    // あなたのコンテンツ  },};
      const exampleContent = {  key: "example",  autoFill: {    fr: "./example.fr.content.json",  },  content: {    // あなたのコンテンツ  },};
      const exampleContent = {  key: "example",  autoFill: "/messages/{{locale}}/{{key}}.content.json",  content: {    // あなたのコンテンツ  },};
      const exampleContent = {  key: "example",  autoFill: "./{{fileName}}.content.json",  content: {    // あなたのコンテンツ  },};