Skip to content

Commit c79ee5c

Browse files
authored
Merge branch 'master' into chore/automatic-static-optimization
2 parents 3f56723 + ee2eb0c commit c79ee5c

File tree

4 files changed

+166
-229
lines changed

4 files changed

+166
-229
lines changed

docs/advanced-features/i18n-routing.md

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
<!-- textlint-disable -->
2-
<!-- 翻訳時には ↑ を削除してください -->
31
---
4-
description: Next.js has built-in support for internationalized routing and language detection. Learn more here.
2+
description: Next.js には国際化されたルーティングと言語検出のビルトインサポートがあります。詳細はこちらをご覧ください。
53
---
64

7-
# Internationalized Routing
5+
# 国際化されたルーティング
86

97
<details>
10-
<summary><b>Examples</b></summary>
8+
<summary><b></b></summary>
119
<ul>
12-
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/i18n-routing">i18n routing</a></li>
10+
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/i18n-routing">i18n ルーティング</a></li>
1311
</ul>
1412
</details>
1513

16-
Next.js has built-in support for internationalized ([i18n](https://en.wikipedia.org/wiki/Internationalization_and_localization#Naming)) routing since `v10.0.0`. You can provide a list of locales, the default locale, and domain-specific locales and Next.js will automatically handle the routing.
14+
Next.js には `v10.0.0` から国際化([i18n](https://en.wikipedia.org/wiki/Internationalization_and_localization#Naming))ルーティングのビルトインサポートがあります。ロケールの一覧やデフォルトのロケール、特定ドメインのロケールを指定すると、Next.js がルーティングを自動的に処理してくれます。
1715

18-
The i18n routing support is currently meant to complement existing i18n library solutions like `react-intl`, `react-i18next`, `lingui`, `rosetta`, and others by streamlining the routes and locale parsing.
16+
i18n ルーティングは、ルートとロケールの解析を効率化することで、`react-intl`, `react-i18next`, `lingui`, `rosetta` やその他の既存 i18n ライブラリによる実装を補完することを目的としています。
1917

20-
## Getting started
18+
## はじめに
2119

22-
To get started, add the `i18n` config to your `next.config.js` file.
20+
まずはじめに、`next.config.js` ファイルに `i18n` の設定を追加します。
2321

24-
Locales are [UTS Locale Identifiers](https://www.unicode.org/reports/tr35/tr35-59/tr35.html#Identifiers), a standardized format for defining locales.
22+
ロケールには、ロケールを定義するための標準化されたフォーマットである UTS ロケール識別子([UTS Locale Identifiers](https://www.unicode.org/reports/tr35/tr35-59/tr35.html#Identifiers))を用います。
2523

26-
Generally a Locale Identifier is made up of a language, region, and script separated by a dash: `language-region-script`. The region and script are optional. An example:
24+
一般的にロケール識別子は、ダッシュ区切りの言語、地域、スクリプトで構成されます: `言語-地域-スクリプト`。地域とスクリプトは任意項目です。例としては、以下のようになります:
2725

28-
- `en-US` - English as spoken in the United States
29-
- `nl-NL` - Dutch as spoken in the Netherlands
30-
- `nl` - Dutch, no specific region
26+
- `en-US` - アメリカで話されている英語
27+
- `nl-NL` - オランダで話されているオランダ語
28+
- `nl` - 地域指定のないオランダ語
3129

3230
```js
3331
// next.config.js
3432
module.exports = {
3533
i18n: {
36-
// These are all the locales you want to support in
37-
// your application
34+
// アプリケーションでサポートしたいすべてのロケール
3835
locales: ['en-US', 'fr', 'nl-NL'],
39-
// This is the default locale you want to be used when visiting
40-
// a non-locale prefixed path e.g. `/hello`
36+
// ロケールのプレフィックスを持たないパスを訪れる際に使用したい
37+
// デフォルトのロケール。例 `/hello`
4138
defaultLocale: 'en-US',
42-
// This is a list of locale domains and the default locale they
43-
// should handle (these are only required when setting up domain routing)
44-
// Note: subdomains must be included in the domain value to be matched e.g. "fr.example.com".
39+
// ロケールドメインの一覧と、それらが扱うべきデフォルトのロケールの一覧
40+
// (ドメインルーティングを設定する場合にのみ必要)
41+
// 注:サブドメインは、一致させるドメインの値に含まれている必要があります。例 "fr.example.com"
4542
domains: [
4643
{
4744
domain: 'example.com',
@@ -60,13 +57,13 @@ module.exports = {
6057
}
6158
```
6259

63-
## Locale Strategies
60+
## ロケール戦略
6461

65-
There are two locale handling strategies: Sub-path Routing and Domain Routing.
62+
ロケールを扱う戦略は 2 つあります: サブパスルーティングとドメインルーティングです。
6663

67-
### Sub-path Routing
64+
### サブパスルーティング
6865

69-
Sub-path Routing puts the locale in the url path.
66+
サブパスルーティングはロケールを URL パスに含めます。
7067

7168
```js
7269
// next.config.js
@@ -78,17 +75,17 @@ module.exports = {
7875
}
7976
```
8077

81-
With the above configuration `en-US`, `fr`, and `nl-NL` will be available to be routed to, and `en-US` is the default locale. If you have a `pages/blog.js` the following urls would be available:
78+
上記の設定では、`en-US`, `fr`, `nl-NL` がルーティング先として利用できます。そして `en-US` がデフォルトのロケールです。`pages/blog.js` がある場合は、以下のような URL が利用できます:
8279

8380
- `/blog`
8481
- `/fr/blog`
8582
- `/nl-nl/blog`
8683

87-
The default locale does not have a prefix.
84+
デフォルトのロケールはプレフィックスがありません。
8885

89-
### Domain Routing
86+
### ドメインルーティング
9087

91-
By using domain routing you can configure locales to be served from different domains:
88+
ドメインルーティングを用いると、異なるドメインごとにロケールを設定できます。
9289

9390
```js
9491
// next.config.js
@@ -109,38 +106,37 @@ module.exports = {
109106
{
110107
domain: 'example.nl',
111108
defaultLocale: 'nl-NL',
112-
// specify other locales that should be redirected
113-
// to this domain
109+
// このドメインにリダイレクトすべき他のロケールを指定
114110
locales: ['nl-BE'],
115111
},
116112
],
117113
},
118114
}
119115
```
120116

121-
For example if you have `pages/blog.js` the following urls will be available:
117+
例えば `pages/blog.js` の場合、以下のような URL が利用できます:
122118

123119
- `example.com/blog`
124120
- `example.fr/blog`
125121
- `example.nl/blog`
126122
- `example.nl/nl-BE/blog`
127123

128-
## Automatic Locale Detection
124+
## ロケールの自動検出
129125

130-
When a user visits the application root (generally `/`), Next.js will try to automatically detect which locale the user prefers based on the [`Accept-Language`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) header and the current domain.
126+
ユーザーがアプリケーションのルート(通常は `/`)にアクセスすると、Next.js [`Accept-Language`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) ヘッダーと現在のドメインに基づいて、ユーザーが好むロケールを自動的に検出しようとします。
131127

132-
If a locale other than the default locale is detected, the user will be redirected to either:
128+
デフォルトのロケール以外のロケールが検出された場合、ユーザーはいずれかのロケールにリダイレクトされます:
133129

134-
- **When using Sub-path Routing:** The locale prefixed path
135-
- **When using Domain Routing:** The domain with that locale specified as the default
130+
- **サブパスルーティングを使用する場合:** 該当するロケールのプレフィックスパス
131+
- **ドメインルーティングを使用する場合:** 該当するロケールをデフォルトに指定するドメイン
136132

137-
When using Domain Routing, if a user with the `Accept-Language` header `fr;q=0.9` visits `example.com`, they will be redirected to `example.fr` since that domain handles the `fr` locale by default.
133+
ドメインルーティングを使用している場合、`Accept-Language` ヘッダー `fr;q=0.9` のユーザーが `example.com` を訪れると、そのドメインは `fr` ロケールをデフォルトとするため、ユーザーは `example.fr` にリダイレクトされます。
138134

139-
When using Sub-path Routing, the user would be redirected to `/fr`.
135+
サブパスルーティングを使用している場合、ユーザーは `/fr` にリダイレクトされます。
140136

141-
### Disabling Automatic Locale Detection
137+
### ロケールの自動検出を無効にする
142138

143-
The automatic locale detection can be disabled with:
139+
ロケールの自動検出は次の設定で無効にできます:
144140

145141
```js
146142
// next.config.js
@@ -151,25 +147,25 @@ module.exports = {
151147
}
152148
```
153149

154-
When `localeDetection` is set to `false` Next.js will no longer automatically redirect based on the user's preferred locale and will only provide locale information detected from either the locale based domain or locale path as described above.
150+
`localeDetection` `false` に設定すると、Next.js はユーザーの好みのロケールに基づいた自動的なリダイレクトを止め、前述の通り、ロケールに基づくドメインまたはロケールパスから検出されたロケール情報のみを提供するようになります。
155151

156-
## Accessing the locale information
152+
## ロケール情報へのアクセス
157153

158-
You can access the locale information via the Next.js router. For example, using the [`useRouter()`](/docs/api-reference/next/router.md#userouter) hook the following properties are available:
154+
ロケール情報には Next.js ルーターを介してアクセスできます。例えば、[`useRouter()`](/docs/api-reference/next/router#userouter) フックを使用すると、以下のようなプロパティが利用できます:
159155

160-
- `locale` contains the currently active locale.
161-
- `locales` contains all configured locales.
162-
- `defaultLocale` contains the configured default locale.
156+
- `locale` には、現在アクティブなロケールが含まれます。
157+
- `locales` には、設定されたすべてのロケールが含まれます。
158+
- `defaultLocale` には、設定されたデフォルトのロケールが含まれます。
163159

164-
When [pre-rendering](/docs/basic-features/pages.md#static-generation-recommended) pages with `getStaticProps` or `getServerSideProps`, the locale information is provided in [the context](/docs/basic-features/data-fetching.md#getstaticprops-static-generation) provided to the function.
160+
`getStaticProps``getServerSideProps` でページを[プリレンダリング](/docs/basic-features/pages#static-generation-recommended)する場合、ロケール情報は関数へ渡される[コンテキスト](/docs/basic-features/data-fetching#getstaticprops-static-generation)に含まれます。
165161

166-
When leveraging `getStaticPaths`, the configured locales are provided in the context parameter of the function under `locales` and the configured defaultLocale under `defaultLocale`.
162+
`getStaticPaths` を利用する場合、設定されたロケールは関数のコンテキストパラメータ内の `locales` 下で、設定された defaultLocale `defaultLocale` 下で提供されます。
167163

168-
## Transition between locales
164+
## ロケール間の遷移
169165

170-
You can use `next/link` or `next/router` to transition between locales.
166+
ロケール間の遷移には、`next/link` または `next/router` を利用できます。
171167

172-
For `next/link`, a `locale` prop can be provided to transition to a different locale from the currently active one. If no `locale` prop is provided, the currently active `locale` is used during client-transitions. For example:
168+
`next/link` の場合、現在有効なロケールから別のロケールへ遷移するために `locale` prop を指定できます。`locale` prop を指定しない場合、現在有効なロケールがクライアント遷移の際に使用されます。例としては、以下のようになります:
173169

174170
```jsx
175171
import Link from 'next/link'
@@ -183,7 +179,7 @@ export default function IndexPage(props) {
183179
}
184180
```
185181

186-
When using the `next/router` methods directly, you can specify the `locale` that should be used via the transition options. For example:
182+
`next/router` メソッドを直接使用する場合、遷移オプションとして適用されるべき `locale` を指定できます。例としては、以下のようになります:
187183

188184
```jsx
189185
import { useRouter } from 'next/router'
@@ -203,7 +199,7 @@ export default function IndexPage(props) {
203199
}
204200
```
205201

206-
If you have a `href` that already includes the locale you can opt-out of automatically handling the locale prefixing:
202+
既にロケールを含む `href` を使用している場合は、ロケールプレフィックスの自動的な処理を適用しないようにできます。
207203

208204
```jsx
209205
import Link from 'next/link'
@@ -217,34 +213,34 @@ export default function IndexPage(props) {
217213
}
218214
```
219215

220-
## Leveraging the NEXT_LOCALE cookie
216+
## NEXT_LOCALE クッキーの活用
221217

222-
Next.js supports overriding the accept-language header with a `NEXT_LOCALE=the-locale` cookie. This cookie can be set using a language switcher and then when a user comes back to the site it will leverage the locale specified in the cookie.
218+
Next.js accept-language ヘッダーを `NEXT_LOCALE=the-locale` クッキーでオーバーライドすることをサポートしています。このクッキーは言語スイッチャーを使って設定でき、ユーザーがサイトに戻ってくると、クッキーで指定されたロケールを利用するようになります。
223219

224-
For example, if a user prefers the locale `fr` but a `NEXT_LOCALE=en` cookie is set the `en` locale will be used instead until the cookie is removed or expired.
220+
例えば、ユーザーはロケール `fr` を好む一方、`NEXT_LOCALE=en` クッキーが設定されている場合、クッキーが削除されるか期限切れになるまで `en` ロケールが代わりに使われます。
225221

226-
## Search Engine Optimization
222+
## 検索エンジン最適化
227223

228-
Since Next.js knows what language the user is visiting it will automatically add the `lang` attribute to the `<html>` tag.
224+
Next.js はユーザーが訪れている言語を把握しているので、自動的に `<html>` タグに `lang` 属性を追加します。
229225

230-
Next.js doesn't know about variants of a page so it's up to you to add the `hreflang` meta tags using [`next/head`](/docs/api-reference/next/head.md). You can learn more about `hreflang` in the [Google Webmasters documentation](https://support.google.com/webmasters/answer/189077).
226+
Next.js はページの複数バージョンについて把握していないので、`next/head` を使って `hreflang` メタタグを追加するかどうかは実装次第です。`hreflang` の詳細については [Google Webmasters ドキュメント](https://support.google.com/webmasters/answer/189077)を参照してください。
231227

232-
## How does this work with Static Generation?
228+
## 静的生成ではどのように動作しますか?
233229

234-
> Note that Internationalized Routing does not integrate with [`next export`](/docs/advanced-features/static-html-export.md) as `next export` does not leverage the Next.js routing layer. Hybrid Next.js applications that do not use `next export` are fully supported.
230+
> `next export` は Next.js ルーティングレイヤーを利用しないため、国際化されたルーティングは `next export` と統合されないことに注意してください。`next export` を使用しないハイブリッド Next.js アプリケーションは完全にサポートされています。
235231
236-
### Automatically Statically Optimized Pages
232+
### 自動的に静的最適化されたページ
237233

238-
For pages that are [automatically statically optimized](/docs/advanced-features/automatic-static-optimization.md), a version of the page will be generated for each locale.
234+
自動的に静的最適化([Automatic Static Optimization](/docs/advanced-features/automatic-static-optimization))されたページについては、ロケールごとにページのバージョンが生成されます。
239235

240-
### Non-dynamic getStaticProps Pages
236+
### 非動的な getStaticProps ページ
241237

242-
For non-dynamic `getStaticProps` pages, a version is generated for each locale like above. `getStaticProps` is called with each `locale` that is being rendered. If you would like to opt-out of a certain locale from being pre-rendered, you can return `notFound: true` from `getStaticProps` and this variant of the page will not be generated.
238+
動的ではない `getStaticProps` ページの場合、上記と同様にロケールごとにバージョンが生成されます。 `getStaticProps` は、レンダリングされる `locale` ごとに呼び出されます。特定のロケールをプリレンダリングから除外したい場合は、`getStaticProps``notFound: true` を返すと、そのページのバージョンは生成されないようになります。
243239

244240
```js
245241
export async function getStaticProps({ locale }) {
246-
// Call an external API endpoint to get posts.
247-
// You can use any data fetching library
242+
// 外部APIエンドポイントを呼び出して投稿を取得。
243+
// どのようなデータ取得ライブラリでも使えます。
248244
const res = await fetch(`https://.../posts?locale=${locale}`)
249245
const posts = await res.json()
250246

@@ -254,8 +250,8 @@ export async function getStaticProps({ locale }) {
254250
}
255251
}
256252

257-
// By returning { props: posts }, the Blog component
258-
// will receive `posts` as a prop at build time
253+
// { props: posts } を返すことで、Blog コンポーネントは
254+
// ビルド時に `posts` を props として受け取ります。
259255
return {
260256
props: {
261257
posts,
@@ -264,9 +260,9 @@ export async function getStaticProps({ locale }) {
264260
}
265261
```
266262

267-
### Dynamic getStaticProps Pages
263+
### 動的な getStaticProps ページ
268264

269-
For dynamic `getStaticProps` pages, any locale variants of the page that is desired to be prerendered needs to be returned from [`getStaticPaths`](/docs/basic-features/data-fetching.md#getstaticpaths-static-generation). Along with the `params` object that can be returned for the `paths`, you can also return a `locale` field specifying which locale you want to render. For example:
265+
動的な `getStaticProps` ページの場合、 プリレンダリングしたいページのロケールバージョンを `getStaticPaths` で返す必要があります。`paths` として返される `params` オブジェクトに加えて、レンダリングしたいロケールを指定した `locale` フィールドを返すこともできます。例としては、以下のようになります:
270266

271267
```js
272268
// pages/blog/[slug].js

0 commit comments

Comments
 (0)