Skip to content

Commit b310432

Browse files
authored
更新のあった差分の翻訳 (#444)
* docs: link directly to equivalent pages in translations vuejs/docs@883b753 * Add TypeScript example for event handling vuejs/docs@2e20116 * docs: elaborate on what can be included in the createApp root props vuejs/docs@9554a83 * add an any and a union type example for typescript prop annotation vuejs/docs@4dc940e * fix: code style in reactivity-computed-watchers.md vuejs/docs@fd21397 * docs: extra examples of migrating keyCode modifiers vuejs/docs@afc2a95 * docs: add various improvements to the Events API migration guide vuejs/docs@d9430c2 * docs: translate new typescript example * docs: translate about createApp root props * docs: translate event api migration guide * docs: translate keycode modifier migration guide * fix: link error vuejs/docs@dd2bf86
1 parent 9b89493 commit b310432

File tree

9 files changed

+178
-63
lines changed

9 files changed

+178
-63
lines changed

src/.vuepress/config.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,23 +423,28 @@ module.exports = {
423423
// Translation maintainers: Please include the link below to the English documentation
424424
{
425425
text: 'English',
426-
link: 'https://v3.vuejs.org/'
426+
link: 'https://v3.vuejs.org/',
427+
isTranslation: true
427428
},
428429
{
429430
text: '中文',
430-
link: 'https://v3.cn.vuejs.org/'
431+
link: 'https://v3.cn.vuejs.org/',
432+
isTranslation: true
431433
},
432434
{
433435
text: '한국어',
434-
link: 'https://v3.ko.vuejs.org/'
436+
link: 'https://v3.ko.vuejs.org/',
437+
isTranslation: true
435438
},
436439
// {
437-
// text: '日本語',
438-
// link: 'https://v3.ja.vuejs.org/'
440+
// text: '日本語',
441+
// link: 'https://v3.ja.vuejs.org/',
442+
// isTranslation: true
439443
// },
440444
{
441445
text: 'Русский',
442-
link: 'https://v3.ru.vuejs.org/'
446+
link: 'https://v3.ru.vuejs.org/ru/',
447+
isTranslation: true
443448
},
444449
{
445450
text: 'その他の翻訳',

src/.vuepress/theme/components/NavLink.vue

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,26 @@
2222
</template>
2323

2424
<script>
25+
import Vue from 'vue'
2526
import { isExternal, isMailto, isTel, ensureExt } from '../util'
2627
28+
const pageLocation = Vue.observable({ path: '/' })
29+
30+
let initPath = () => {
31+
initPath = () => {}
32+
33+
const updatePath = () => {
34+
pageLocation.path = location.pathname
35+
}
36+
37+
updatePath()
38+
39+
// There is no event for detecting navigation but these cover most cases
40+
for (const event of ['focusin', 'scroll', 'mouseover', 'keydown']) {
41+
window.addEventListener(event, updatePath)
42+
}
43+
}
44+
2745
export default {
2846
name: 'NavLink',
2947
@@ -35,7 +53,13 @@ export default {
3553
3654
computed: {
3755
link () {
38-
return ensureExt(this.item.link)
56+
let link = ensureExt(this.item.link)
57+
58+
if (this.item.isTranslation) {
59+
link = link.replace(/\/$/, '') + pageLocation.path
60+
}
61+
62+
return link
3963
},
4064
4165
exact () {
@@ -68,7 +92,7 @@ export default {
6892
},
6993
7094
rel () {
71-
if (this.isNonHttpURI) {
95+
if (this.isNonHttpURI || this.item.isTranslation) {
7296
return null
7397
}
7498
if (this.item.rel) {
@@ -82,6 +106,10 @@ export default {
82106
focusoutAction () {
83107
this.$emit('focusout')
84108
}
109+
},
110+
111+
mounted () {
112+
initPath()
85113
}
86114
}
87115
</script>

src/.vuepress/theme/layouts/404.vue

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
<div class="theme-default-content">
44
<h1>404</h1>
55

6-
<blockquote>{{ getMsg() }}</blockquote>
6+
<blockquote>
7+
<p>Whoops! This page doesn't exist.</p>
8+
</blockquote>
9+
10+
<p v-show="isTranslation">
11+
New pages are added to the documentation all the time. This page might not be included in all of the translations yet.
12+
</p>
713

814
<RouterLink to="/">
915
Take me home.
@@ -13,17 +19,22 @@
1319
</template>
1420

1521
<script>
16-
const msgs = [
17-
`There's nothing here.`,
18-
`How did we get here?`,
19-
`That's a Four-Oh-Four.`,
20-
`Looks like we've got some broken links.`
21-
]
22+
import { repos } from '../../components/guide/contributing/translations-data.js'
2223
2324
export default {
24-
methods: {
25-
getMsg () {
26-
return msgs[Math.floor(Math.random() * msgs.length)]
25+
data () {
26+
return {
27+
isTranslation: false
28+
}
29+
},
30+
31+
mounted () {
32+
const toOrigin = url => (String(url).match(/https?:\/\/[^/]+/) || [])[0]
33+
const referrer = toOrigin(document.referrer)
34+
35+
// Did we get here from a translation?
36+
if (referrer && referrer !== location.origin && repos.some(({ url }) => toOrigin(url) === referrer)) {
37+
this.isTranslation = true
2738
}
2839
}
2940
}

src/api/global-api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const app = createApp(
6363
</div>
6464
```
6565

66+
ルートプロパティは VNode を作成するとき [`h`](#h) に渡されるのと同じように、未加工のプロパティです。コンポーネントプロパティに加えて、ルートコンポーネントに適用される属性やイベントリスナも含めることができます。
67+
6668
### 型定義
6769

6870
```ts

src/guide/migration/events-api.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,46 @@ badges:
77

88
## 概要
99

10-
インスタンスメソッド `$on``$off``$once` は削除されました。アプリケーションインスタンスはイベントエミッタインタフェースを実装しなくなりました
10+
インスタンスメソッド `$on``$off``$once` は削除されました。コンポーネントインスタンスはイベントエミッタインタフェースを実装しなくなりました
1111

1212
## 2.x での構文
1313

14-
2.x では、Vue インスタンスを使用して、イベントエミッタ API (`$on``$off``$once`) を介して強制的に接続されたハンドラをトリガすることができました。これは、アプリケーション全体で使用されるグローバルイベントリスナーを作成するための _イベントハブ_ を作るために使用されました
14+
2.x では、Vue インスタンスを使用して、イベントエミッタ API (`$on``$off``$once`) を介して強制的に接続されたハンドラをトリガすることができました。これは、アプリケーション全体で使用されるグローバルイベントリスナーを作成するための _イベントバス_ を作るために使用できました
1515

1616
```js
17-
// eventHub.js
17+
// eventBus.js
1818

19-
const eventHub = new Vue()
19+
const eventBus = new Vue()
2020

21-
export default eventHub
21+
export default eventBus
2222
```
2323

2424
```js
2525
// ChildComponent.vue
26-
import eventHub from './eventHub'
26+
import eventBus from './eventBus'
2727

2828
export default {
2929
mounted() {
30-
// eventHub リスナーの追加
31-
eventHub.$on('custom-event', () => {
30+
// eventBus リスナーの追加
31+
eventBus.$on('custom-event', () => {
3232
console.log('Custom event triggered!')
3333
})
3434
},
3535
beforeDestroy() {
36-
// eventHub リスナーの削除
37-
eventHub.$off('custom-event')
36+
// eventBus リスナーの削除
37+
eventBus.$off('custom-event')
3838
},
3939
}
4040
```
4141

4242
```js
4343
// ParentComponent.vue
44-
import eventHub from './eventHub'
44+
import eventBus from './eventBus'
4545

4646
export default {
4747
methods: {
4848
callGlobalCustomEvent() {
49-
eventHub.$emit('custom-event') // ChildComponent がマウントされている場合、コンソールにメッセージが表示されます。
49+
eventBus.$emit('custom-event') // ChildComponent がマウントされている場合、コンソールにメッセージが表示されます。
5050
},
5151
},
5252
}
@@ -58,26 +58,47 @@ export default {
5858

5959
## 移行の戦略
6060

61+
[移行ビルドのフラグ: `INSTANCE_EVENT_EMITTER`](migration-build.html#compat-の設定)
62+
6163
Vue 3 では、これらの API を使用して、コンポーネント内からコンポーネント自身が発行したイベントを購読することはできなくなりました。そのユースケースのための移行パスはありません。
6264

63-
ただし、EventHub (イベントハブ) パターンは、Event Emitter (イベントエミッタ) インタフェースを実装した外部ライブラリを使用することで置き換えることができます。例えば、[mitt](https://github.com/developit/mitt)[tiny-emitter](https://github.com/scottcorgan/tiny-emitter) などです。
65+
### ルートコンポーネントのイベント
66+
67+
静的なイベントリスナは `createApp` にプロパティとして渡すことで、ルートコンポーネントに追加することができます:
68+
69+
```js
70+
createApp(App, {
71+
// 'expand' イベントを待機する
72+
onExpand() {
73+
console.log('expand')
74+
}
75+
})
76+
```
77+
78+
### Event Bus
79+
80+
Event Bus (イベントバス) パターンは、Event Emitter (イベントエミッタ) インタフェースを実装した外部ライブラリを使用することで置き換えることができます。例えば、[mitt](https://github.com/developit/mitt)[tiny-emitter](https://github.com/scottcorgan/tiny-emitter) などです。
6481

6582
例:
6683

6784
```js
68-
// eventHub.js
85+
// eventBus.js
6986
import emitter from 'tiny-emitter/instance'
7087

7188
export default {
7289
$on: (...args) => emitter.on(...args),
7390
$once: (...args) => emitter.once(...args),
7491
$off: (...args) => emitter.off(...args),
75-
$emit: (...args) => emitter.emit(...args),
92+
$emit: (...args) => emitter.emit(...args)
7693
}
7794
```
7895

7996
これは Vue 2 と同じような Event Emitter API を提供します。
8097

81-
これらのメソッドは、Vue 3 の将来の互換ビルドでもサポートされる可能性があります。
98+
ほとんどの場合、コンポーネント同士の通信にグローバル Event Bus を使うことには反対します。短期的にはもっとも単純な解決策であることが多いですが、長期的にはいつもメンテナンスの頭痛の種になることが証明されています。状況に応じて、Event Bus を使う以外のいろいろな方法があります。:
8299

83-
[移行ビルドのフラグ: `INSTANCE_EVENT_EMITTER`](migration-build.html#compat-の設定)
100+
* [プロパティ](/guide/component-basics.html#プロパティを用いた子コンポーネントへのデータの受け渡し)[イベント](/guide/component-basics.html#子コンポーネントのイベントを購読する) は、親子間の通信をする最初の選択肢です。兄弟は親を介して通信できます。
101+
* [Provide と Inject](/guide/component-provide-inject.html) はコンポーネントと、そのスロットのコンテンツとの通信を可能にします。これはいつも一緒に使われる緊密に結合されたコンポーネントに有効です。
102+
* `provide`/`inject` はコンポーネント間の距離が離れている通信にも使えます。プロパティを必要としないコンポーネントを何階層にもわたって、プロパティを渡す必要のある「Prop Drilling(プロパティのバケツリレーのこと)」を回避するのに役立ちます。
103+
* Prop Drilling はスロットを使うようにリファクタリングして回避することもできます。中間のコンポーネントがプロパティを必要としない場合、それは関心の分離に問題があることを示しているかもしれません。そのコンポーネントにスロットを導入することで、親はコンテンツを直接作成することができて、中間のコンポーネントが関与することなくプロパティを渡すことができます。
104+
* [Vuex](https://next.vuex.vuejs.org/) のような [グローバルな状態管理](/guide/state-management.html) もあります。

src/guide/migration/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Vue 3 で注目すべきいくつかの新機能の次のとおりです。
5353
- [Fragments](/guide/migration/fragments.html)
5454
- [Emits Component Option](/guide/component-custom-events.html)
5555
- カスタムレンダラを作るための [`@vue/runtime-core``createRenderer` API](https://github.com/vuejs/vue-next/tree/master/packages/runtime-core)
56-
- [SFC での Composition API の Syntax Sugar (`<script setup>`)](https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md) <Badge text="experimental" type="warning" />
56+
- [SFC での Composition API の Syntax Sugar (`<script setup>`)](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md) <Badge text="experimental" type="warning" />
5757
- [SFC でのステートドリブンな CSS Variables (`<style>``v-bind`)](https://github.com/vuejs/rfcs/blob/style-vars-2/active-rfcs/0000-sfc-style-variables.md) <Badge text="experimental" type="warning" />
5858
- [SFC での `<style scoped>` は、グローバルルールまたはスロットされたコンテンツのみを対象とするルールを含めることができるようになった](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0023-scoped-styles-changes.md)
5959
- [Suspense](/guide/migration/suspense.html) <Badge text="experimental" type="warning" />

src/guide/migration/keycode-modifiers.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ Vue.config.keyCodes = {
4646

4747
```html
4848
<!-- Vue 3 の v-on でキー修飾子を利用する場合 -->
49-
<input v-on:keyup.delete="confirmDelete" />
49+
<input v-on:keyup.page-down="nextPage">
50+
51+
<!-- Matches both q and Q -->
52+
<input v-on:keypress.q="quit">
5053
```
5154

5255
`config.keyCodes` の利用も同様の理由で非推奨となり、サポートされなくなりました。
@@ -55,6 +58,14 @@ Vue.config.keyCodes = {
5558

5659
キーコードを利用している場合は、ケバブケースでの命名に変更することを推奨します。
5760

61+
一部の句読点のキーは、文字のまま含めることができます。例えば、`,` キーでは:
62+
63+
```html
64+
<input v-on:keypress.,="commaPress">
65+
```
66+
67+
構文の制限のため `"``'``/``=``>``.` といった特定の文字はマッチしません。それらの文字については、代わりにリスナの中で `event.key` をチェックする必要があります。
68+
5869
[移行ビルドのフラグ:](migration-build.html#compat-の設定)
5970

6071
- `CONFIG_KEY_CODES`

0 commit comments

Comments
 (0)