著者:
    作成:2026-11-23最終更新:2026-11-23

    Intlayerでvinextサイトを翻訳する

    vinextは、Next.js APIをVite上で再実装したものです。app/ディレクトリ、next/*のインポート、proxy.tsはそのまま動作しますが、ビルドはTurbopackやwebpackではなくViteで実行されます。

    Intlayerは2つのパッケージでこの構成に組み込まれます。Next.jsで既にコンポーネントが使っているフック、プロバイダー、プロキシを提供するnext-intlayerと、ビルド側(辞書のコンパイル、ウォッチ、バンドルの最適化)を担うvite-intlayerです。

    独自のツールチェーンでNext.jsを動かしていますか?その場合はNext.js 16ガイドに従ってください。

    目次

    なぜ他の選択肢ではなくIntlayerなのか?

    next-intlやi18nextのようなソリューションと比べて、Intlayerには最適化が組み込まれています。

    同じnext-intlayerのコードがNext.jsでもvinextでも動作します。Server Componentsはサーバー上でコンテンツを解決し、Client Componentsはプロバイダー経由で読み取り、ロケールルーティングはproxy.tsから実行されます。2つのツールチェーン間の移行でコンポーネントを変更する必要はありません。

    巨大なJSONファイルをページに読み込む代わりに、必要なコンテンツだけを読み込みます。Viteプラグインが各useIntlayer呼び出しを、コンポーネントが実際に使うエントリに置き換えるため、バンドルとページのサイズを最大50%削減できます。

    コンテンツをコンポーネント単位に分けることで、大規模アプリケーションの保守が簡単になります。コンテンツ全体のコードベースを見直すことなく、機能フォルダを複製または削除でき、Intlayerは完全に型付けされているため、コンテンツの正確さが保たれます。

    コンテンツを同じ場所に置くことで、LLMに必要なコンテキストが減ります。Intlayerは、翻訳漏れをテストするCLI、LSP、MCPサーバー、エージェントスキルを提供します。

    お好みのLLMを使い、AIプロバイダーの料金負担でCI/CDパイプライン内で翻訳できます。Intlayerには、コンテンツ抽出を自動化するコンパイラーと、バックグラウンドで翻訳できるWebプラットフォームもあります。

    Intlayerは、セルフホスト可能なビジュアルエディターとフルCMSを提供し、翻訳者やコピーライターとリアルタイムで多言語コンテンツを管理できます。コンテンツはローカルまたはリモート(あるいは両方)に保存できます。

    vinextアプリケーションにIntlayerを設定するステップバイステップガイド

    1. 依存関係をインストールする

      動作するvinextプロジェクトから始めます。新規作成するにはnpm create vinext-app@latestを実行します。既存のNext.jsアプリを移行するにはnpx vinext initを実行します。

      次にIntlayerをインストールします。

      bash
      npm install intlayer next-intlayer
      npm install vite-intlayer --save-dev
      
      • intlayer

        設定管理、翻訳、コンテンツ宣言、トランスパイル、CLIコマンドなど、国際化ツールを提供するコアパッケージです。

      • next-intlayer

        Next.js API向けのプロバイダー、フック、プロキシを提供します。vinextはnext/navigation、next/headers、next/serverを独自の実装に解決するため、next-intlayerは変更なしで動作します。

      • vite-intlayer

        コンテンツ宣言をビルドし、開発中に監視し、本番バンドルで辞書を最適化するViteプラグインです。vinextが実行しないNext.jsプラグインwithIntlayer()の代わりになります。

    2. プロジェクトを設定する

      アプリケーションでローカライズされたURLパス(例:/en/about、/fr/about)を使うか、パスにロケールセグメントを含めずにコンテンツを提供するか(例:/about、Cookie、ヘッダー、クエリパラメーターでロケールを検出)を選択します。

      アーキテクチャ

      ローカライズされたページはすべて動的セグメント[locale]の下にネストされます。言語ごとに固有のURLを持つため、SEOと静的レンダリングに推奨されます。

      bash
      .
      ├── src
      │   ├── app
      │   │   ├── [locale]
      │   │   │   ├── layout.tsx            # Locale layout for the Intlayer provider
      │   │   │   ├── page.content.ts
      │   │   │   └── page.tsx
      │   │   └── layout.tsx                # Root layout for style and global providers
      │   ├── components
      │   │   ├── client-component-example.content.ts
      │   │   ├── ClientComponentExample.tsx
      │   │   ├── LocaleSwitcher
      │   │   │   ├── localeSwitcher.content.ts
      │   │   │   └── LocaleSwitcher.tsx
      │   │   ├── server-component-example.content.ts
      │   │   └── ServerComponentExample.tsx
      │   └── proxy.ts
      ├── intlayer.config.ts
      ├── next.config.ts
      ├── vite.config.ts
      ├── package.json
      └── tsconfig.json
      

      設定

      intlayer.config.tsファイルを作成して、対応言語を宣言します。

      intlayer.config.ts
      import { Locales, type IntlayerConfig } from "intlayer";
      
      const config: IntlayerConfig = {
        internationalization: {
          locales: [
            Locales.ENGLISH,
            Locales.FRENCH,
            Locales.SPANISH,
            // Your other locales
          ],
          defaultLocale: Locales.ENGLISH,
        },
        routing: {
          mode: "prefix-no-default", // or `prefix-all`
        },
      };
      
      export default config;
      

      アーキテクチャ

      ルートに[locale]セグメントは含まれません。すべてのページはsrc/app/直下に置かれ、ロケールはCookie、ヘッダー、クエリパラメーターから取得されます。ダッシュボードや認証が必要なアプリに適しています。

      bash
      .
      ├── src
      │   ├── app
      │   │   ├── layout.tsx                # Root layout for Intlayer provider and styling
      │   │   ├── page.content.ts
      │   │   └── page.tsx
      │   ├── components
      │   │   ├── client-component-example.content.ts
      │   │   ├── ClientComponentExample.tsx
      │   │   ├── server-component-example.content.ts
      │   │   └── ServerComponentExample.tsx
      │   └── proxy.ts
      ├── intlayer.config.ts
      ├── next.config.ts
      ├── vite.config.ts
      ├── package.json
      └── tsconfig.json
      

      設定

      routing.modeを"search-params"(例:/about?locale=fr)または"no-prefix"に設定します。

      intlayer.config.ts
      import { Locales, type IntlayerConfig } from "intlayer";
      
      const config: IntlayerConfig = {
        internationalization: {
          locales: [
            Locales.ENGLISH,
            Locales.FRENCH,
            Locales.SPANISH,
            // Your other locales
          ],
          defaultLocale: Locales.ENGLISH,
        },
        routing: {
          mode: "search-params", // or `no-prefix`
        },
      };
      
      export default config;
      
      このファイルでは、プロキシのリダイレクト、Cookie名、コンテンツ宣言の場所と拡張子、ログなども設定できます。完全な一覧は設定ドキュメントを参照してください。
    3. Vite設定にIntlayerを組み込む

      vite.config.tsで、vinext()の隣にintlayer()プラグインを追加します。

      vite.config.ts
      import { defineConfig } from "vite";
      import vinext from "vinext";
      import { intlayer } from "vite-intlayer";
      
      export default defineConfig({
        plugins: [
          vinext(),
          intlayer({
            // Locale routing is handled by `src/proxy.ts` (step 7)
            proxy: { ignore: () => true },
          }),
        ],
      });
      
      intlayer()プラグインは、ビルド開始前に辞書をビルドし、開発中にコンテンツファイルを監視し、RSC、SSR、クライアントの各環境でnext-intlayerが使うエイリアスと最適化を設定します。
      intlayer()はViteの開発サーバー向けにロケールルーティングのミドルウェアも提供します。vinextでは、src/proxy.tsが開発時も本番ランタイムでも同じ役割を果たすため、ignoreオプションでVite側を無効にし、すべてのリクエストが二重にルーティングされるのを防ぎます。
      next.config.tsにwithIntlayer()を追加しないでください。vinextはredirects、rewrites、headersなどのオプションのためにnext.config.tsを読み込みますが、webpackやTurbopackのプラグインは実行しません。

      Cloudflare Workersにデプロイする場合は、vinext initが生成したcloudflare()プラグインを残してください。

      vite.config.ts
      import { cloudflare } from "@cloudflare/vite-plugin";
      import { defineConfig } from "vite";
      import vinext from "vinext";
      import { intlayer } from "vite-intlayer";
      
      export default defineConfig({
        plugins: [
          vinext(),
          intlayer({ proxy: { ignore: () => true } }),
          cloudflare({
            viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] },
          }),
        ],
      });
      
    4. 動的ロケールルートを定義する

      RootLayoutの中身をすべて削除し、次のコードに置き換えます。

      src/app/layout.tsx
      import type { PropsWithChildren, FC } from "react";
      import "./globals.css";
      
      const RootLayout: FC<PropsWithChildren> = ({ children }) => (
        // You can still wrap the children with other providers, like `next-themes` or `react-query`
        <>{children}</>
      );
      
      export default RootLayout;
      
      RootLayoutを空のままにしておくと、ロケールレイアウトが<html>タグのlang属性とdir属性を設定できます。

      [locale]ディレクトリにレイアウトを追加します。

      src/app/[locale]/layout.tsx
      import { getHTMLTextDir } from "intlayer";
      import type { NextLayoutIntlayer } from "next-intlayer";
      import { IntlayerProvider } from "next-intlayer/server";
      
      export { generateStaticParams } from "next-intlayer";
      
      const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {
        const { locale } = await params;
      
        return (
          <html lang={locale} dir={getHTMLTextDir(locale)}>
            <body>
              <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
            </body>
          </html>
        );
      };
      
      export default LocaleLayout;
      
      1つのIntlayerProviderでツリーの両側をカバーします。Server Componentsにロケールを提供し、クライアントプロバイダーをマウントすることでClient Componentsにも同じロケールが渡されます。
      [locale]セグメントがロケールを保持します。/en-US/aboutはen-US、/fr/aboutはfrに解決されます。以前のsrc/app/page.tsxは使われなくなったため削除できます。プロキシ(ステップ7)がルートでデフォルトロケールを提供します。
      generateStaticParamsにより、vinextはロケールごとにすべてのページをプリレンダリングします。vinextはdynamicParamsも適用するため、export const dynamicParams = falseを設定すると、未知のロケールは404を返します。

      [locale]ディレクトリはありません。src/app/layout.tsxを設定して、リクエストからロケールを読み取り、アプリケーションをIntlayerProviderでラップします。

      src/app/layout.tsx
      import type { Metadata } from "next";
      import type { ReactNode } from "react";
      import "./globals.css";
      import { getHTMLTextDir, getIntlayer } from "intlayer";
      import { getLocale, IntlayerProvider } from "next-intlayer/server";
      
      export const generateMetadata = async (): Promise<Metadata> => {
        const locale = await getLocale();
        const { title, description, keywords } = getIntlayer("metadata", locale);
      
        return {
          title,
          description,
          keywords,
        };
      };
      
      const RootLayout = async ({
        children,
      }: Readonly<{
        children: ReactNode;
      }>) => {
        const locale = await getLocale();
      
        return (
          <html lang={locale} dir={getHTMLTextDir(locale)}>
            <body>
              <IntlayerProvider locale={locale}>{children}</IntlayerProvider>
            </body>
          </html>
        );
      };
      
      export default RootLayout;
      
    5. コンテンツを宣言する

      翻訳を保存するコンテンツ宣言を作成します。

      src/app/[locale]/page.content.ts
      import { t, type Dictionary } from "intlayer";
      
      const pageContent = {
        key: "page",
        content: {
          getStarted: {
            main: t({
              ja: "編集を始めてください",
              en: "Get started by editing",
              fr: "Commencez par éditer",
              es: "Comience por editar",
            }),
            pageLink: "src/app/page.tsx",
          },
        },
      } satisfies Dictionary;
      
      export default pageContent;
      
      コンテンツ宣言は、コンテンツ宣言の拡張子(デフォルトは.content.{json,ts,tsx,js,jsx,mjs,cjs,md,mdx,yaml,yml})に一致していれば、contentDirディレクトリ(デフォルトは./src)内のどこにでも置けます。
      詳細はコンテンツ宣言ドキュメントを参照してください。
    6. コード内でコンテンツを利用する

      任意のコンポーネントから辞書にアクセスできます。

      src/app/[locale]/page.tsx
      import type { FC } from "react";
      import { ClientComponentExample } from "@components/ClientComponentExample";
      import { ServerComponentExample } from "@components/ServerComponentExample";
      import { type NextPageIntlayer, useIntlayer } from "next-intlayer";
      
      const PageContent: FC = () => {
        const content = useIntlayer("page");
      
        return (
          <>
            <p>{content.getStarted.main}</p>
            <code>{content.getStarted.pageLink}</code>
          </>
        );
      };
      
      const Page: NextPageIntlayer = () => (
        <>
          <PageContent />
          <ServerComponentExample />
          <ClientComponentExample />
        </>
      );
      
      export default Page;
      
      src/components/ClientComponentExample.tsx
      "use client";
      
      import type { FC } from "react";
      import { useIntlayer } from "next-intlayer";
      
      export const ClientComponentExample: FC = () => {
        const content = useIntlayer("client-component-example"); // Create related content declaration
      
        return (
          <div>
            <h2>{content.title}</h2>
            <p>{content.content}</p>
          </div>
        );
      };
      
      src/components/ServerComponentExample.tsx
      import type { FC } from "react";
      import { useIntlayer } from "next-intlayer";
      
      export const ServerComponentExample: FC = () => {
        const content = useIntlayer("server-component-example"); // Create related content declaration
      
        return (
          <div>
            <h2>{content.title}</h2>
            <p>{content.content}</p>
          </div>
        );
      };
      
      next-intlayerはアイソモーフィックです。vinextがRSC環境に適用するreact-serverエクスポート条件により、Server Componentsにはサーバー実装が、Client Componentsにはコンテキストベースの実装が提供されます。同じ呼び出しがどちら側でも動作します。

      alt、title、href、aria-labelなどのstring属性でコンテンツを使うには、その値を読み取ります。

      tsx
      <img src={content.image.src.value} alt={content.image.value} />
      
      詳細はuseIntlayerドキュメントを参照してください。
      既存のアプリがある場合は、Intlayerコンパイラーとextractコマンドが、数千のコンポーネントを1秒で変換します。
    7. ロケール検出用のプロキシを設定する

      vinextはproxy.ts(およびmiddleware.ts)をNext.js 16と同様に、開発時も本番時も、Cloudflare Workers上でも実行します。Intlayerのプロキシをエクスポートします。

      src/proxy.ts
      export { intlayerProxy as proxy } from "next-intlayer/proxy";
      
      export const config = {
        matcher:
          "/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)",
      };
      
      intlayerProxyはユーザーの優先ロケールを検出し、設定に従って該当するURLにリダイレクトし、ロケールをCookieに保存します。また、ロケールをgetLocale()とサーバーフックに渡すため、ロケールパスなしのアーキテクチャでも残してください。
      複数のプロキシを連結する場合(例:intlayerProxyと認証)は、multipleProxiesを使います。
      ts
      import { multipleProxies, intlayerProxy } from "next-intlayer/proxy";
      import { customProxy } from "@utils/customProxy";
      
      export const proxy = multipleProxies([intlayerProxy, customProxy]);
      
    8. メタデータの国際化

      オプション

      vinextはMetadata APIをサポートしています。generateMetadataとgetIntlayerを使って、ページのメタデータを翻訳します。

      src/app/[locale]/metadata.content.ts
      import { type Dictionary, t } from "intlayer";
      import type { Metadata } from "next";
      
      const metadataContent = {
        key: "page-metadata",
        content: {
          title: t({
            ja: "私のvinextアプリ",
            en: "My vinext app",
            fr: "Mon application vinext",
            es: "Mi aplicación vinext",
          }),
          description: t({
            ja: "Vite上で動作するNext.jsアプリ",
            en: "A Next.js app running on Vite",
            fr: "Une application Next.js qui tourne sur Vite",
            es: "Una aplicación Next.js que funciona con Vite",
          }),
        },
      } satisfies Dictionary<Metadata>;
      
      export default metadataContent;
      
      src/app/[locale]/layout.tsx or src/app/[locale]/page.tsx
      import { getIntlayer, getMultilingualUrls } from "intlayer";
      import type { Metadata } from "next";
      import type { LocalPromiseParams } from "next-intlayer";
      
      export const generateMetadata = async ({
        params,
      }: LocalPromiseParams): Promise<Metadata> => {
        const { locale } = await params;
      
        const metadata = getIntlayer("page-metadata", locale);
      
        /**
         * Generates an object containing all url for each locale.
         *
         * Example:
         * ```ts
         *  getMultilingualUrls('/about');
         *
         *  // Returns
         *  // {
         *  //   en: '/about',
         *  //   fr: '/fr/about',
         *  //   es: '/es/about',
         *  // }
         * ```
         */
        const multilingualUrls = getMultilingualUrls("/");
        const localizedUrl =
          multilingualUrls[locale as keyof typeof multilingualUrls];
      
        return {
          ...metadata,
          alternates: {
            canonical: localizedUrl,
            languages: { ...multilingualUrls, "x-default": "/" },
          },
          openGraph: {
            url: localizedUrl,
          },
        };
      };
      
      // ... Rest of the code
      
      intlayerからインポートしたgetIntlayer関数は、メタデータオブジェクトにそのまま使える生の値を返します。next-intlayerのものは、ビジュアルエディター向けにラップします。
    9. sitemap.xmlとrobots.txtの国際化

      オプション

      sitemap.tsとrobots.tsはNext.jsと同様に動作します。getMultilingualUrlsを使って、ローカライズされたすべてのURLを列挙します。

      src/app/sitemap.ts
      import { getMultilingualUrls } from "intlayer";
      import type { MetadataRoute } from "next";
      
      const sitemap = (): MetadataRoute.Sitemap => [
        {
          url: "https://example.com",
          alternates: {
            languages: {
              ...getMultilingualUrls("https://example.com"),
              "x-default": "https://example.com",
            },
          },
        },
        {
          url: "https://example.com/login",
          alternates: {
            languages: {
              ...getMultilingualUrls("https://example.com/login"),
              "x-default": "https://example.com/login",
            },
          },
        },
      ];
      
      export default sitemap;
      
      src/app/robots.ts
      import type { MetadataRoute } from "next";
      import { getMultilingualUrls } from "intlayer";
      
      const getAllMultilingualUrls = (urls: string[]) =>
        urls.flatMap((url) => Object.values(getMultilingualUrls(url)) as string[]);
      
      const robots = (): MetadataRoute.Robots => ({
        rules: {
          userAgent: "*",
          allow: ["/"],
          disallow: getAllMultilingualUrls(["/login", "/register"]),
        },
        host: "https://example.com",
        sitemap: `https://example.com/sitemap.xml`,
      });
      
      export default robots;
      
    10. コンテンツの言語を変更する

      オプション

      ローカライズされたページへの移動にはnext/linkを使います。vinextはクライアントサイドナビゲーションとプリフェッチを維持するため、ページ全体をリロードせずに切り替わります。

      src/components/LocaleSwitcher.tsx
      "use client";
      
      import type { FC } from "react";
      import {
        Locales,
        getHTMLTextDir,
        getLocaleName,
        getLocalizedUrl,
      } from "intlayer";
      import { useLocale } from "next-intlayer";
      import Link from "next/link";
      
      export const LocaleSwitcher: FC = () => {
        const { locale, pathWithoutLocale, availableLocales, setLocale } =
          useLocale();
      
        return (
          <div>
            <button popoverTarget="localePopover">{getLocaleName(locale)}</button>
            <div id="localePopover" popover="auto">
              {availableLocales.map((localeItem) => (
                <Link
                  href={getLocalizedUrl(pathWithoutLocale, localeItem)}
                  key={localeItem}
                  aria-current={locale === localeItem ? "page" : undefined}
                  onClick={() => setLocale(localeItem)}
                  replace // The browser "back" button returns to the previous page
                >
                  <span>
                    {/* Locale - e.g. FR */}
                    {localeItem}
                  </span>
                  <span>
                    {/* Language in its own Locale - e.g. Français */}
                    {getLocaleName(localeItem, locale)}
                  </span>
                  <span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
                    {/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */}
                    {getLocaleName(localeItem)}
                  </span>
                  <span dir="ltr" lang={Locales.ENGLISH}>
                    {/* Language in English - e.g. French */}
                    {getLocaleName(localeItem, Locales.ENGLISH)}
                  </span>
                </Link>
              ))}
            </div>
          </div>
        );
      };
      

      ドキュメントリファレンス:

    11. ローカライズされたLinkコンポーネントを作成する

      オプション

      カスタムLinkコンポーネントは内部URLに現在のロケールを付与します。これにより、フランス語のユーザーが/aboutをクリックすると/fr/aboutに遷移します。

      src/components/Link.tsx
      "use client";
      
      import { getLocalizedUrl } from "intlayer";
      import NextLink, { type LinkProps as NextLinkProps } from "next/link";
      import { useLocale } from "next-intlayer";
      import type { PropsWithChildren, FC } from "react";
      
      /**
       * Checks whether a URL is external (starts with http:// or https://).
       */
      export const checkIsExternalLink = (href?: string): boolean =>
        /^https?:\/\//.test(href ?? "");
      
      /**
       * Link that localizes internal URLs with the current locale.
       */
      export const Link: FC<PropsWithChildren<NextLinkProps>> = ({
        href,
        children,
        ...props
      }) => {
        const { locale } = useLocale();
        const isExternalLink = checkIsExternalLink(href.toString());
      
        const hrefI18n: NextLinkProps["href"] =
          href && !isExternalLink ? getLocalizedUrl(href.toString(), locale) : href;
      
        return (
          <NextLink href={hrefI18n} {...props}>
            {children}
          </NextLink>
        );
      };
      
    12. Server Actionsで現在のロケールを取得する

      オプション

      Server Action内でnext-intlayer/serverのgetLocaleを呼び出します。

      src/app/actions/getLocale.ts
      "use server";
      
      import { getLocale } from "next-intlayer/server";
      
      export const myServerAction = async () => {
        const locale = await getLocale();
      
        // Do something with the locale
      };
      
      getLocaleは、プロキシがリクエストヘッダーに設定したロケール、次にロケールCookie、次にブラウザーのAccept-Languageヘッダーの順に読み取り、最後にデフォルトロケールにフォールバックします。
    13. Cloudflare Workersにデプロイする

      オプション

      Intlayerはビルド時に辞書をバンドルへコンパイルするため、実行時にファイルシステムを読み取るものはなく、アプリはworkerd上でそのまま動作します。vinext CLIでビルドとデプロイを行います。

      bash
      npx @vinext/cloudflare deploy
      
      他の環境(Vercel、Netlify、AWS、Node.js)にデプロイする場合は、vinext()の隣にNitroのViteプラグインを追加するか、next.config.tsでoutput: "standalone"を設定します。Intlayerの設定は変わりません。
    14. コンポーネントからコンテンツを抽出する

      オプション

      既存のコードベースでは、Intlayerのコンパイラーとエクストラクターを使って、ハードコードされた文字列をコンテンツ宣言へ移せます。

      intlayer.config.tsでコンパイラーを有効にします。

      intlayer.config.ts
      import { type IntlayerConfig } from "intlayer";
      
      const config: IntlayerConfig = {
        // ... Rest of your config
        compiler: {
          /**
           * Indicates if the compiler should be enabled.
           */
          enabled: true,
      
          /**
           * Defines the output files path
           */
          output: ({ fileName, extension }) => `./${fileName}${extension}`,
      
          /**
           * If `true`, the compiler rewrites the component files on disk.
           * If `false`, the transformation stays in the build output only.
           */
          saveComponents: false,
      
          /**
           * Dictionary key prefix
           */
          dictionaryKeyPrefix: "",
        },
      };
      
      export default config;
      

      エクストラクターを実行して、コンポーネントを変換しコンテンツを抽出します。

      bash
      npx intlayer extract
      

      intlayer()のViteプラグインにはコンパイラーが含まれています。compiler.enabledを設定したら、通常どおり開発サーバーまたはビルドを実行します。

      bash
      npm run build # Or npm run dev
      

    TypeScriptを設定する

    Intlayerはモジュール拡張(module augmentation)を使って、コンテンツのキーと値に型を付けます。

    Autocompletion

    Translation error

    生成された型をTypeScript設定に含めます。

    tsconfig.json
    {
      // ... Your existing TypeScript configurations
      "include": [
        // ... Your existing TypeScript configurations
        ".intlayer/**/*.ts", // Include the auto-generated types
      ],
    }
    

    Git設定

    Intlayerが生成するファイルを無視します。

    .gitignore
    # Ignore the files generated by Intlayer
    .intlayer
    

    VS Code拡張機能

    公式のIntlayer VS Code拡張機能をインストールすると、キーの自動補完、翻訳漏れのエラー、インラインプレビュー、クイックアクションが利用できます。拡張機能のドキュメントを参照してください。

    さらに進むには

    ビジュアルエディターを追加するか、CMSでコンテンツを外部化します。

    よくある質問

    vinextは、CloudflareがメンテナンスしているオープンソースのViteプラグインで、Next.jsの公開API(App RouterとPages Router、React Server Components、Server Actions、proxy.ts、ルートハンドラー、next/*モジュール)を再実装しています。Next.jsのコードはVite上で動作し、Cloudflare Workersにネイティブにデプロイでき、Nitro経由で他のプラットフォームにもデプロイできます。

    変わるのはビルド統合だけです。Next.jsではwithIntlayer()がnext.config.tsをラップします。vinextでは、代わりにvite-intlayerのintlayer()プラグインをvite.config.tsに追加します。プロバイダー、フック、proxy.ts、メタデータ、サイトマップのコードは同じなので、このページで扱っていない内容はNext.js 16ガイドに従ってください。

    いいえ。next.config.tsのi18nフィールドは、vinextではPages Routerのロケールプレフィックスにしか対応せず、Intlayerはproxy.tsで独自にルーティングを行います。@intlayer/swcプラグインも不要です。ViteプラグインがすでにuseIntlayer呼び出しを置き換えるため、各ページは使用する辞書だけを配信します。バンドルの最適化を参照してください。

    いいえ。intlayer()のViteプラグインがvite devと同時にコンテンツウォッチャーを起動し、コンテンツを編集すると、変更された辞書を読み込むコンポーネントだけがホットアップデートされます。

    はい。next-intlからの移行ガイドまたはi18nextからの移行ガイドに従うか、Intlayerの辞書で動くnext-intl、react-i18next、react-intlのAPIを提供する互換アダプターで現在のAPIを維持できます。

    いいえ。routing.modeは次の値を受け付けます。

    • "prefix-no-default"(デフォルト):デフォルトロケールは/about、それ以外は/fr/about。
    • "prefix-all":すべてのロケールにプレフィックスが付きます(/en/about、/fr/about)。
    • "no-prefix":パスにロケールを含めず、Cookieまたはヘッダーから解決します。
    • "search-params":/about?locale=fr。

    設定リファレンスと、ステップ2のロケールパスなしのアーキテクチャを参照してください。