# General Translation React SDKs (gt-react, gt-next, gt-react-native): Pages Router の静的サイト生成 URL: https://generaltranslation.com/ja/docs/react/nextjs/pages-router-static-site-generation.mdx --- title: Pages Router の静的サイト生成 description: General Translation を使用して、ローカライズされた Next.js Pages Router ページを事前レンダリングする方法。 related: links: - /docs/react/nextjs-pages-router-quickstart - /docs/react/nextjs/pages-router-middleware - /docs/react/guides/storing-translations --- `withGTStaticProps` を使用して、ローカライズされた Pages Router ページを事前レンダリングします。設定は `withGTServerSideProps` とほぼ同じですが、props は Next.js がビルド時に生成します。 ## ロケールルーティングを設定する [#config] Next.js では、ロケールごとに各ページのバージョンを生成するため、ビルド時にすべてのロケールを認識している必要があります。`gt.config.json` から値をインポートします。`locales` 配列には `defaultLocale` を含める必要があります。 ```ts title="next.config.ts" import type { NextConfig } from 'next'; import { withGTConfig } from 'gt-next/config'; import gtConfig from './gt.config.json'; const nextConfig: NextConfig = { i18n: { locales: gtConfig.locales, defaultLocale: gtConfig.defaultLocale, }, }; export default withGTConfig(nextConfig); ``` ページは通常の場所に配置したままにします。Next.js の国際化ルーティングでは、`pages/[locale]` セグメントを使用せずにローカライズされた URL が生成されます。完全な設定については、[Pages Router のロケールルーティング](/docs/react/nextjs/pages-router-middleware)を参照してください。 ## 静的 props を追加 [#static-props] 各ページの`getStaticProps`関数を`withGTStaticProps`でラップします: ```tsx title="pages/about.tsx" import type { GetStaticProps } from 'next'; import { T, Var, withGTStaticProps } from 'gt-next'; type AboutPageProps = { generatedAt: string; }; export const getStaticProps: GetStaticProps = withGTStaticProps(async () => ({ props: { generatedAt: new Date().toISOString(), }, })); export default function AboutPage({ generatedAt }: AboutPageProps) { return Generated at: {generatedAt}; } ``` `withGTStaticProps` は、返されるページの props にロケールと翻訳スナップショットを追加します。ページに他の props がない場合は、引数なしの形式を使用します。 ```tsx title="pages/index.tsx" import { withGTStaticProps } from 'gt-next'; export const getStaticProps = withGTStaticProps(); ``` Next.js は設定されたロケールごとに`getStaticProps`を1回呼び出し、`context.locale`を渡します。生成された値を[`GTProvider`](/docs/react/reference/components/gt-provider)に渡し、`_app.tsx`で[ロケールの変更に対応](/docs/react/nextjs/pages-router-middleware#locale-changes)します。 ## Next steps - /docs/react/nextjs-pages-router-quickstart - /docs/react/nextjs/pages-router-middleware - /docs/react/guides/storing-translations