Skip to content

Commit 1dcadd4

Browse files
authored
docs: translation Reusability & Composition > Plugins (#78)
* pluginsの翻訳 * fix: レビュー後の修正
1 parent cdc0a70 commit 1dcadd4

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/guide/plugins.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1-
# Plugins
1+
# プラグイン
22

3-
Plugins are self-contained code that usually add global-level functionality to Vue. It is either an `object` that exposes an `install()` method, or a `function`.
3+
大抵の場合、プラグインは Vue にグローバルレベルでの機能を追加するコードで、`install()` メソッドを公開する `object` または `function` です。
44

5-
There is no strictly defined scope for a plugin, but common scenarios where plugins are useful include:
5+
プラグインを厳密に定義するスコープはありませんが、プラグインが役立つ一般的なシナリオは以下の通りです。
66

7-
1. Add some global methods or properties, e.g. [vue-custom-element](https://github.com/karol-f/vue-custom-element).
7+
1. グローバルメソッドまたはグローパルプロパティの追加 例)[vue-custom-element](https://github.com/karol-f/vue-custom-element).
88

9-
2. Add one or more global assets: directives/filters/transitions etc. (e.g. [vue-touch](https://github.com/vuejs/vue-touch)).
9+
2. directives / filters / transitions のような1つ以上のグローバルアセットの追加 例) [vue-touch](https://github.com/vuejs/vue-touch)).
1010

11-
3. Add some component options by global mixin (e.g. [vue-router](https://github.com/vuejs/vue-router)).
11+
3. グローバル mixin によるコンポーネントオプションの追加 例) [vue-router](https://github.com/vuejs/vue-router)).
1212

13-
4. Add some global instance methods by attaching them to `config.globalProperties`.
13+
4. `config.globalProperties` にグローバルインスタンスメソッドを追加する
1414

15-
5. A library that provides an API of its own, while at the same time injecting some combination of the above (e.g. [vue-router](https://github.com/vuejs/vue-router)).
15+
5. 自身のAPIを提供すると同時に、上記のいくつかの組み合わせを導入するライブラリ 例) [vue-router](https://github.com/vuejs/vue-router)).
1616

17-
## Writing a Plugin
17+
## プラグインを書く
1818

19-
In order to better understand how to create your own Vue.js plugins, we will create a very simplified version of a plugin that displays `i18n` ready strings.
19+
独自の Vue.js プラグインの作り方をより理解しやすくするために、`i18n` に対応した文字列を表示するシンプルなバージョンのプラグインを用意しました。
2020

21-
Whenever this plugin is added to an application, the `install` method will be called if it is an object. If it is a `function`, the function itself will be called. In both cases, it will receive two parameters - the `app` object resulting from Vue's `createApp`, and the options passed in by the user.
21+
このプラグインがアプリケーションに導入されると、プラグインがオブジェクトの場合、`install` メソッドが呼ばれます。もし `function` のときは `function` そのものが呼ばれます。
22+
いずれの場合においても、Vue の `createapp` から生じる `app` オブジェクトとユーザーから受け取るオプションの2つのパラメータを受け取るでしょう。
2223

23-
Let's begin by setting up the plugin object. It is recommended to create it in a separate file and export it, as shown below to keep the logic contained and separate.
24+
それではプラグインオブジェクトの設定を始めましょう。プラグインオブジェクトは別のファイルに作成し、エクスポートすることを推奨します。下記のように、ロジックを含めたまま分離します。
2425

2526
```js
2627
// plugins/i18n.js
2728
export default {
2829
install: (app, options) => {
29-
// Plugin code goes here
30+
// プラグインのコードをここに書く
3031
}
3132
}
3233
```
3334

34-
We want to make a function to translate keys available to the whole application, so we will expose it using `app.config.globalProperties`.
35+
キーを変換する機能をアプリケーション全体で利用可能にするため、`app.config.globalProperties` を使って公開します。
3536

36-
This function will receive a `key` string, which we will use to look up the translated string in the user-provided options.
37+
この機能は `key` 文字列を受け取り、ユーザーから与えられたオプションに従って翻訳された文字列を引き当てます。
3738

3839
```js
3940
// plugins/i18n.js
@@ -48,7 +49,8 @@ export default {
4849
}
4950
```
5051

51-
We will assume that our users will pass in an object containing the translated keys in the `options` parameter when they use the plugin. Our `$translate` function will take a string such as `greetings.hello`, look inside the user provided configuration and return the translated value - in this case, `Bonjour!`
52+
ユーザーがプラグインを利用するとき、`options` パラメーターに翻訳されたキーを含むオブジェクトを渡すと想定します。`$translate` 関数 は `grettings.hello` のような文字列を受け取り、ユーザーから与えられた設定を探し、翻訳された値を返します。- この場合は、`Bonjour!`
53+
5254

5355
Ex:
5456

@@ -58,7 +60,7 @@ greetings: {
5860
}
5961
```
6062

61-
Plugins also allow us to use `inject` to provide a function or attribute to the plugin's users. For example, we can allow the application to have access to the `options` parameter to be able to use the translations object.
63+
また、プラグインのユーザーに関数や属性を提供するために、`inject` を使用することもできます。例えば、アプリケーションが翻訳オブジェクトを使用できるようにするための `options` パラメータへのアクセスを許可することができます。
6264

6365
```js
6466
// plugins/i18n.js
@@ -75,9 +77,9 @@ export default {
7577
}
7678
```
7779

78-
Plugin users will now be able to `inject['i18n']` into their components and access the object.
80+
プラグインの利用者は `[‘i18n]` をコンポーネントに注入し、オブジェクトにアクセスすることができます。
7981

80-
Additionally, since we have access to the `app` object, all other capabilities like using `mixin` and `directive` are available to the plugin. To learn more about `createApp` and the application instance, check out the [Application API documentation](/api/application-api.html).
82+
さらに、`app` オブジェクトにアクセスできるため、`mixin` `directive` など、他のすべての機能をプラグインで利用できます。`createApp` とアプリケーションインスタンスについて更に詳しく学ぶには、[アプリケーション API ドキュメント](/api/application-api.html) をチェックしてください。
8183

8284
```js
8385
// plugins/i18n.js
@@ -92,35 +94,35 @@ export default {
9294

9395
app.directive('my-directive', {
9496
mounted (el, binding, vnode, oldVnode) {
95-
// some logic ...
97+
// 何らかのロジック ...
9698
}
9799
...
98100
})
99101

100102
app.mixin({
101103
created() {
102-
// some logic ...
104+
// 何らかのロジック ...
103105
}
104106
...
105107
})
106108
}
107109
}
108110
```
109111

110-
## Using a Plugin
112+
## プラグインを使う
111113

112-
After a Vue app has been initialized with `createApp()`, you can add a plugin to your application by calling the `use()` method.
114+
Vue のアプリが `createApp()` で初期化されたあと、`use()` メソッドを使うことであなたのアプリケーションにプラグインを追加することができます。
113115

114-
We will use the `i18nPlugin` we created in the [Writing a Plugin](#writing-a-plugin) section for demo purposes.
116+
ここでは[プラグインを書く](#writing-a-plugin)のセクションでデモ用に作成した `i18nPlugin` を使います。
115117

116-
The `use()` method takes two parameters. The first one is the plugin to be installed, in this case `i18nPlugin`.
118+
`use()` メソッドは2つのパラメータを引数に取ります。まず、第1引数はインストールするプラグインですが、この場合は `i18nPlugin` です。
117119

118-
It also automatically prevents you from using the same plugin more than once, so calling it multiple times on the same plugin will install the plugin only once.
120+
また、同じプラグインを複数回使用することを自動的に防止してくれるため、同じプラグインのインストールを複数回実行した場合でも一度だけインストールされます。
119121

120-
The second parameter is optional, and depends on each particular plugin. In the case of the demo `i18nPlugin`, it is an object with the translated strings.
122+
第2引数はオプションで、それぞれのプラグインに依存します。デモの `i18nPlugin` の場合は、翻訳された文字列を持つオブジェクトです。
121123

122124
:::info
123-
If you are using third party plugins such as `Vuex` or `Vue Router`, always check the documentation to know what that particular plugin expects to receive as a second parameter.
125+
`Vuex` `Vue Router` などのサードパーティ製プラグインを使用している場合は、そのプラグインが2番目のパラメータとして何を受け取ることを期待しているのか、必ずドキュメントを確認してください。
124126
:::
125127

126128
```js
@@ -139,4 +141,5 @@ app.use(i18nPlugin, i18nStrings)
139141
app.mount('#app')
140142
```
141143

142-
Checkout [awesome-vue](https://github.com/vuejs/awesome-vue#components--libraries) for a huge collection of community-contributed plugins and libraries.
144+
コミュニティが貢献したプラグインやライブラリの膨大なコレクションについては [awesome-vue](https://github.com/vuejs/awesome-vue#components--libraries) をご覧ください。
145+

0 commit comments

Comments
 (0)