Skip to content

Commit b110672

Browse files
doc: Svelte/Runtime/Contextを翻訳 (#61)
1 parent 128cd5e commit b110672

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

apps/svelte.dev/content/docs/svelte/06-runtime/02-context.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ NOTE: do not edit this file, it is generated in apps/svelte.dev/scripts/sync-doc
33
title: Context
44
---
55

6-
Context allows components to access values owned by parent components without passing them down as props (potentially through many layers of intermediate components, known as 'prop-drilling'). The parent component sets context with `setContext(key, value)`...
6+
Context を使うと、コンポーネントは親コンポーネントが所有する値に、 props を介さずアクセスできます。(中間コンポーネントを何層も経由する'prop-drilling'という手法を回避できます。) 親コンポーネントは `setContext(key, value)` で context を設定します...
77

88
```svelte
99
<!--- file: Parent.svelte --->
@@ -14,7 +14,7 @@ Context allows components to access values owned by parent components without pa
1414
</script>
1515
```
1616

17-
...and the child retrieves it with `getContext`:
17+
...そして、子コンポーネントは `getContext` で context を取得します:
1818

1919
```svelte
2020
<!--- file: Child.svelte --->
@@ -27,21 +27,21 @@ Context allows components to access values owned by parent components without pa
2727
<h1>{message}, inside Child.svelte</h1>
2828
```
2929

30-
This is particularly useful when `Parent.svelte` is not directly aware of `Child.svelte`, but instead renders it as part of a `children` [snippet](snippet) ([demo](/playground/untitled#H4sIAAAAAAAAE42Q3W6DMAyFX8WyJgESK-oto6hTX2D3YxcM3IIUQpR40yqUd58CrCXsp7tL7HNsf2dAWXaEKR56yfTBGOOxFWQwfR6Qz8q1XAHjL-GjUhvzToJd7bU09FO9ctMkG0wxM5VuFeeFLLjtVK8ZnkpNkuGo-w6CTTJ9Z3PwsBAemlbUF934W8iy5DpaZtOUcU02-ZLcaS51jHEkTFm_kY1_wfOO8QnXrb8hBzDEc6pgZ4gFoyz4KgiD7nxfTe8ghqAhIfrJ46cTzVZBbkPlODVJsLCDO6V7ZcJoncyw1yRr0hd1GNn_ZbEM3I9i1bmVxOlWElUvDUNHxpQngt3C4CXzjS1rtvkw22wMrTRtTbC8Lkuabe7jvthPPe3DofYCAAA=)):
30+
これは、 `Parent.svelte` `Child.svelte` を直接含んでおらず, `children` [snippet](snippet) の一部としてレンダリングするとき、特に便利です。 ([デモ](/playground/untitled#H4sIAAAAAAAAE42Q3W6DMAyFX8WyJgESK-oto6hTX2D3YxcM3IIUQpR40yqUd58CrCXsp7tL7HNsf2dAWXaEKR56yfTBGOOxFWQwfR6Qz8q1XAHjL-GjUhvzToJd7bU09FO9ctMkG0wxM5VuFeeFLLjtVK8ZnkpNkuGo-w6CTTJ9Z3PwsBAemlbUF934W8iy5DpaZtOUcU02-ZLcaS51jHEkTFm_kY1_wfOO8QnXrb8hBzDEc6pgZ4gFoyz4KgiD7nxfTe8ghqAhIfrJ46cTzVZBbkPlODVJsLCDO6V7ZcJoncyw1yRr0hd1GNn_ZbEM3I9i1bmVxOlWElUvDUNHxpQngt3C4CXzjS1rtvkw22wMrTRtTbC8Lkuabe7jvthPPe3DofYCAAA=)):
3131

3232
```svelte
3333
<Parent>
3434
<Child />
3535
</Parent>
3636
```
3737

38-
The key (`'my-context'`, in the example above) and the context itself can be any JavaScript value.
38+
キー (上記の例では `'my-context'`) と context 自体を、任意の JavaScript の値にすることができます。
3939

40-
In addition to [`setContext`](svelte#setContext) and [`getContext`](svelte#getContext), Svelte exposes [`hasContext`](svelte#hasContext) and [`getAllContexts`](svelte#getAllContexts) functions.
40+
[`setContext`](svelte#setContext) [`getContext`](svelte#getContext) に加えて、 Svelte [`hasContext`](svelte#hasContext) [`getAllContexts`](svelte#getAllContexts) 関数を提供しています。
4141

42-
## Using context with state
42+
## state と context を使用する <!--Using-context-with-state-->
4343

44-
You can store reactive state in context ([demo](/playground/untitled#H4sIAAAAAAAAE41R0W6DMAz8FSuaBNUQdK8MkKZ-wh7HHihzu6hgosRMm1D-fUpSVNq12x4iEvvOx_kmQU2PIhfP3DCCJGgHYvxkkYid7NCI_GUS_KUcxhVEMjOelErNB3bsatvG4LW6n0ZsRC4K02qpuKqpZtmrQTNMYJA3QRAs7PTQQxS40eMCt3mX3duxnWb-lS5h7nTI0A4jMWoo4c44P_Hku-zrOazdy64chWo-ScfRkRgl8wgHKrLTH1OxHZkHgoHaTraHcopXUFYzPPVfuC_hwQaD1GrskdiNCdQwJljJqlvXfyqVsA5CGg0uRUQifHw56xFtciO75QrP07vo_JXf_tf8yK2ezDKY_ZWt_1y2qqYzv7bI1IW1V_sN19m-07wCAAA=))...
44+
リアクティブな state context に保存できます ([デモ](/playground/untitled#H4sIAAAAAAAAE41R0W6DMAz8FSuaBNUQdK8MkKZ-wh7HHihzu6hgosRMm1D-fUpSVNq12x4iEvvOx_kmQU2PIhfP3DCCJGgHYvxkkYid7NCI_GUS_KUcxhVEMjOelErNB3bsatvG4LW6n0ZsRC4K02qpuKqpZtmrQTNMYJA3QRAs7PTQQxS40eMCt3mX3duxnWb-lS5h7nTI0A4jMWoo4c44P_Hku-zrOazdy64chWo-ScfRkRgl8wgHKrLTH1OxHZkHgoHaTraHcopXUFYzPPVfuC_hwQaD1GrskdiNCdQwJljJqlvXfyqVsA5CGg0uRUQifHw56xFtciO75QrP07vo_JXf_tf8yK2ezDKY_ZWt_1y2qqYzv7bI1IW1V_sN19m-07wCAAA=))...
4545

4646
```svelte
4747
<script>
@@ -64,27 +64,27 @@ You can store reactive state in context ([demo](/playground/untitled#H4sIAAAAAAA
6464
<Child />
6565
```
6666

67-
...though note that if you _reassign_ `counter` instead of updating it, you will 'break the link' — in other words instead of this...
67+
...ただし、 `counter` _再代入する_ (更新ではなく)と「リンクが切れる」点に注意してください。 つまり、次のようにするのではなく...
6868

6969
```svelte
7070
<button onclick={() => counter = { count: 0 }}>
7171
reset
7272
</button>
7373
```
7474

75-
...you must do this:
75+
...次のようにします:
7676

7777
```svelte
7878
<button onclick={() => +++counter.count = 0+++}>
7979
reset
8080
</button>
8181
```
8282

83-
Svelte will warn you if you get it wrong.
83+
もしあなたが間違えても、 Svelte が警告してくれます。
8484

85-
## Type-safe context
85+
## 型安全な context <!--Type-safe-context-->
8686

87-
A useful pattern is to wrap the calls to `setContext` and `getContext` inside helper functions that let you preserve type safety:
87+
便利なパターンとして、型安全性を維持できるヘルパー関数で `setContext` `getContext` の呼び出しをラップする方法があります:
8888

8989
```js
9090
/// file: context.js
@@ -107,9 +107,9 @@ export function getUserContext() {
107107
}
108108
```
109109

110-
## Replacing global state
110+
## グローバル state の置き換え<!--Replacing-global-state-->
111111

112-
When you have state shared by many different components, you might be tempted to put it in its own module and just import it wherever it's needed:
112+
多くの異なるコンポーネントで共有される state があるとき、 state を独自のモジュールに配置し、必要に応じてインポートしたくなるかもしれません:
113113

114114
```js
115115
/// file: state.svelte.js
@@ -121,7 +121,7 @@ export const myGlobalState = $state({
121121
});
122122
```
123123

124-
In many cases this is perfectly fine, but there is a risk: if you mutate the state during server-side rendering (which is discouraged, but entirely possible!)...
124+
大部分のケースではまったく問題ありませんが、リスクがあります。サーバーサイドレンダリング中に state を変更すると(これは非推奨ですが、完全に可能です!)...
125125

126126
```svelte
127127
<!--- file: App.svelte ---->
@@ -136,4 +136,4 @@ In many cases this is perfectly fine, but there is a risk: if you mutate the sta
136136
</script>
137137
```
138138

139-
...then the data may be accessible by the _next_ user. Context solves this problem because it is not shared between requests.
139+
...すると、そのデータに _次の_ ユーザーがアクセスできる可能性があります。 context はリクエスト間で共有されないため、この問題を解決します。

0 commit comments

Comments
 (0)