Skip to content

Commit 5012159

Browse files
authored
Merge pull request #10 from tomoam/translate-04-advanced-loading
Svelte のチュートリアルを svelte-site-jp から追加
2 parents b968996 + 201d7ca commit 5012159

File tree

58 files changed

+275
-273
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+275
-273
lines changed

content/tutorial/01-svelte/06-bindings/01-text-inputs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
title: Text inputs
33
---
44

5-
As a general rule, data flow in Svelte is _top down_ — a parent component can set props on a child component, and a component can set attributes on an element, but not the other way around.
5+
原則、Svelteのデータフローはトップダウンです。親コンポーネントは子コンポーネントにプロパティをセットできますし、コンポーネントは要素に属性をセットできますが、その逆はできません。
66

7-
Sometimes it's useful to break that rule. Take the case of the `<input>` element in this component — we _could_ add an `on:input` event handler that sets the value of `name` to `event.target.value`, but it's a bit... boilerplatey. It gets even worse with other form elements, as we'll see.
7+
時々、そのルールを破ると便利なことがあります。このコンポーネントの`<input>`要素の例で考えてみましょう。`on:input`イベントハンドラを追加して、`name`の値を`event.target.value`に設定できますが、それは少し…面倒(boilerplatey)です。想像がつくと思いますが、他のフォーム要素ではそれがさらに悪化します。
88

9-
Instead, we can use the `bind:value` directive:
9+
代わりに、`bind:value`を使用することができます。
1010

1111
```svelte
1212
<input bind:value={name}>
1313
```
1414

15-
This means that not only will changes to the value of `name` update the input value, but changes to the input value will update `name`.
15+
これは`name`の値が変更されるとinputの値が更新されるだけでなく、inputの値が変更されると`name`の値が更新されることを意味します。

content/tutorial/01-svelte/06-bindings/02-numeric-inputs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: Numeric inputs
33
---
44

5-
In the DOM, everything is a string. That's unhelpful when you're dealing with numeric inputs — `type="number"` and `type="range"` — as it means you have to remember to coerce `input.value` before using it.
5+
DOMの中では、全てが文字列(string)です。これは、数値のinput(`type="number"` `type="range"`)を扱う際、その値を取り出す時に`input.value`を使わなければならないため、不便です。
66

7-
With `bind:value`, Svelte takes care of it for you:
7+
`bind:value`を使用すれば、Svelteがそれを代行してくれます。
88

99
```svelte
1010
<input type=number bind:value={a} min=0 max=10>

content/tutorial/01-svelte/06-bindings/03-checkbox-inputs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Checkbox inputs
33
---
44

5-
Checkboxes are used for toggling between states. Instead of binding to `input.value`, we bind to `input.checked`:
5+
チェックボックスは状態を切り替えるのに使用されます。`input.value`にバインドする代わりに、`input.checked`にバインドします。
66

77
```svelte
88
<input type=checkbox bind:checked={yes}>

content/tutorial/01-svelte/06-bindings/04-group-inputs/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
title: Group inputs
33
---
44

5-
If you have multiple inputs relating to the same value, you can use `bind:group` along with the `value` attribute. Radio inputs in the same group are mutually exclusive; checkbox inputs in the same group form an array of selected values.
5+
同じ値に関係する複数のinputがあるなら、`value`属性に加えて`bind:group`を使用できます。同じグループ内のラジオinputは相互に排他的で、同じグループ内のチェックボックスinputは選択された値の配列を形成します。
66

7-
Add `bind:group` to each input:
7+
各inputに`bind:group`を追加しましょう。
88

99
```svelte
1010
<input type=radio bind:group={scoops} name="scoops" value={1}>
1111
```
1212

13-
In this case, we could make the code simpler by moving the checkbox inputs into an `each` block. First, add a `menu` variable to the `<script>` block...
13+
この場合、チェックボックスinputを`each`ブロックに移動させることでコードをよりシンプルにすることができます。まず、`<script>`ブロックに`menu`変数を追加します。
1414

1515
```js
1616
let menu = ['Cookies and cream', 'Mint choc chip', 'Raspberry ripple'];
1717
```
1818

19-
...then replace the second section:
19+
…それから2つ目のセクションを置き換えます。
2020

2121
```svelte
2222
<h2>Flavours</h2>
@@ -29,4 +29,4 @@ let menu = ['Cookies and cream', 'Mint choc chip', 'Raspberry ripple'];
2929
{/each}
3030
```
3131

32-
It's now easy to expand our ice cream menu in new and exciting directions.
32+
アイスクリームのメニューを新しいエキサイティングな方向に簡単に拡張できるようになりました。

