Skip to content

Commit 7ee1a72

Browse files
authored
Japanese translation (Global API section) (#40)
1 parent aa2c452 commit 7ee1a72

File tree

5 files changed

+125
-119
lines changed

5 files changed

+125
-119
lines changed

.vitepress/locales/ja.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export default {
2828
]
2929
},
3030
{
31-
text: 'Global API',
31+
text: 'グローバル API',
3232
items: [
3333
{
34-
text: 'Global API Application Instance',
34+
text: 'グローバル API アプリケーションインスタンス',
3535
link: '/ja/breaking-changes/global-api'
3636
},
3737
{
38-
text: 'Global API Treeshaking',
38+
text: 'グローバル API ツリーシェイキング',
3939
link: '/ja/breaking-changes/global-api-treeshaking'
4040
}
4141
]

.vitepress/theme/MigrationBadges.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ const localeBadges = {
1313
breaking: '非兼容',
1414
removed: '移除',
1515
updated: '更新'
16+
},
17+
'ja-JP': {
18+
new: '新機能',
19+
breaking: '破壊的変更',
20+
removed: '削除',
21+
updated: '更新'
1622
}
1723
}
1824

src/ja/breaking-changes/global-api-treeshaking.md

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

6-
# Global API Treeshaking <MigrationBadges :badges="$frontmatter.badges" />
6+
# グローバル API ツリーシェイキング <MigrationBadges :badges="$frontmatter.badges" />
77

8-
## 2.x Syntax
8+
## 2.x の構文
99

10-
If you’ve ever had to manually manipulate DOM in Vue, you might have come across this pattern:
10+
Vue で DOM を手動で操作したことがある人は、次のパターンに出くわしたことがあるかもしれません:
1111

1212
```js
1313
import Vue from 'vue'
1414

1515
Vue.nextTick(() => {
16-
// something DOM-related
16+
// DOM 関連の何か
1717
})
1818
```
1919

20-
Or, if you’ve been unit-testing an application involving async components, chances are you’ve written something like this:
20+
あるいは、非同期コンポーネントを含むアプリケーションをユニットテストしている場合、次のようなことを書いたことがあるのではないでしょうか:
2121

2222
```js
2323
import { shallowMount } from '@vue/test-utils'
@@ -26,33 +26,33 @@ import { MyComponent } from './MyComponent.vue'
2626
test('an async feature', async () => {
2727
const wrapper = shallowMount(MyComponent)
2828

29-
// execute some DOM-related tasks
29+
// DOM に関連するいくつかのタスクを実行
3030

3131
await wrapper.vm.$nextTick()
3232

33-
// run your assertions
33+
// アサーション実行
3434
})
3535
```
3636

37-
`Vue.nextTick()` is a global API exposed directly on a single Vue object – in fact, the instance method `$nextTick()` is just a handy wrapper around `Vue.nextTick()` with the callback’s `this` context automatically bound to the current instance for convenience.
37+
`Vue.nextTick()` は、単一の Vue オブジェクト上で直接公開されるグローバル API です - 実際のところ、インスタンスメソッド `$nextTick()` `Vue.nextTick()` の便利なラッパーに過ぎず、コールバックの `this` コンテキストは便宜上、現在のインスタンスに自動的に結合されます。
3838

39-
But what if you’ve never had to deal with manual DOM manipulation, nor are you using or testing async components in your app? Or, what if, for whatever reason, you prefer to use the good old `window.setTimeout()` instead? In such a case, the code for `nextTick()` will become dead code – that is, code that’s written but never used. And dead code is hardly a good thing, especially in our client-side context where every kilobyte matters.
39+
しかし、手動で DOM を操作する必要がなく、アプリで非同期コンポーネントを使用したりテストしたりすることもない場合はどうでしょうか? あるいは、何らかの理由で、代わりに古き良き `window.setTimeout()` を使いたい場合はどうでしょうか? このような場合、`nextTick()` のコードはデッドコード、つまり、書かれているが使われないコードになってしまいます。特に、1 キロバイト単位が重要なクライアントサイドの文脈では、デッドコードは良いことではありません。
4040

