Skip to content

Commit b5e17c4

Browse files
doc: svelte/awaitの翻訳 (#67)
1 parent ddcc1cf commit b5e17c4

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

apps/svelte.dev/content/docs/svelte/03-template-syntax/19-await-expressions.md

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

6-
As of Svelte 5.36, you can use the `await` keyword inside your components in three places where it was previously unavailable:
6+
Svelte5.36 以降、コンポーネント内のうち、これまで使えなかった3箇所で `await` キーワードを使えるようになりました:
77

8-
- at the top level of your component's `<script>`
9-
- inside `$derived(...)` declarations
10-
- inside your markup
8+
- コンポーネントの `<script>` トップレベル
9+
- `$derived(...)` 宣言の内部
10+
- マークアップの内部
1111

12-
This feature is currently experimental, and you must opt in by adding the `experimental.async` option wherever you [configure](/docs/kit/configuration) Svelte, usually `svelte.config.js`:
12+
この機能は実験的なものであり、Svelteの[設定](/docs/kit/configuration)(通常は `svelte.config.js`)に `experimental.async` オプションを追加して、明示的に有効にする必要があります:
1313

1414
```js
1515
/// file: svelte.config.js
@@ -22,11 +22,11 @@ export default {
2222
};
2323
```
2424

25-
The experimental flag will be removed in Svelte 6.
25+
この実験的なフラグは Svelte 6 で削除される予定です。
2626

27-
## Boundaries
27+
## Boundary(境界) <!--Boundaries-->
2828

29-
Currently, you can only use `await` inside a [`<svelte:boundary>`](svelte-boundary) with a `pending` snippet:
29+
現在、 `await` `pending` snippetを持つ [`<svelte:boundary>`](svelte-boundary) の内部でのみ使えます:
3030

3131
```svelte
3232
<svelte:boundary>
@@ -38,13 +38,13 @@ Currently, you can only use `await` inside a [`<svelte:boundary>`](svelte-bounda
3838
</svelte:boundary>
3939
```
4040

41-
This restriction will be lifted once Svelte supports asynchronous server-side rendering (see [caveats](#Caveats)).
41+
この制限は、 Svelte が非同期のサーバーサイドレンダリングをサポートするようになれば解除されます([注意事項](#Caveats)を参照)。
4242

43-
> [!NOTE] In the [playground](/playground), your app is rendered inside a boundary with an empty pending snippet, so that you can use `await` without having to create one.
43+
> [!NOTE] [プレイグラウンド](/playground)では、アプリは空の pending snippet を持つ boudary 内でレンダリングされるため、自分で作成しなくても `await` を使えます。
4444
45-
## Synchronized updates
45+
## 同期された更新 <!--Synchronized-updates-->
4646

47-
When an `await` expression depends on a particular piece of state, changes to that state will not be reflected in the UI until the asynchronous work has completed, so that the UI is not left in an inconsistent state. In other words, in an example like [this](/playground/untitled#H4sIAAAAAAAAE42QsWrDQBBEf2VZUkhYRE4gjSwJ0qVMkS6XYk9awcFpJe5Wdoy4fw-ycdykSPt2dpiZFYVGxgrf2PsJTlPwPWTcO-U-xwIH5zli9bminudNtwEsbl-v8_wYj-x1Y5Yi_8W7SZRFI1ZYxy64WVsjRj0rEDTwEJWUs6f8cKP2Tp8vVIxSPEsHwyKdukmA-j6jAmwO63Y1SidyCsIneA_T6CJn2ZBD00Jk_XAjT4tmQwEv-32eH6AsgYK6wXWOPPTs6Xy1CaxLECDYgb3kSUbq8p5aaifzorCt0RiUZbQcDIJ10ldH8gs3K6X2Xzqbro5zu1KCHaw2QQPrtclvwVSXc2sEC1T-Vqw0LJy-ClRy_uSkx2ogHzn9ADZ1CubKAQAA)...
47+
ある `await` 式が特定の state に依存しているとき、その state への変更は、非同期処理が完了するまでUIに反映されません。UIが矛盾した状態にならないようにするためです。つまり、[こちら](/playground/untitled#H4sIAAAAAAAAE42QsWrDQBBEf2VZUkhYRE4gjSwJ0qVMkS6XYk9awcFpJe5Wdoy4fw-ycdykSPt2dpiZFYVGxgrf2PsJTlPwPWTcO-U-xwIH5zli9bminudNtwEsbl-v8_wYj-x1Y5Yi_8W7SZRFI1ZYxy64WVsjRj0rEDTwEJWUs6f8cKP2Tp8vVIxSPEsHwyKdukmA-j6jAmwO63Y1SidyCsIneA_T6CJn2ZBD00Jk_XAjT4tmQwEv-32eH6AsgYK6wXWOPPTs6Xy1CaxLECDYgb3kSUbq8p5aaifzorCt0RiUZbQcDIJ10ldH8gs3K6X2Xzqbro5zu1KCHaw2QQPrtclvwVSXc2sEC1T-Vqw0LJy-ClRy_uSkx2ogHzn9ADZ1CubKAQAA)のような例では...
4848

4949
```svelte
5050
<script>
@@ -63,46 +63,46 @@ When an `await` expression depends on a particular piece of state, changes to th
6363
<p>{a} + {b} = {await add(a, b)}</p>
6464
```
6565

66-
...if you increment `a`, the contents of the `<p>` will _not_ immediately update to read this —
66+
...`a` の値をインクリメントしても、 `<p>` の内容は次のようには _なりません。_
6767

6868
```html
6969
<p>2 + 2 = 3</p>
7070
```
7171

72-
— instead, the text will update to `2 + 2 = 4` when `add(a, b)` resolves.
72+
実際には、`add(a, b)`が解決されたときに、`<p>`の内容を `2 + 2 = 4` に更新します。
7373

74-
Updates can overlap — a fast update will be reflected in the UI while an earlier slow update is still ongoing.
74+
更新は重複することがあります。先行する更新が遅く、まだ進行中であっても、続く更新が速ければ、速いほうが先にUIに反映されます。
7575

76-
## Concurrency
76+
## 並行性 <!--Concurrency-->
7777

78-
Svelte will do as much asynchronous work as it can in parallel. For example if you have two `await` expressions in your markup...
78+
Svelte は可能な限り非同期処理を並行におこないます。例えば、マークアップ内に2つの `await` 式があるとき...
7979

8080
```svelte
8181
<p>{await one()}</p>
8282
<p>{await two()}</p>
8383
```
8484

85-
...both functions will run at the same time, as they are independent expressions, even though they are _visually_ sequential.
85+
...それらは独立した式ですので、 _見た目上は_ 順次実行されているように見えても、両方の関数が同時に実行されます。
8686

87-
This does not apply to sequential `await` expressions inside your `<script>` or inside async functions — these run like any other asynchronous JavaScript. An exception is that independent `$derived` expressions will update independently, even though they will run sequentially when they are first created:
87+
これは、`<script>` 内や非同期関数内の連続した `await` 式には適用されません。これらは他の非同期JavaScriptと同じように実行されます。例外として、独立した `$derived` 式は、最初の作成時には順次実行されますが、そのあとは独立して更新されます:
8888

8989
```js
9090
async function one() { return 1; }
9191
async function two() { return 2; }
9292
// ---cut---
93-
// these will run sequentially the first time,
94-
// but will update independently
93+
// これらは最初は順次実行されますが、
94+
// そのあとは独立して更新されます
9595
let a = $derived(await one());
9696
let b = $derived(await two());
9797
```
9898

99-
> [!NOTE] If you write code like this, expect Svelte to give you an [`await_waterfall`](runtime-warnings#Client-warnings-await_waterfall) warning
99+
> [!NOTE] このようなコードを書くと、Svelteから [`await_waterfall`](runtime-warnings#Client-warnings-await_waterfall) 警告が表示されます。
100100
101-
## Indicating loading states
101+
## ローディング状態の表示<!--Indicating-loading-states-->
102102

103-
In addition to the nearest boundary's [`pending`](svelte-boundary#Properties-pending) snippet, you can indicate that asynchronous work is ongoing with [`$effect.pending()`]($effect#$effect.pending).
103+
`await` によるローディング状態は、それを囲むもっとも内側の `<svelte:boundary>` に定義された [`pending`](svelte-boundary#Properties-pending) によって表示されます。それに加えて、 [`$effect.pending()`]($effect#$effect.pending) を使っても、非同期処理が進行中であることを示せます。
104104

105-
You can also use [`settled()`](svelte#settled) to get a promise that resolves when the current update is complete:
105+
また、 [`settled()`](svelte#settled) を使うと、現在の更新が完了したときに解決(resolve)される Promise を取得できます:
106106

107107
```js
108108
let color = 'red';
@@ -114,32 +114,32 @@ import { tick, settled } from 'svelte';
114114
async function onclick() {
115115
updating = true;
116116

117-
// without this, the change to `updating` will be
118-
// grouped with the other changes, meaning it
119-
// won't be reflected in the UI
117+
// これがないと、`updating` への変更は
118+
// 他の変更とまとめられてしまうため、
119+
// UI に反映されません
120120
await tick();
121121

122122
color = 'octarine';
123123
answer = 42;
124124

125125
await settled();
126126

127-
// any updates affected by `color` or `answer`
128-
// have now been applied
127+
// `color` `answer` の変更に影響される
128+
// あらゆる更新が、この時点で適用済みになります
129129
updating = false;
130130
}
131131
```
132132

133-
## Error handling
133+
## エラーハンドリング <!--Error-handling-->
134134

135-
Errors in `await` expressions will bubble to the nearest [error boundary](svelte-boundary).
135+
`await` 式のエラーは、もっとも近い [error boundary](svelte-boundary) に伝播します。
136136

137-
## Caveats
137+
## 注意事項 <!--Caveats-->
138138

139-
As an experimental feature, the details of how `await` is handled (and related APIs like `$effect.pending()`) are subject to breaking changes outside of a semver major release, though we intend to keep such changes to a bare minimum.
139+
実験的な機能であるため、 `await` 扱いの詳細(および `$effect.pending()` のような関連API)は、セマンティックバージョニングのメジャーリリース外では破壊的変更がおこなわれる可能性があります。ただし、そのような変更は最小限に抑えるつもりです。
140140

141-
Currently, server-side rendering is synchronous. If a `<svelte:boundary>` with a `pending` snippet is encountered during SSR, only the `pending` snippet will be rendered.
141+
現在、サーバーサイドレンダリングは同期的です。SSR中に `pending` snippet を持つ `<svelte:boundary>` が検出されたとき、 `pending` snippet のみがレンダリングされます。
142142

143-
## Breaking changes
143+
## 破壊的変更 <!--Breaking-changes-->
144144

145-
Effects run in a slightly different order when the `experimental.async` option is `true`. Specifically, _block_ effects like `{#if ...}` and `{#each ...}` now run before an `$effect.pre` or `beforeUpdate` in the same component, which means that in [very rare situations](/playground/untitled?#H4sIAAAAAAAAE22R3VLDIBCFX2WLvUhnTHsf0zre-Q7WmfwtFV2BgU1rJ5N3F0jaOuoVcPbw7VkYhK4_URTiGYkMnIyjDjLsFGO3EvdCKkIvipdB8NlGXxSCPt96snbtj0gctab2-J_eGs2oOWBE6VunLO_2es-EDKZ5x5ZhC0vPNWM2gHXGouNzAex6hHH1cPHil_Lsb95YT9VQX6KUAbS2DrNsBdsdDFHe8_XSYjH1SrhELTe3MLpsemajweiWVPuxHSbKNd-8eQTdE0EBf4OOaSg2hwNhhE_ABB_ulJzjj9FULvIcqgm5vnAqUB7wWFMfhuugQWkcAr8hVD-mq8D12kOep24J_IszToOXdveGDsuNnZwbJUNlXsKnhJdhUcTo42s41YpOSneikDV5HL8BktM6yRcCAAA=) it is possible to update a block that should no longer exist, but only if you update state inside an effect, [which you should avoid]($effect#When-not-to-use-$effect).
145+
`experimental.async` オプションが `true` のとき、効果の実行順序がわずかに異なります。具体的には、 `{#if ...}` `{#each ...}` のような _ブロック_ の効果を、 `$effect.pre` `beforeUpdate` の前に実行するようになります。これにより、[非常にまれな状況](/playground/untitled?#H4sIAAAAAAAAE22R3VLDIBCFX2WLvUhnTHsf0zre-Q7WmfwtFV2BgU1rJ5N3F0jaOuoVcPbw7VkYhK4_URTiGYkMnIyjDjLsFGO3EvdCKkIvipdB8NlGXxSCPt96snbtj0gctab2-J_eGs2oOWBE6VunLO_2es-EDKZ5x5ZhC0vPNWM2gHXGouNzAex6hHH1cPHil_Lsb95YT9VQX6KUAbS2DrNsBdsdDFHe8_XSYjH1SrhELTe3MLpsemajweiWVPuxHSbKNd-8eQTdE0EBf4OOaSg2hwNhhE_ABB_ulJzjj9FULvIcqgm5vnAqUB7wWFMfhuugQWkcAr8hVD-mq8D12kOep24J_IszToOXdveGDsuNnZwbJUNlXsKnhJdhUcTo42s41YpOSneikDV5HL8BktM6yRcCAAA=)では、存在しないはずのブロックを更新してしまう可能性があります。ただし、これは効果内で state を更新した場合に限られますし、[そのような状況は避けるべきです]($effect#When-not-to-use-$effect)

0 commit comments

Comments
 (0)