-
-
Notifications
You must be signed in to change notification settings - Fork 815
i18n(ja): added translation for route-data-reference
#3463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kenzo-Wada
wants to merge
4
commits into
withastro:main
Choose a base branch
from
Kenzo-Wada:i18n/route-data-reference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
--- | ||
title: ルートデータ | ||
description: Starlight のルートデータオブジェクトに関する完全なリファレンスドキュメントです。 | ||
--- | ||
|
||
Starlight のルートデータオブジェクトには、現在のページに関する情報が含まれています。 | ||
Starlight のデータモデルがどのように機能するかについては、[「ルートデータ」ガイド](/ja/guides/route-data/) を参照してください。 | ||
|
||
Astro コンポーネント内では、`Astro.locals.starlightRoute` からルートデータにアクセスできます。 | ||
|
||
```astro {4} | ||
--- | ||
// src/components/Custom.astro | ||
|
||
const { hasSidebar } = Astro.locals.starlightRoute; | ||
--- | ||
``` | ||
|
||
[ルートミドルウェア](/ja/guides/route-data/#ルートデータのカスタマイズ) 内では、ミドルウェア関数に渡される context オブジェクトからルートデータにアクセスします。 | ||
|
||
```ts {5} | ||
// src/routeData.ts | ||
import { defineRouteMiddleware } from '@astrojs/starlight/route-data'; | ||
|
||
export const onRequest = defineRouteMiddleware((context) => { | ||
const { hasSidebar } = context.locals.starlightRoute; | ||
}); | ||
``` | ||
|
||
## `starlightRoute` | ||
|
||
`starlightRoute` オブジェクトには、次のプロパティがあります。 | ||
|
||
### `dir` | ||
|
||
**型:** `'ltr' | 'rtl'` | ||
|
||
ページの文字方向。 | ||
|
||
### `lang` | ||
|
||
**型:** `string` | ||
|
||
このページのロケールを示す BCP-47 言語タグ。例: `en`, `zh-CN`, `pt-BR`。 | ||
|
||
### `locale` | ||
|
||
**型:** `string | undefined` | ||
|
||
言語が提供されるベースパス。ルートロケールスラッグの場合は `undefined`。 | ||
|
||
### `siteTitle` | ||
|
||
**型:** `string` | ||
|
||
このページのロケールに対応するサイトタイトル。 | ||
|
||
### `siteTitleHref` | ||
|
||
**型:** `string` | ||
|
||
サイトタイトルの `href` 属性に設定される値で、トップページへのリンクです。 | ||
多言語サイトの場合は現在のロケールを含みます(例: `/en/` や `/zh-cn/`)。 | ||
|
||
### `slug` | ||
|
||
**型:** `string` | ||
|
||
コンテンツファイル名から生成されたこのページのスラッグ。 | ||
|
||
このプロパティは非推奨であり、今後のバージョンで削除される予定です。 | ||
[Starlight の `docsLoader`](/ja/manual-setup/#コンテンツコレクションの設定) を使用して新しいコンテンツレイヤー API に移行し、代わりに [`id`](#id) プロパティを使用してください。 | ||
|
||
### `id` | ||
|
||
**型:** `string` | ||
|
||
[`legacy.collections`](https://docs.astro.build/ja/reference/legacy-flags/#collections) フラグを使用している場合は、コンテンツファイル名に基づくこのページの一意の ID、またはスラッグ。 | ||
|
||
### `isFallback` | ||
|
||
**型:** `boolean | undefined` | ||
|
||
現在の言語で未翻訳のページが既定ロケールのフォールバックコンテンツを使用している場合に `true`。 | ||
多言語サイトでのみ使用されます。 | ||
|
||
### `entryMeta` | ||
|
||
**型:** `{ dir: 'ltr' | 'rtl'; lang: string }` | ||
|
||
ページコンテンツのロケールメタデータ。 | ||
ページがフォールバックコンテンツを使用している場合、トップレベルのロケール値とは異なることがあります。 | ||
|
||
### `entry` | ||
|
||
現在のページに対応する Astro コンテンツコレクションのエントリ。 | ||
現在のページの frontmatter 値は `entry.data` に含まれます。 | ||
|
||
```ts | ||
entry: { | ||
data: { | ||
title: string; | ||
description: string | undefined; | ||
// その他の値 | ||
} | ||
} | ||
``` | ||
|
||
このオブジェクトの構造については、[Astro の Collection Entry Type](https://docs.astro.build/ja/reference/modules/astro-content/#collectionentry) リファレンスを参照してください。 | ||
|
||
### `sidebar` | ||
|
||
**型:** `SidebarEntry[]` | ||
|
||
このページに対応するサイトナビゲーションサイドバーのエントリ。 | ||
|
||
### `hasSidebar` | ||
|
||
**型:** `boolean` | ||
|
||
このページでサイドバーを表示するかどうか。 | ||
|
||
### `pagination` | ||
|
||
**型:** `{ prev?: Link; next?: Link }` | ||
|
||
サイドバーが有効な場合、前後のページへのリンク。 | ||
|
||
### `toc` | ||
|
||
**型:** `{ minHeadingLevel: number; maxHeadingLevel: number; items: TocItem[] } | undefined` | ||
|
||
このページの目次(有効な場合)。 | ||
|
||
### `headings` | ||
|
||
**型:** `{ depth: number; slug: string; text: string }[]` | ||
|
||
現在のページから抽出されたすべての Markdown 見出しの配列。 | ||
Starlight の設定に従う目次コンポーネントを作成したい場合は、代わりに [`toc`](#toc) を使用してください。 | ||
|
||
### `lastUpdated` | ||
|
||
**型:** `Date | undefined` | ||
|
||
このページが最後に更新された日時を表す JavaScript の `Date` オブジェクト(有効な場合)。 | ||
|
||
### `editUrl` | ||
|
||
**型:** `URL | undefined` | ||
|
||
このページを編集できるアドレスの `URL` オブジェクト(有効な場合)。 | ||
|
||
### `head` | ||
|
||
**型:** [`HeadConfig[]`](/ja/reference/configuration/#headconfig) | ||
|
||
現在のページの `<head>` に含めるすべてのタグの配列。 | ||
`<title>` や `<meta charset="utf-8">` などの重要なタグが含まれます。 | ||
|
||
## ユーティリティ | ||
|
||
### `defineRouteMiddleware()` | ||
|
||
ルートミドルウェアモジュールに型を付けるには、`defineRouteMiddleware()` ユーティリティを使用します。 | ||
|
||
```ts "defineRouteMiddleware" | ||
// src/routeData.ts | ||
import { defineRouteMiddleware } from '@astrojs/starlight/route-data'; | ||
|
||
export const onRequest = defineRouteMiddleware((context) => { | ||
// ... | ||
}); | ||
``` | ||
|
||
### `StarlightRouteData` 型 | ||
|
||
Starlight のルートデータを扱うコードを書く場合、`StarlightRouteData` 型をインポートして | ||
`Astro.locals.starlightRoute` の構造と一致させることができます。 | ||
|
||
次の例では、`usePageTitleInTOC()` 関数がルートデータを更新し、目次内の最初の項目ラベルをデフォルトの「Overview」から現在のページタイトルに置き換えます。 | ||
`StarlightRouteData` 型を使うことで、ルートデータの変更が正しいかどうかを検証できます。 | ||
|
||
```ts "StarlightRouteData" | ||
// src/route-utils.ts | ||
import type { StarlightRouteData } from '@astrojs/starlight/route-data'; | ||
|
||
export function usePageTitleInTOC(starlightRoute: StarlightRouteData) { | ||
const overviewLink = starlightRoute.toc?.items[0]; | ||
if (overviewLink) { | ||
overviewLink.text = starlightRoute.entry.data.title; | ||
} | ||
} | ||
``` | ||
|
||
この関数は次のようにルートミドルウェアから呼び出すことができます。 | ||
|
||
```ts {3,6} | ||
// src/route-middleware.ts | ||
import { defineRouteMiddleware } from '@astrojs/starlight/route-data'; | ||
import { usePageTitleInTOC } from './route-utils'; | ||
|
||
export const onRequest = defineRouteMiddleware((context) => { | ||
usePageTitleInTOC(context.locals.starlightRoute); | ||
}); | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the translation @Kenzo-Wada! After updating the branch with your changes from #3462, link checks are passing 🎉
The translation looks good, but I have one stylistic query: in many places on this page, paragraphs with multiple sentences are broken up by newlines, like on line 6 here.
You can see the rendered result:


Whereas the equivalent English paragraph is not broken up in the same way:
Was that an intentional stylistic decision? I noticed other pages translated into Japanse don’t do this and match the English line breaks.