Skip to content

Commit dba49b0

Browse files
committed
Translate 03-svelte-files.md from en to jp
1 parent 968dd8f commit dba49b0

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
---
2-
title: .svelte files
2+
title: .svelte ファイル
33
---
44

5-
Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML.
5+
コンポーネントは Svelte アプリケーションの構成要素です。これらは `.svelte` ファイルに書かれ、HTML のスーパーセットを使って記述されます。
66

7-
All three sections — script, styles and markup — are optional.
7+
以下の3つのセクション — script, styles, markup — は任意です。
88

99
<!-- prettier-ignore -->
1010
```svelte
1111
/// file: MyComponent.svelte
1212
<script module>
13-
// module-level logic goes here
14-
// (you will rarely use this)
13+
// モジュールレベルのロジックはここに書きます
14+
// (ほとんど使うことはありません)
1515
</script>
1616
1717
<script>
18-
// instance-level logic goes here
18+
// インスタンスレベルのロジックはここに書きます
1919
</script>
2020
21-
<!-- markup (zero or more items) goes here -->
21+
<!-- マークアップ (0行以上) はここに書きます -->
2222
2323
<style>
24-
/* styles go here */
24+
/* スタイルはここに書きます */
2525
</style>
2626
```
2727

2828
## `<script>`
2929

30-
A `<script>` block contains JavaScript (or TypeScript, when adding the `lang="ts"` attribute) that runs when a component instance is created. Variables declared (or imported) at the top level can be referenced in the component's markup.
30+
`<script>` ブロックは、コンポーネントインスタンスが作成されたときに実行される JavaScript (または `lang="ts` 属性を追加した時の TypeScript) を含みます。トップレベルで宣言 (またはインポート) された変数は、コンポーネントのマークアップで参照できます。
3131

32-
In addition to normal JavaScript, you can use _runes_ to declare [component props]($props) and add reactivity to your component. Runes are covered in the next section.
32+
通常のJavaScriptに加えて、_runes_ を使用して[コンポーネントのプロパティ]($props)を宣言したり、コンポーネントにリアクティビティを追加したりできます。Runes については次のセクションで説明します。
3333

3434
<!-- TODO describe behaviour of `export` -->
3535

3636
## `<script module>`
3737

38-
A `<script>` tag with a `module` attribute runs once when the module first evaluates, rather than for each component instance. Variables declared in this block can be referenced elsewhere in the component, but not vice versa.
38+
`<script>` タグに `module` 属性を付けると、モジュールが最初に評価される際に1回だけ実行され、各コンポーネントインスタンスごとに実行されるわけではありません。このブロックで宣言された変数は、コンポーネント内の他の場所から参照できますが、その逆はできません。
3939

4040
```svelte
4141
<script module>
@@ -50,22 +50,26 @@ A `<script>` tag with a `module` attribute runs once when the module first evalu
5050

5151
You can `export` bindings from this block, and they will become exports of the compiled module. You cannot `export default`, since the default export is the component itself.
5252

53+
このブロックから `export` バインディングを使用してエクスポートすることができ、それらはコンパイルされたモジュールのエクスポートとして扱われます。ただし、コンポーネント自体にデフォルトエクスポートがされるため `export default` は使用できません。
54+
5355
> [!NOTE] If you are using TypeScript and import such exports from a `module` block into a `.ts` file, make sure to have your editor setup so that TypeScript knows about them. This is the case for our VS Code extension and the IntelliJ plugin, but in other cases you might need to setup our [TypeScript editor plugin](https://www.npmjs.com/package/typescript-svelte-plugin).
5456
57+
> [!NOTE] TypeScriptを使用していて、`module` ブロックからエクスポートされたものを `.ts` ファイルにインポートする場合は、TypeScriptがそれらを認識できるようにエディタの設定を行う必要があります。VS Code拡張機能やIntelliJプラグインを使用している場合はこの設定が必要となりますが、それ以外の場合は [TypeScript エディタープラグイン](https://www.npmjs.com/package/typescript-svelte-plugin) を設定する必要がある場合があります。
58+
5559
> [!LEGACY]
56-
> In Svelte 4, this script tag was created using `<script context="module">`
60+
> Svelte 4 では、このスクリプトタグは `<script context="module">` を使用して作成されました。
5761
5862
## `<style>`
5963

60-
CSS inside a `<style>` block will be scoped to that component.
64+
`<style>` ブロック内のCSSは、そのコンポーネントにスコープされます。
6165

6266
```svelte
6367
<style>
6468
p {
65-
/* this will only affect <p> elements in this component */
69+
/* これはこのコンポネント内の <p> 要素にのみ影響します */
6670
color: burlywood;
6771
}
6872
</style>
6973
```
7074

71-
For more information, head to the section on [styling](scoped-styles).
75+
詳細については、[スタイリング](scoped-styles) のセクションをご覧ください。

0 commit comments

Comments
 (0)