41-
Module bundlers like webpack and Rollup (which Vite is based upon) support [tree-shaking](https://webpack.js.org/guides/tree-shaking/), which is a fancy term for “dead code elimination.” Unfortunately, due to how the code is written in previous Vue versions, global APIs like `Vue.nextTick()` are not tree-shakeable and will be included in the final bundle regardless of where they are actually used or not.
41+
webpack や(Vite のベースとなっている)Rollup のようなモジュールバンドラーは、[ツリーシェイキング](https://webpack.js.org/guides/tree-shaking/)をサポートしています。これは「デッドコードの排除」を意味する装飾的な用語です。残念ながら以前の Vue バージョンではコードの記述方法が原因で、`Vue.nextTick()` のようなグローバル API はツリーシェイクされず、実際に使われる場所や使わない場所に関係なく最終的にバンドルに含まれます。
4242

43-
## 3.x Syntax
43+
## 3.x の構文
4444

45-
In Vue 3, the global and internal APIs have been restructured with tree-shaking support in mind. As a result, the global APIs can now only be accessed as named exports for the ES Modules build. For example, our previous snippets should now look like this:
45+
Vue 3 では、ツリーシェイキングのサポートを念頭に置いて、グローバル API と内部 API が再構築されました。その結果、グローバル API は、ES モジュールビルドの名前付きエクスポートとしてのみアクセスできるようになりました。例えば、上記のスニペットは次のようになります:
4646

4747
```js
4848
import { nextTick } from 'vue'
4949

5050
nextTick(() => {
51-
// something DOM-related
51+
// DOM 関連の何か
5252
})
5353
```
5454

55-
and
55+
さらに
5656

5757
```js
5858
import { shallowMount } from '@vue/test-utils'
@@ -62,40 +62,40 @@ import { nextTick } from 'vue'
6262
test('an async feature', async () => {
6363
const wrapper = shallowMount(MyComponent)
6464

65-
// execute some DOM-related tasks
65+
// DOM に関連するいくつかのタスクを実行
6666

6767
await nextTick()
6868

69-
// run your assertions
69+
// アサーション実行
7070
})
7171
```
7272

73-
Calling `Vue.nextTick()` directly will now result in the infamous `undefined is not a function` error.
73+
`Vue.nextTick()` を直接呼び出すと、悪名高い `undefined is not a function` エラーが発生するようになりました。
7474

75-
With this change, provided the module bundler supports tree-shaking, global APIs that are not used in a Vue application will be eliminated from the final bundle, resulting in an optimal file size.
75+
この変更により、モジュールバンドラーがツリーシェイキングをサポートしている場合、Vue アプリケーションで使用されないグローバル API は最終的なバンドルから排除され、最適なファイルサイズになります。
7676

77-
## Affected APIs
77+
## 影響を受ける API
7878

79-
These global APIs in Vue 2.x are affected by this change:
79+
以下の Vue 2.x のグローバル API は、この変更の影響を受けます:
8080

8181
- `Vue.nextTick`
82-
- `Vue.observable` (replaced by `Vue.reactive`)
82+
- `Vue.observable``Vue.reactive` に置き換え)
8383
- `Vue.version`
84-
- `Vue.compile` (only in full builds)
85-
- `Vue.set` (only in compat builds)
86-
- `Vue.delete` (only in compat builds)
84+
- `Vue.compile`(フルビルドのみ)
85+
- `Vue.set`(互換ビルドのみ)
86+
- `Vue.delete`(互換ビルドのみ)
8787

88-
## Internal Helpers
88+
## 内部ヘルパー
8989

90-
In addition to public APIs, many of the internal components/helpers are now exported as named exports as well. This allows the compiler to output code that only imports features when they are used. For example the following template:
90+
パブリック API に加え、内部コンポーネントやヘルパーの多くも名前付きエクスポートとして公開されるようになりました。これにより、コンパイラーは、機能が使用されるときだけインポートするコードを出力できます。例えば次のテンプレートは:
9191

9292
```html
9393
<transition>
9494
<div v-show="ok">hello</div>
9595
</transition>
9696
```
9797

98-
is compiled into something similar to the following:
98+
以下のようなものにコンパイルされます:
9999

100100
```js
101101
import { h, Transition, withDirectives, vShow } from 'vue'
@@ -105,17 +105,17 @@ export function render() {
105105
}
106106
```
107107

108-
This essentially means the `Transition` component only gets imported when the application actually makes use of it. In other words, if the application doesn’t have any `<transition>` component, the code supporting this feature will not be present in the final bundle.
108+
つまり、`Transition` コンポーネントは、アプリケーションが実際に使用するときにのみインポートされます。言い換えれば、アプリケーションが `<transition>` コンポーネントを持たない場合、この機能をサポートするコードは最終的なバンドルには含まれません。
109109

110-
With global tree-shaking, the users only “pay” for the features they actually use. Even better, knowing that optional features won't increase the bundle size for applications not using them, framework size has become much less a concern for additional core features in the future, if at all.
110+
グローバルのツリーシェイキングでは、ユーザーは実際に使用する機能に対してのみ「支払う」ことになります。さらに良いことに、オプション機能を使用しないアプリケーションではバンドルサイズが大きくならないことが分かっているため、将来的にコア機能を追加する場合でも、フレームワークのサイズについて懸念することは少なくなっています。
111111

112-
::: warning Important
113-
The above only applies to the [ES Modules builds](https://github.com/vuejs/core/tree/master/packages/vue#which-dist-file-to-use) for use with tree-shaking capable bundlers - the UMD build still includes all features and exposes everything on the Vue global variable (and the compiler will produce appropriate output to use APIs off the global instead of importing).
112+
::: warning 重要
113+
上記は、ツリーシェイキング可能なバンドラーで使用するための [ES モジュールビルド](https://github.com/vuejs/core/tree/master/packages/vue#which-dist-file-to-use)にのみ適用されます。UMD ビルドは依然としてすべての機能を含み、Vue グローバル変数ですべてを公開します(そしてコンパイラーは、インポートする代わりにグローバルから API を使用するように適切な出力を生成します)。
114114
:::
115115

116-
## Usage in Plugins
116+
## プラグインでの使用
117117

118-
If your plugin relies on an affected Vue 2.x global API, for instance:
118+
あなたのプラグインが、影響を受ける Vue 2.x のグローバル API に依存している場合、例えば:
119119

120120
```js
121121
const plugin = {
@@ -127,7 +127,7 @@ const plugin = {
127127
}
128128
```
129129

130-
In Vue 3, you’ll have to import it explicitly:
130+
Vue 3 では、明示的にインポートする必要があります:
131131

132132
```js
133133
import { nextTick } from 'vue'
@@ -141,7 +141,7 @@ const plugin = {
141141
}
142142
```
143143

144-
If you use a module bundle like webpack, this may cause Vue’s source code to be bundled into the plugin, and more often than not that’s not what you'd expect. A common practice to prevent this from happening is to configure the module bundler to exclude Vue from the final bundle. In webpack's case, you can use the [`externals`](https://webpack.js.org/configuration/externals/) configuration option:
144+
webpack のようなモジュールバンドルを使っている場合、Vue のソースコードがプラグインにバンドルされてしまうことがあり、それはほとんどが期待するものではないです。これを防ぐための一般的な方法は、最終的なバンドルから Vue を除外するようにモジュールバンドラーを設定することです。webpack の場合、[`externals`](https://webpack.js.org/configuration/externals/) という設定オプションを使用します:
145145

146146
```js
147147
// webpack.config.js
@@ -153,9 +153,9 @@ module.exports = {
153153
}
154154
```
155155

156-
This will tell webpack to treat the Vue module as an external library and not bundle it.
156+
これは webpack に、Vue モジュールを外部ライブラリーとして扱い、バンドルしないように指示します。
157157

158-
If your module bundler of choice happens to be [Rollup](https://rollupjs.org/), you basically get the same effect for free, as by default Rollup will treat absolute module IDs (`'vue'` in our case) as external dependencies and not include them in the final bundle. During bundling though, it might emit a [Treating vue as external dependency](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) warning, which can be suppressed with the `external` option:
158+
モジュールバンドラーに [Rollup](https://rollupjs.org/) を選択した場合、基本的には何もせずに同じ効果を得られます。デフォルトでは Rollup は絶対モジュール ID(この例では `'vue'`)を外部依存関係として扱い、最終バンドルに含めないからです。しかし、バンドル中に ["Treating vue as external dependency"](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) という警告が出ることがありますが、これは `external` オプションで抑制できます:
159159

160160
```js
161161
// rollup.config.js

0 commit comments

Comments
 (0)