content/tutorial/01-svelte/06-bindings/05-textarea-inputs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
title: Textarea inputs
33
---
44

5-
> This exercise doesn't currently work. You can switch to the old tutorial instead: https://svelte.dev/tutorial/textarea-inputs
5+
> この練習問題は現時点では動作しません。代わりに、既存のチュートリアルをお試しください: https://svelte.jp/tutorial/textarea-inputs
66
7-
The `<textarea>` element behaves similarly to a text input in Svelte — use `bind:value`:
7+
Svelteでは、`<textarea>`要素はtext inputと同じように振る舞います。`bind:value`を使ってみましょう。
88

99
```svelte
1010
<textarea bind:value={value}></textarea>
1111
```
1212

13-
In cases like these, where the names match, we can also use a shorthand form:
13+
このように名前が一致する場合は、省略形を使用することもできます。
1414

1515
```svelte
1616
<textarea bind:value></textarea>
1717
```
1818

19-
This applies to all bindings, not just textareas.
19+
これはtextareaに限らず全てのバインディングに適用されます。

content/tutorial/01-svelte/06-bindings/06-select-bindings/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
title: Select bindings
33
---
44

5-
We can also use `bind:value` with `<select>` elements. Update line 32:
5+
`<select>`要素にも`bind:value`を使用できます。32行目を更新してください。
66

77
```svelte
88
<select bind:value={selected} on:change="{() => answer = ''}">
99
```
1010

11-
Note that the `<option>` values are objects rather than strings. Svelte doesn't mind.
11+
`<option>`の値は文字列ではなくオブジェクトであることにご注意ください。Svelteは気にしません。
1212

13-
> Because we haven't set an initial value of `selected`, the binding will set it to the default value (the first in the list) automatically. Be careful though — until the binding is initialised, `selected` remains undefined, so we can't blindly reference e.g. `selected.id` in the template.
13+
> `selected`の初期値を設定していないので、バインディングは自動的にデフォルト値(配列の先頭)に設定されます。しかし、注意してください。バインディングが初期化されるまで、`selected`はundefinedのままなので、よく考えもせずにテンプレート内の`selected.id`などを参照することはできません。

content/tutorial/01-svelte/06-bindings/07-multiple-select-bindings/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: Select multiple
33
---
44

5-
A select can have a `multiple` attribute, in which case it will populate an array rather than selecting a single value.
5+
select `multiple` 属性を持つことができ、その場合は単一の値を選択するのではなく配列を追加します。
66

7-
Returning to our [earlier ice cream example](/tutorial/group-inputs), we can replace the checkboxes with a `<select multiple>`:
7+
[先ほどのアイスクリームの例](/tutorial/group-inputs)に戻り、チェックボックスを `<select multiple>` で置き換えることができます。
88

99
```svelte
1010
<h2>Flavours</h2>
@@ -18,4 +18,4 @@ Returning to our [earlier ice cream example](/tutorial/group-inputs), we can rep
1818
</select>
1919
```
2020

21-
> Press and hold the `control` key (or the `command` key on MacOS) for selecting multiple options.
21+
> 複数のオプションを選択するには `control` キー (MacOSの場合は `command` キー) を押したままにしてください。

content/tutorial/01-svelte/07-lifecycle/01-onmount/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: onMount
33
---
44

5-
> The images in this exercise don't currently work. You can switch to the old tutorial instead: https://svelte.dev/tutorial/onmount
5+
> この練習問題の画像は現時点では動作しません。代わりに、既存のチュートリアルをお試しください: https://svelte.jp/tutorial/onmount
66
7-
Every component has a _lifecycle_ that starts when it is created, and ends when it is destroyed. There are a handful of functions that allow you to run code at key moments during that lifecycle.
7+
すべてのコンポーネントには、作成される時を開始とし、破棄される時に終了とする *ライフサイクル* があります。その重要なタイミングにコードを実行できるようにする関数がいくつかあります。
88

9-
The one you'll use most frequently is `onMount`, which runs after the component is first rendered to the DOM.
9+
最も頻繁に使用するのは `onMount` で、これはコンポーネントが最初に DOM にレンダリングされた後に実行されます。
1010

11-
We'll add an `onMount` handler that loads some data over the network:
11+
`onMount` ハンドラにネットワークからデータを読み込む処理を追加します。
1212

1313
```svelte
1414
<script>
@@ -23,8 +23,8 @@ We'll add an `onMount` handler that loads some data over the network:
2323
</script>
2424
```
2525

