Skip to content

Commit f4a6854

Browse files
committed
translate into Japanese
1 parent 6fe5cbc commit f4a6854

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

sites/svelte-5-preview/src/routes/docs/content/01-api/02-runes.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Todo {
6666

6767
## `$state.frozen`
6868

69-
State declared with `$state.frozen` cannot be mutated; it can only be _reassigned_. In other words, rather than assigning to a property of an object, or using an array method like `push`, replace the object or array altogether if you'd like to update it:
69+
`$state.frozen` で宣言された state は変更することができません、できるのは再代入だけです。言い換えると、もし更新したいのであれば、オブジェクトのプロパティに代入したり `push` のような配列のメソッドを使用するのではなく、オブジェクトや配列を完全に置き換える必要がある、ということです:
7070

7171
```diff
7272
<script>
@@ -89,28 +89,28 @@ State declared with `$state.frozen` cannot be mutated; it can only be _reassigne
8989
</p>
9090
```
9191

92-
This can improve performance with large arrays and objects that you weren't planning to mutate anyway, since it avoids the cost of making them reactive. Note that frozen state can _contain_ reactive state (for example, a frozen array of reactive objects).
92+
これによって、対象ををリアクティブにするコストを避けることができるため、変更するつもりのない大きな配列やオブジェクトを扱うときにパフォーマンスを改善することができます。凍結された(frozen) state にはリアテクティブな state を含めることができます(例えば、リアクティブなオブジェクトの凍結された配列、のように)。
9393

94-
> Objects and arrays passed to `$state.frozen` will be shallowly frozen using `Object.freeze()`. If you don't want this, pass in a clone of the object or array instead.
94+
> `$state.frozen` に渡されたオブジェクトや配列は、`Object.freeze()` を使用して浅く (shallowly) 凍結されます。こうしたくない場合は、代わりにオブジェクトや配列のクローンを渡してください。
9595
9696
## `$state.snapshot`
9797

98-
To take a static snapshot of a deeply reactive `$state` proxy, use `$state.snapshot`:
98+
深い (deeply) リアクティブな `$state` proxy の静的なスナップショットを取得するには、`$state.snapshot` を使用します:
9999

100100
```svelte
101101
<script>
102102
let counter = $state({ count: 0 });
103103
104104
function onclick() {
105-
// Will log `{ count: ... }` rather than `Proxy { ... }`
105+
// `Proxy { ... }` ではなく`{ count: ... }` がログ出力される
106106
console.log($state.snapshot(counter));
107107
}
108108
</script>
109109
```
110110

111-
This is handy when you want to pass some state to an external library or API that doesn't expect a proxy, such as `structuredClone`.
111+
これは、例えば `structuredClone` のような、proxy を受け取ることを想定していない API や外部のライブラリに state を渡すときに役立ちます。
112112

113-
> Note that `$state.snapshot` will clone the data when removing reactivity. If the value passed isn't a `$state` proxy, it will be returned as-is.
113+
> `$state.snapshot` はリアクティビティを削除するときにそのデータをクローンしていることにご注意ください。渡された値が `$state` proxy でない場合は、そのまま返されます。
114114
115115
## `$derived`
116116

@@ -155,7 +155,7 @@ This is handy when you want to pass some state to an external library or API tha
155155

156156
## `$derived.by`
157157

158-
Sometimes you need to create complex derivations that don't fit inside a short expression. In these cases, you can use `$derived.by` which accepts a function as its argument.
158+
時には、短い式には収まらない、複雑な導出(derivations)を作成する必要あります。そのような場合は、関数を引数に取る `$derived.by` を使用します。
159159

160160
```svelte
161161
<script>
@@ -174,7 +174,7 @@ Sometimes you need to create complex derivations that don't fit inside a short e
174174
</button>
175175
```
176176

177-
In essence, `$derived(expression)` is equivalent to `$derived.by(() => expression)`.
177+
本質的には、`$derived(expression)` `$derived.by(() => expression)` は同等のものです。
178178

179179
## `$effect`
180180

@@ -197,18 +197,18 @@ In essence, `$derived(expression)` is equivalent to `$derived.by(() => expressio
197197
<p>{count} doubled is {doubled}</p>
198198
```
199199

200-
`$effect` will automatically subscribe to any `$state` or `$derived` values it reads _synchronously_ and reruns whenever their values change — that means, values after an `await` or inside a `setTimeout` will _not_ be tracked. `$effect` will run after the DOM has been updated.
200+
`$effect` は 同期的に読み取った `$state` `$derived` の値を自動的にサブスクライブし、値が変わるたびに再実行されます。なお、その値が `await` の後や `setTimeout` の中にある場合はその値は追跡されません。`$effect` DOM が更新されたあとに実行されます。
201201

202202
```svelte
203203
<script>
204204
let count = $state(0);
205205
let doubled = $derived(count * 2);
206206
207207
$effect(() => {
208-
// runs after the DOM has been updated
209-
// when the component is mounted
210-
// and whenever `count` changes,
211-
// but not when `doubled` changes,
208+
// DOM が更新されたあとに実行されます。
209+
// コンポーネントがマウントされるときや、
210+
// `count` が変更されるたびに実行されますが、
211+
// `doubled` が変更されたときには実行されません。
212212
console.log(count);
213213
214214
setTimeout(() => console.log(doubled));
@@ -222,7 +222,7 @@ In essence, `$derived(expression)` is equivalent to `$derived.by(() => expressio
222222
<p>{count} doubled is {doubled}</p>
223223
```
224224

225-
An effect only reruns when the object it reads changes, not when a property inside it changes. If you want to react to _any_ change inside an object for inspection purposes at dev time, you may want to use [`inspect`](#$inspect).
225+
effect は読み取ったオブジェクトが変更された場合には再実行されますが、そのオブジェクトが持つプロパティが変更された場合には再実行されません。もし開発時に、検査(inspection)目的でオブジェクト内部のあらゆる変更にリアクティブにしたければ、[`inspect`](#$inspect) を使用するとよいでしょう。
226226

227227
```svelte
228228
<script>
@@ -232,20 +232,20 @@ An effect only reruns when the object it reads changes, not when a property insi
232232
});
233233
234234
$effect(() => {
235-
// never reruns, because object does not change,
236-
// only its property changes
235+
// これは再実行されません。objectのプロパティ(object.count)は変更されますが、
236+
// object自体は変更されないからです。
237237
object;
238238
console.log('object');
239239
});
240240
241241
$effect(() => {
242-
// reruns, because object.count changes
242+
// これは再実行されます。object.count は変更されるからです。
243243
object.count;
244244
console.log('object.count');
245245
});
246246
247247
$effect(() => {
248-
// reruns, because $derived produces a new object on each rerun
248+
// これは再実行されます。$derived は派生元(object.count)が変更されるたびに、新しいオブジェクトを生成するからです。
249249
derived_object;
250250
console.log('derived_object');
251251
});
@@ -258,23 +258,23 @@ An effect only reruns when the object it reads changes, not when a property insi
258258
<p>{object.count} doubled is {derived_object.doubled}</p>
259259
```
260260

261-
You can return a function from `$effect`, which will run immediately before the effect re-runs, and before it is destroyed ([demo](/#H4sIAAAAAAAAE42SzW6DMBCEX2Vl5RDaVCQ9JoDUY--9lUox9lKsGBvZC1GEePcaKPnpqSe86_m0M2t6ViqNnu0_e2Z4jWzP3pqGbRhdmrHwHWrCUHvbOjF2Ei-caijLTU4aCYRtDUEKK0-ccL2NDstNrbRWHoU10t8Eu-121gTVCssSBa3XEaQZ9GMrpziGj0p5OAccCgSHwmEgJZwrNNihg6MyhK7j-gii4uYb_YyGUZ5guQwzPdL7b_U4ZNSOvp9T2B3m1rB5cLx4zMkhtc7AHz7YVCVwEFzrgosTBMuNs52SKDegaPbvWnMH8AhUXaNUIY6-hHCldQhUIcyLCFlfAuHvkCKaYk8iYevGGgy2wyyJnpy9oLwG0sjdNe2yhGhJN32HsUzi2xOapNpl_bSLIYnDeeoVLZE1YI3QSpzSfo7-8J5PKbwOmdf2jC6JZyD7HxpPaMk93aHhF6utVKVCyfbkWhy-hh9Z3o_2nQIAAA==)).
261+
`$effect` は関数を返すことができます。その関数は、effect が再実行される直前と、破棄される直前に実行されます ([デモ](/#H4sIAAAAAAAAE42SzW6DMBCEX2Vl5RDaVCQ9JoDUY--9lUox9lKsGBvZC1GEePcaKPnpqSe86_m0M2t6ViqNnu0_e2Z4jWzP3pqGbRhdmrHwHWrCUHvbOjF2Ei-caijLTU4aCYRtDUEKK0-ccL2NDstNrbRWHoU10t8Eu-121gTVCssSBa3XEaQZ9GMrpziGj0p5OAccCgSHwmEgJZwrNNihg6MyhK7j-gii4uYb_YyGUZ5guQwzPdL7b_U4ZNSOvp9T2B3m1rB5cLx4zMkhtc7AHz7YVCVwEFzrgosTBMuNs52SKDegaPbvWnMH8AhUXaNUIY6-hHCldQhUIcyLCFlfAuHvkCKaYk8iYevGGgy2wyyJnpy9oLwG0sjdNe2yhGhJN32HsUzi2xOapNpl_bSLIYnDeeoVLZE1YI3QSpzSfo7-8J5PKbwOmdf2jC6JZyD7HxpPaMk93aHhF6utVKVCyfbkWhy-hh9Z3o_2nQIAAA==)).
262262

263263
```svelte
264264
<script>
265265
let count = $state(0);
266266
let milliseconds = $state(1000);
267267
268268
$effect(() => {
269-
// This will be recreated whenever `milliseconds` changes
269+
// この interval は `milliseconds`が変更されるたびに再作成されます
270270
const interval = setInterval(() => {
271271
count += 1;
272272
}, milliseconds);
273273
274274
return () => {
275-
// if a callback is provided, it will run
276-
// a) immediately before the effect re-runs
277-
// b) when the component is destroyed
275+
// コールバックが提供される場合、以下のときに実行されます
276+
// a) effect が再実行される直前
277+
// b) コンポーネントが破棄されるとき
278278
clearInterval(interval);
279279
};
280280
});
@@ -288,21 +288,21 @@ You can return a function from `$effect`, which will run immediately before the
288288

