Skip to content

Commit 6b629db

Browse files
authored
Merge pull request #153 from n-makoto/translate-attribute-coercion-behavior
Migration Guide > Attribute Coercion Behavior の翻訳
2 parents bf78a96 + 97361b7 commit 6b629db

File tree

1 file changed

+66
-65
lines changed

1 file changed

+66
-65
lines changed

src/guide/migration/attribute-coercion.md

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,113 @@ badges:
33
- breaking
44
---
55

6-
# Attribute Coercion Behavior <MigrationBadges :badges="$frontmatter.badges" />
6+
# 属性強制の振舞い <MigrationBadges :badges="$frontmatter.badges" />
77

88
::: info Info
9-
This is a low-level internal API change and does not affect most developers.
9+
これはローレベルな内部 API の変更であり、ほとんどの開発者には影響しません。
1010
:::
1111

12-
## Overview
12+
## 概要
1313

14-
Here is a high level summary of the changes:
14+
以下に変更点の概要を示します:
1515

16-
- Drop the internal concept of enumerated attributes and treat those attributes the same as normal non-boolean attributes
17-
- **BREAKING**: No longer removes attribute if value is boolean `false`. Instead, it's set as attr="false" instead. To remove the attribute, use `null` or `undefined`.
16+
- 列挙された属性の内部概念を削除し、それらの属性を通常の非ブール属性と同じように扱う。
17+
- **破壊的変更**: 値がブール値 `false` の場合に属性を削除しないようになりました。代わりに attr="false" として設定されます。属性を削除するには、`null` `undefined` を使ってください。
1818

19-
For more information, read on!
19+
詳しくは、以下をお読みください!
2020

21-
## 2.x Syntax
21+
## 2.x での構文
2222

23-
In 2.x, we had the following strategies for coercing `v-bind` values:
23+
2.x では、`v-bind`の値を強制するために以下のような戦略がありました:
2424

25-
- For some attribute/element pairs, Vue is always using the corresponding IDL attribute (property): [like `value` of `<input>`, `<select>`, `<progress>`, etc](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L11-L18).
25+
- いくつかの属性/要素のペアでは、Vue は常に対応する IDL 属性(プロパティ)を使用します。: [`<input>``<select>``<progress>`における`value`など](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L11-L18)
2626

27-
- For "[boolean attributes](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L33-L40)" and [xlinks](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L44-L46), Vue removes them if they are "falsy" ([`undefined`, `null` or `false`](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L52-L54)) and adds them otherwise (see [here](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L66-L77) and [here](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L81-L85)).
27+
- [ブール属性](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L33-L40)」と[xlinks](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L44-L46)については、Vue はそれらが"falsy"([`undefined``null``false`](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L52-L54))の場合には削除し、それ以外の場合には追加します ([ここ](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L66-L77)[こちら](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L81-L85)を見てください)。
2828