26-
> It's recommended to put the `fetch` in `onMount` rather than at the top level of the `<script>` because of server-side rendering (SSR). With the exception of `onDestroy`, lifecycle functions don't run during SSR, which means we can avoid fetching data that should be loaded lazily once the component has been mounted in the DOM.
26+
> このコンポーネントがDOMにレンダリングされた上で遅延して読み込まれるべきデータを、サーバーサイドレンダリング(SSR)中には取得せずに済むように、この`fetch`を、`<script>` の最上位ではなく、 `onMount` の中に入れることが推奨されます。なぜなら、`onDestroy`以外のライフサイクル関数がSSR中に動作することはないからです。
2727
28-
Lifecycle functions must be called while the component is initialising so that the callback is bound to the component instance — not (say) in a `setTimeout`.
28+
ライフサイクル関数は、コールバックがコンポーネントのインスタンスにバインドされるように、コンポーネントの初期化中に呼び出されなければなりません。例えば、`setTimeout` の中で呼び出されてはいけません。
2929

30-
If the `onMount` callback returns a function, that function will be called when the component is destroyed.
30+
もし `onMount` コールバックが関数を返す場合、その関数はコンポーネントが破棄されたときに呼び出されます。

content/tutorial/01-svelte/07-lifecycle/02-ondestroy/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: onDestroy
33
---
44

5-
To run code when your component is destroyed, use `onDestroy`.
5+
コンポーネントが破棄されたときにコードを実行するには、`onDestroy` を使いましょう。
66

7-
For example, we can add a `setInterval` function when our component initialises, and clean it up when it's no longer relevant. Doing so prevents memory leaks.
7+
例えば、コンポーネントの初期化時に `setInterval` 関数を追加し、それが不要になったらそれをクリーンアップすることができます。そうすることでメモリリークを防ぐことができます。
88

99
```svelte
1010
<script>
@@ -17,7 +17,7 @@ For example, we can add a `setInterval` function when our component initialises,
1717
</script>
1818
```
1919

20-
While it's important to call lifecycle functions during the component's initialisation, it doesn't matter _where_ you call them from. So if we wanted, we could abstract the interval logic into a helper function in `utils.js`...
20+
コンポーネントの初期化中にライフサイクル関数を呼び出すことは重要ですが、それらを *どこ* から呼び出すかは重要ではありません。そのため、インターバルロジックを抽象化して `utils.js` のヘルパー関数にすることができます…
2121

2222
```js
2323
import { onDestroy } from 'svelte';
@@ -31,7 +31,7 @@ export function onInterval(callback, milliseconds) {
3131
}
3232
```
3333

34-
...and import it into our component:
34+
…そして、それをコンポーネントにインポートします。
3535

3636
```svelte
3737
<script>
@@ -42,4 +42,4 @@ export function onInterval(callback, milliseconds) {
4242
</script>
4343
```
4444

45-
Open and close the timer a few times and make sure the counter keeps ticking and the CPU load increases. This is due to a memory leak as the previous timers are not deleted. Don't forget to refresh the page before solving the example.
45+
何度かタイマーを開いたり閉じたりして、カウンターが動き続けCPU負荷が上昇することを確認してみてください。これは古いタイマーが削除されていないため、メモリリークが発生しているからです。例題を解く前にこのページを更新するのを忘れないでくださいね。

content/tutorial/01-svelte/07-lifecycle/03-update/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
title: beforeUpdate and afterUpdate
33
---
44

5-
The `beforeUpdate` function schedules work to happen immediately before the DOM is updated. `afterUpdate` is its counterpart, used for running code once the DOM is in sync with your data.
5+
`beforeUpdate` 関数は DOM が更新される直前に作業をスケジュールします。`afterUpdate` はそれと対になるもので、DOM がデータと同期した後にコードを実行するために使用されます。
66

7-
Together, they're useful for doing things imperatively that are difficult to achieve in a purely state-driven way, like updating the scroll position of an element.
7+
これらは、要素のスクロール位置を更新するなど、純粋な状態駆動では実現が困難なことを、命令的に行うのに便利です。
88

9-
This [Eliza](https://en.wikipedia.org/wiki/ELIZA) chatbot is annoying to use, because you have to keep scrolling the chat window. Let's fix that.
9+
この[Eliza](https://en.wikipedia.org/wiki/ELIZA)のチャットボットは、チャットウィンドウをスクロールし続けなければならないので、使うのが面倒です。そこを直しましょう。
1010

1111
```js
1212
let div;
@@ -21,4 +21,4 @@ afterUpdate(() => {
2121
});
2222
```
2323

24-
Note that `beforeUpdate` will first run before the component has mounted, so we need to check for the existence of `div` before reading its properties.
24+
`beforeUpdate` はコンポーネントが最初にマウントされる前に実行されるので、プロパティを読み込む前に `div` が存在するかどうかをチェックする必要があるということに注意してください。

0 commit comments

Comments
 (0)