289289
### When not to use `$effect`
290290

291-
In general, `$effect` is best considered something of an escape hatch — useful for things like analytics and direct DOM manipulation — rather than a tool you should use frequently. In particular, avoid using it to synchronise state. Instead of this...
291+
一般的には、`$effect` は、頻繁に使用すべきツールというよりは、なんらかの (例えばアナリティクスや直接的な DOM 操作を行うのに便利な) エスケープハッチであると考えたほうがよいでしょう。特に、state の同期に使用するのは避けましょう。こうする代わりに…
292292

293293
```svelte
294294
<script>
295295
let count = $state(0);
296296
let doubled = $state();
297297
298-
// don't do this!
298+
// これをやってはいけません!
299299
$effect(() => {
300300
doubled = count * 2;
301301
});
302302
</script>
303303
```
304304

305-
...do this:
305+
…こうしましょう:
306306

307307
```svelte
308308
<script>
@@ -311,12 +311,12 @@ In general, `$effect` is best considered something of an escape hatch — useful
311311
</script>
312312
```
313313

314-
> For things that are more complicated than a simple expression like `count * 2`, you can also use [`$derived.by`](#$derived-by).
314+
> `count * 2` のようなシンプルな式ではなく、もっと複雑なものを扱う場合は、[`$derived.by`](#$derived-by) を使うこともできます。
315315
316-
When reacting to a state change and writing to a different state as a result, think about if it's possible to use callback props instead.
316+
ある state の変更に対してリアクティブに反応し、その結果として別のステートに書き込む場合は、代わりにコールバック props が使用できないか検討しましょう。
317317

318318
```svelte
319-
<!-- Don't do this -->
319+
<!-- これをやってはいけません -->
320320
<script>
321321
let value = $state();
322322
let value_uppercase = $state();
@@ -327,7 +327,7 @@ When reacting to a state change and writing to a different state as a result, th
327327
328328
<Text bind:value />
329329
330-
<!-- Do this instead: -->
330+
<!-- 代わりにこうしましょう: -->
331331
<script>
332332
let value = $state();
333333
let value_uppercase = $state();
@@ -340,7 +340,7 @@ When reacting to a state change and writing to a different state as a result, th
340340
<Text {value} {onValueChange}>
341341
```
342342

343-
If you want to have something update from above but also modify it from below (i.e. you want some kind of "writable `$derived`"), and events aren't an option, you can also use an object with getters and setters.
343+
何かを (コンポーネントツリーの) 上側から更新したいけれど、下側からも変更したい場合 (つまり、ある種の "書き込み可能な (writable) `$derived`" が欲しい場合)、かつ、event が選択肢にない場合、getter と setter を持つオブジェクトを使うこともできます。
344344

345345
```svelte
346346
<script>
@@ -358,7 +358,7 @@ If you want to have something update from above but also modify it from below (i
358358
<input bind:value={facade.value} />
359359
```
360360

361-
If you absolutely have to update `$state` within an effect and run into an infinite loop because you read and write to the same `$state`, use [untrack](functions#untrack).
361+
もし、どうしても `$state` effect の中で更新する必要があり、同じ `$state` を読み書きするために無限ループになってしまう場合は、[untrack](functions#untrack) を使用しましょう。
362362

363363
### What this replaces
364364

@@ -384,12 +384,12 @@ If you absolutely have to update `$state` within an effect and run into an infin
384384
// ...
385385
386386
$effect.pre(() => {
387-
if (!div) return; // not yet mounted
387+
if (!div) return; // まだマウントされていない場合
388388
389-
// reference `messages` so that this code re-runs whenever it changes
389+
// `messages` を参照することで、これが変更されるたびにこのコードが再実行されます
390390
messages;
391391
392-
// autoscroll when new messages are added
392+
// 新しい messages が追加されるたびに自動スクロールします
393393
if (
394394
div.offsetHeight + div.scrollTop >
395395
div.scrollHeight - 20
@@ -408,7 +408,7 @@ If you absolutely have to update `$state` within an effect and run into an infin
408408
</div>
409409
```
410410

411-
Apart from the timing, `$effect.pre` works exactly like [`$effect`](#$effect) — refer to its documentation for more info.
411+
タイミング以外は、`$effect.pre` [`$effect`](#$effect) と同じように動作します。詳細はドキュメントをご参照ください。
412412

413413
### What this replaces
414414

@@ -517,28 +517,28 @@ let { y } = $props();
517517

518518
## `$bindable`
519519

520-
To declare props as bindable, use `$bindable()`. Besides using them as regular props, the parent can (_can_, not _must_) then also `bind:` to them.
520+
バインド可能 (bindable) な props を宣言するには、`$bindable()` を使用します。通常の props として使用するだけでなく、親がそれを `bind:` することができます(必須ではなく、あくまで可能であるというだけです)。
521521

522522
```svelte
523523
<script>
524524
let { bindableProp = $bindable() } = $props();
525525
</script>
526526
```
527527

528-
You can pass an argument to `$bindable()`. This argument is used as a fallback value when the property is `undefined`.
528+
`$bindable()` には引数を渡すことができます。この引数は、その props が `undefined` のときのフォールバック値として使用されます。
529529

530530
```svelte
531531
<script>
532532
let { bindableProp = $bindable('fallback') } = $props();
533533
</script>
534534
```
535535

536-
Note that the parent is not allowed to pass `undefined` to a property with a fallback if it `bind:`s to that property.
536+
フォールバックを持つ props を親が `bind:` している場合、親はその props に `undefined` を渡すことはできないことにご注意ください。
537537

538538
## `$inspect`
539539

540540
`$inspect` rune は大まかには `console.log` と一緒ですが、与えられた引数が変わるたびに再実行されるという点が異なります。
541-
`$inspect` はリアクティブな state を深く(deeply)追跡します。つまり、[fine-grained reactivity](/docs/fine-grained-reactivity) によって
541+
`$inspect` はリアクティブな state を深く(deeply)追跡します。つまり、[きめ細やかなリアクティビティ(fine-grained reactivity)](/docs/fine-grained-reactivity) によって
542542
オブジェクトや配列の内側で何かしらが更新されると再実行されます。([デモ:](/#H4sIAAAAAAAACkWQ0YqDQAxFfyUMhSotdZ-tCvu431AXtGOqQ2NmmMm0LOK_r7Utfby5JzeXTOpiCIPKT5PidkSVq2_n1F7Jn3uIcEMSXHSw0evHpAjaGydVzbUQCmgbWaCETZBWMPlKj29nxBDaHj_edkAiu12JhdkYDg61JGvE_s2nR8gyuBuiJZuDJTyQ7eE-IEOzog1YD80Lb0APLfdYc5F9qnFxjiKWwbImo6_llKRQVs-2u91c_bD2OCJLkT3JZasw7KLA2XCX31qKWE6vIzNk1fKE0XbmYrBTufiI8-_8D2cUWBA_AQAA))
543543

544544
```svelte

0 commit comments

Comments
 (0)