29-
- For "[enumerated attributes](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L20)" (currently `contenteditable`, `draggable` and `spellcheck`), Vue tries to [coerce](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L24-L31) them to string (with special treatment for `contenteditable` for now, to fix [vuejs/vue#9397](https://github.com/vuejs/vue/issues/9397)).
29+
- [列挙された属性](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L20)」(現在は`contenteditable``draggable``spellcheck`)については、Vue はそれらを[強制的に](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/util/attrs.js#L24-L31)文字列にしようとします ([vuejs/vue#9397](https://github.com/vuejs/vue/issues/9397)を修正するために、`contenteditable`については今のところ特別な扱いをしています)。
3030

31-
- For other attributes, we remove "falsy" values (`undefined`, `null`, or `false`) and set other values as-is (see [here](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L92-L113)).
31+
- 他の属性については、"falsy"な値(`undefined`, `null`, or `false`)は削除し、他の値はそのまま設定します([こちら](https://github.com/vuejs/vue/blob/bad3c326a3f8b8e0d3bcf07917dc0adf97c32351/src/platforms/web/runtime/modules/attrs.js#L92-L113)を見てください)。
3232

33-
The following table describes how Vue coerce "enumerated attributes" differently with normal non-boolean attributes:
33+
次の表では、Vue が「列挙された属性」を通常の非ブール属性とは異なる方法で強制する方法を説明しています:
3434

35-
| Binding expression | `foo` <sup>normal</sup> | `draggable` <sup>enumerated</sup> |
36-
| ------------------- | ----------------------- | --------------------------------- |
37-
| `:attr="null"` | / | `draggable="false"` |
38-
| `:attr="undefined"` | / | / |
39-
| `:attr="true"` | `foo="true"` | `draggable="true"` |
40-
| `:attr="false"` | / | `draggable="false"` |
41-
| `:attr="0"` | `foo="0"` | `draggable="true"` |
42-
| `attr=""` | `foo=""` | `draggable="true"` |
43-
| `attr="foo"` | `foo="foo"` | `draggable="true"` |
44-
| `attr` | `foo=""` | `draggable="true"` |
35+
| バインディング式 | `foo` <sup>通常の属性</sup> | `draggable` <sup>列挙された属性</sup> |
36+
| ------------------- | --------------------------- | ------------------------------------- |
37+
| `:attr="null"` | / | `draggable="false"` |
38+
| `:attr="undefined"` | / | / |
39+
| `:attr="true"` | `foo="true"` | `draggable="true"` |
40+
| `:attr="false"` | / | `draggable="false"` |
41+
| `:attr="0"` | `foo="0"` | `draggable="true"` |
42+
| `attr=""` | `foo=""` | `draggable="true"` |
43+
| `attr="foo"` | `foo="foo"` | `draggable="true"` |
44+
| `attr` | `foo=""` | `draggable="true"` |
4545

46-
We can see from the table above, current implementation coerces `true` to `'true'` but removes the attribute if it's `false`. This also led to inconsistency and required users to manually coerce boolean values to string in very common use cases like `aria-*` attributes like `aria-selected`, `aria-hidden`, etc.
46+
上の表からわかるように、現在の実装では`true``'true'`に強制していますが、`false`の場合は属性を削除しています。これはまた、`aria-selected``aria-hidden`といった`aria-*`属性のような非常に一般的なユースケースでも、ユーザーが手動でブール値を文字列に強制する必要があるなど、一貫性に欠けていました。
4747

48-
## 3.x Syntax
48+
## 3.x での構文
4949

50-
We intend to drop this internal concept of "enumerated attributes" and treat them as normal non-boolean HTML attributes.
50+
この「列挙された属性」という内部概念を捨てて、通常の非ブール HTML 属性として扱うつもりです。
5151

52-
- This solves the inconsistency between normal non-boolean attributes and "enumerated attributes"
53-
- It also makes it possible to use values other than `'true'` and `'false'`, or even keywords yet to come, for attributes like `contenteditable`
52+
- これは、通常の非ブール属性と「列挙された属性」の間の矛盾を解決します。
53+
- また、`'true'``'false'`以外の値や、`contenteditable` のような属性には、これから定義されるキーワードを使用することも可能になります。
5454

55-
For non-boolean attributes, Vue will stop removing them if they are `false` and coerce them to `'false'` instead.
55+
非ブール属性については、Vue `false`であれば削除はせず、代わりに`'false'`に強制します。
5656

57-
- This solves the inconsistency between `true` and `false` and makes outputting `aria-*` attributes easier
57+
- これにより、`true``false`の間の矛盾が解消され、`aria-*`属性の出力が容易になります。
5858

59-
The following table describes the new behavior:
59+
新しい振舞いについては、以下の表を参照してください:
6060

61-
| Binding expression | `foo` <sup>normal</sup> | `draggable` <sup>enumerated</sup> |
62-
| ------------------- | -------------------------- | --------------------------------- |
63-
| `:attr="null"` | / | / <sup>†</sup> |
64-
| `:attr="undefined"` | / | / |
65-
| `:attr="true"` | `foo="true"` | `draggable="true"` |
66-
| `:attr="false"` | `foo="false"` <sup>†</sup> | `draggable="false"` |
67-
| `:attr="0"` | `foo="0"` | `draggable="0"` <sup>†</sup> |
68-
| `attr=""` | `foo=""` | `draggable=""` <sup>†</sup> |
69-
| `attr="foo"` | `foo="foo"` | `draggable="foo"` <sup>†</sup> |
70-
| `attr` | `foo=""` | `draggable=""` <sup>†</sup> |
61+
| バインディング式 | `foo` <sup>通常の属性</sup> | `draggable` <sup>列挙された属性</sup> |
62+
| ------------------- | --------------------------- | ------------------------------------- |
63+
| `:attr="null"` | / | / <sup>†</sup> |
64+
| `:attr="undefined"` | / | / |
65+
| `:attr="true"` | `foo="true"` | `draggable="true"` |
66+
| `:attr="false"` | `foo="false"` <sup>†</sup> | `draggable="false"` |
67+
| `:attr="0"` | `foo="0"` | `draggable="0"` <sup>†</sup> |
68+
| `attr=""` | `foo=""` | `draggable=""` <sup>†</sup> |
69+
| `attr="foo"` | `foo="foo"` | `draggable="foo"` <sup>†</sup> |
70+
| `attr` | `foo=""` | `draggable=""` <sup>†</sup> |
7171

72-
<small>†: changed</small>
72+
<small>†: 変更点</small>
7373

74-
Coercion for boolean attributes is left untouched.
74+
ブール属性への強制はそのままです。
7575

76-
## Migration Strategy
76+
## 移行の戦略
7777

78-
### Enumerated attributes
78+
### 列挙された属性
7979

80-
The absence of an enumerated attribute and `attr="false"` may produce different IDL attribute values (which will reflect the actual state), described as follows:
80+
列挙された属性が存在しない場合や`attr="false"`が存在しない場合に、以下のように異なる IDL 属性値(実際の状態を反映した値)が生成されることがあります:
8181

82-
| Absent enumerated attr | IDL attr & value |
83-
| ---------------------- | ------------------------------------ |
84-
| `contenteditable` | `contentEditable` &rarr; `'inherit'` |
85-
| `draggable` | `draggable` &rarr; `false` |
86-
| `spellcheck` | `spellcheck` &rarr; `true` |
82+
| 列挙された属性の不在 | IDL 属性と値 |
83+
| -------------------- | ------------------------------------ |
84+
| `contenteditable` | `contentEditable` &rarr; `'inherit'` |
85+
| `draggable` | `draggable` &rarr; `false` |
86+
| `spellcheck` | `spellcheck` &rarr; `true` |
8787

88-
To keep the old behavior work, and as we will be coercing `false` to `'false'`, in 3.x Vue developers need to make `v-bind` expression resolve to `false` or `'false'` for `contenteditable` and `spellcheck`.
88+
これまでの振舞いを維持するために、また、`false``'false'`に強制するために、3.x Vue の開発者は`contenteditable``spellcheck`に対して`v-bind`式を`false`または`'false'`に解決する必要があります。
8989

90-
In 2.x, invalid values were coerced to `'true'` for enumerated attributes. This was usually unintended and unlikely to be relied upon on a large scale. In 3.x `true` or `'true'` should be explicitly specified.
90+
2.x では、列挙された属性に対して無効な値を`'true'`に強制的に設定していました。これは通常意図していなかったもので、大規模に利用される可能性は低いと思われます。3.x では、`true`または`'true'`を明示的に指定する必要があります。
9191

92-
### Coercing `false` to `'false'` instead of removing the attribute
92+
### 属性を削除する代わりに `false` `'false'` に強制する
9393

94-
In 3.x, `null` or `undefined` should be used to explicitly remove an attribute.
94+
3.x では、明示的に属性を削除するには `null` または `undefined` を使用しなければなりません。
9595

96-
### Comparison between 2.x & 3.x behavior
96+
### 2.x 3.x 間の振舞いの比較
9797

9898
<table>
9999
<thead>
100100
<tr>
101-
<th>Attribute</th>
102-
<th><code>v-bind</code> value <sup>2.x</sup></th>
103-
<th><code>v-bind</code> value <sup>3.x</sup></th>
104-
<th>HTML output</th>
101+
<th>属性</th>
102+
<th><code>v-bind</code> <sup>2.x</sup></th>
103+
<th><code>v-bind</code> <sup>3.x</sup></th>
104+
<th>HTML 出力</th>
105105
</tr>
106106
</thead>
107107
<tbody>
108108
<tr>
109-
<td rowspan="3">2.x “Enumerated attrs”<br><small>i.e. <code>contenteditable</code>, <code>draggable</code> and <code>spellcheck</code>.</small></td>
109+
<td rowspan="3">2.x “列挙された属性”<br><small>つまり<code>contenteditable</code><code>draggable</code><code>spellcheck</code></small></td>
110110
<td><code>undefined</code>, <code>false</code></td>
111111
<td><code>undefined</code>, <code>null</code></td>
112-
<td><i>removed</i></td>
112+
<td><i>削除されます</i></td>
113113
</tr>
114114
<tr>
115115
<td>
@@ -125,10 +125,11 @@ In 3.x, `null` or `undefined` should be used to explicitly remove an attribute.
125125
<td><code>"false"</code></td>
126126
</tr>
127127
<tr>
128-
<td rowspan="2">Other non-boolean attrs<br><small>eg. <code>aria-checked</code>, <code>tabindex</code>, <code>alt</code>, etc.</small></td>
128+
<td rowspan="2">その他の非ブール属性<br><small>例えば
129+
<code>aria-checked</code>、<code>tabindex</code>、<code>alt</code>など</small></td>
129130
<td><code>undefined</code>, <code>null</code>, <code>false</code></td>
130131
<td><code>undefined</code>, <code>null</code></td>
131-
<td><i>removed</i></td>
132+
<td><i>削除されます</i></td>
132133
</tr>
133134
<tr>
134135
<td><code>'false'</code></td>

0 commit comments

Comments
 (0)