Skip to content

Commit 730deb7

Browse files
kitakktsn
authored andcommitted
Translate v2 docs in Japanese. (#428)
* Starting japanese translation. * Move intro.md from v1.0 * Installation.md in Japanese * translate headers * Copy docs/en/getting-started.md from 1.0 * Copy docs/en/getting-started.md from 2.0, understanding diff 1.0 and 2.0 * Copy docs/ja/getting-started.md from 1.0 * Translated the part of getting-started.md which has no diff 1.0 and 2.0 * Translate getting-started.md * Make getting-started.md more readable * Tiny change * Translate intro * translate intro * Copy docs/en/getters.md to ja * Translate getters.md * Translate mapGetters helper * Copy docs/en/mutations.md from 1.0 * Copy docs/en/mutations.md from 2.0, understanding diff 1.0 and 2.0 * Copy docs/ja/mutations.md from 1.0 * Translate mutations.md * Delete unnecessary rows * Copy actions.md from 1.0 * Copy actions.md from 2.0, understanding diff 1.0 and 2.0 * Copy docs/ja/actions.md from 1.0 * Translate state * Translate dispatching actions * Translate actions.md * Copy docs/en/modules.md to docs/ja/modules.md * Translate modules.md * Translate title of docs/ja/modules.md * Copy docs/en/structure.md of 1.0 to docs/ja/structure.md * Copy docs/en/structure.md of 2.0, understanding diff 1.0 and 2.0 * Copy version 1.0 of docs/ja/structure.md * Translate structure.md * Copy docs/en/testing.md of 1.0 to docs/ja/testing.md * Copy docs/en/testing.md of 2.0, understanding diff 1.0 and 2.0 * Copy version 1.0 of docs/ja/testing.md * Translate testing mutations * Translate testing actions * Translate docs/ja/testing.md * Copy docs/en/strict.md 1.0 to docs/ja/strict.md * Copy version 1.0 of docs/ja/strict.md * Translate strict.md * Add hot-reload * Translate plugins * Translate forms * Translate SUMMARY * Improve intro * Improve * Improve translation of resolve * Improve translation of actions.md * Fix translation of docs/ja/getters.md * Cut off the broken link * Fix typo * Improve translation * Improve * Improve intro translation * Improve translation * Improve * Improve * Link to old japanese document * Reflect review by @ktsn * Reflect #470 * Reflect #438 * Reflect change of actions.md in #421 * Translate docs/ja/api.md * Replace プロミス with Promise * Improve translation of 'expose' * Improve translation of 'component methods options' * Fix indent * Improve translation * Replace Vue store with ストア * Improve transration * Fix arguments of dispatch and watch * Improve translation * Fix indent * Improve translation * Improve translation * Improve translation * Add README.md and book.json
1 parent 994f6a8 commit 730deb7

22 files changed

+1563
-1
lines changed

docs/LANGS.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
* [2.0 - 简体中文](zh-cn/)
33
* [2.0 - Français](fr/)
44
* [2.0 - Русский](ru/)
5+
* [2.0 - 日本語](ja/)
56
* [1.0 Docs](old/)

docs/en/getters.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Getters
32

43
Sometimes we may need to compute derived state based on store state, for example filtering through a list of items and counting them:

docs/ja/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% include "./SUMMARY.md" %}

docs/ja/SUMMARY.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Vuex
2+
3+
> 注意: これは [email protected] のドキュメントです
4+
5+
- [1.0のドキュメントをお探しですか?](https://github.com/vuejs/vuex/tree/1.0/docs/ja)
6+
- [リリースノート](https://github.com/vuejs/vuex/releases)
7+
- [インストール](installation.md)
8+
- [Vuex とは何か?](intro.md)
9+
- [Vuex 入門](getting-started.md)
10+
- コアコンセプト
11+
- [ステート](state.md)
12+
- [ゲッター](getters.md)
13+
- [ミューテーション](mutations.md)
14+
- [アクション](actions.md)
15+
- [モジュール](modules.md)
16+
- [アプリケーションの構造](structure.md)
17+
- [プラグイン](plugins.md)
18+
- [厳格モード](strict.md)
19+
- [フォームの扱い](forms.md)
20+
- [テスト](testing.md)
21+
- [ホットリローディング](hot-reload.md)
22+
- [API リファレンス](api.md)

docs/ja/actions.md

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# アクション
2+
3+
アクションはミューテーションと似ていますが、下記の点で異なります:
4+
5+
- アクションは、状態を変更するのではなく、ミューテーションをコミットします。
6+
- アクションは任意の非同期処理を含むことができます。
7+
8+
シンプルなアクションを登録してみましょう:
9+
10+
``` js
11+
const store = new Vuex.Store({
12+
state: {
13+
count: 0
14+
},
15+
mutations: {
16+
increment (state) {
17+
state.count++
18+
}
19+
},
20+
actions: {
21+
increment (context) {
22+
context.commit('increment')
23+
}
24+
}
25+
})
26+
```
27+
28+
アクションハンドラはストアインスタンスのメソッドやプロパティのセットと同じものを呼び出せるコンテキストオブジェクトを受け取ります。したがって `context.commit` を呼び出すことでミューテーションをコミットできます。あるいは `context.state``context.getters` で、状態やゲッターにアクセスできます。なぜコンテキストオブジェクトがストアインスタンスそのものではないのかは、後ほど[モジュール](modules.md)で説明します。
29+
30+
実際にはコードを少しシンプルにするために ES2015 の[引数分割束縛(argument destructuring)](https://github.com/lukehoban/es6features#destructuring)がよく使われます(特に `commit` を複数回呼び出す必要があるとき):
31+
32+
``` js
33+
actions: {
34+
increment ({ commit }) {
35+
commit('increment')
36+
}
37+
}
38+
```
39+
40+
### アクションのディスパッチ
41+
42+
アクションは `store.dispatch` がトリガーとなって実行されます:
43+
44+
``` js
45+
store.dispatch('increment')
46+
```
47+
48+
これは一見ばかげて見えるかもしれません。つまり、カウントをインクリメントしたいときに、どうして直接 `store.commit('increment')` を呼び出してミューテーションをコミットしないのか、と。**ミューテーションは同期的でなければならない**というのを覚えていますか?アクションはそうではありません。アクションの中では**非同期**の操作を行うことができます。
49+
50+
``` js
51+
actions: {
52+
incrementAsync ({ commit }) {
53+
setTimeout(() => {
54+
commit('increment')
55+
}, 1000)
56+
}
57+
}
58+
```
59+
60+
アクションはペイロード形式とオブジェクトスタイルのディスパッチをサポートします:
61+
62+
``` js
63+
// ペイロードを使ってディスパッチする
64+
store.dispatch('incrementAsync', {
65+
amount: 10
66+
})
67+
68+
// オブジェクトを使ってディスパッチする
69+
store.dispatch({
70+
type: 'incrementAsync',
71+
amount: 10
72+
})
73+
```
74+
75+
より実践的な例として、ショッピングカートをチェックアウトするアクションを挙げます。このアクションは**非同期な API の呼び出し**と、**複数のミューテーションのコミット**をします:
76+
77+
``` js
78+
actions: {
79+
checkout ({ commit, state }, products) {
80+
// 現在のカート内の商品を保存する
81+
const savedCartItems = [...state.cart.added]
82+
// チェックアウトのリクエストを送信し、楽観的にカート内をクリアする
83+
commit(types.CHECKOUT_REQUEST)
84+
// shop API は成功時のコールバックと失敗時のコールバックを受け取る
85+
shop.buyProducts(
86+
products,
87+
// 成功時の処理
88+
() => commit(types.CHECKOUT_SUCCESS),
89+
// 失敗時の処理
90+
() => commit(types.CHECKOUT_FAILURE, savedCartItems)
91+
)
92+
}
93+
}
94+
```
95+
96+
一連の非同期の処理を実行しつつ、ミューテーションのコミットによってのみ副作用(状態の変更)を与えていることに注意してください。
97+
98+
### コンポーネント内でのアクションのディスパッチ
99+
100+
`this.$store.dispatch('xxx')` でコンポーネント内でアクションをディスパッチできます。あるいはコンポーネントのメソッドを `store.dispatch` にマッピングする `mapActions` ヘルパーを使うこともできます(ルートの `store` の注入が必要です):
101+
102+
``` js
103+
import { mapActions } from 'vuex'
104+
105+
export default {
106+
// ...
107+
methods: {
108+
...mapActions([
109+
'increment' // this.increment() を this.$store.dispatch('increment') にマッピングする
110+
]),
111+
...mapActions({
112+
add: 'increment' // this.add() を this.$store.dispatch('increment') にマッピングする
113+
})
114+
}
115+
}
116+
```
117+
118+
### アクションを構成する
119+
120+
アクションはしばしば非同期処理を行いますが、アクションが完了したことをどうやって知れば良いのでしょう?そしてもっと重要なことは、さらに複雑な非同期処理を取り扱うために、どうやって複数のアクションを構成させるかということです。
121+
122+
まず知っておくべきことは `store.dispatch` がトリガーされたアクションハンドラによって返された Promise を処理できることと、`store.dispatch` もまた Promise を返すことです。
123+
124+
``` js
125+
actions: {
126+
actionA ({ commit }) {
127+
return new Promise((resolve, reject) => {
128+
setTimeout(() => {
129+
commit('someMutation')
130+
resolve()
131+
}, 1000)
132+
})
133+
}
134+
}
135+
```
136+
137+
すると次のようにできます:
138+
139+
``` js
140+
store.dispatch('actionA').then(() => {
141+
// ...
142+
})
143+
```
144+
145+
また別のアクションで下記のように書くと:
146+
147+
``` js
148+
actions: {
149+
// ...
150+
actionB ({ dispatch, commit }) {
151+
return dispatch('actionA').then(() => {
152+
commit('someOtherMutation')
153+
})
154+
}
155+
}
156+
```
157+
158+
最終的に JavaScript の機能として近く導入される [async / await](https://tc39.github.io/ecmascript-asyncawait/) を使用することで、次のようにアクションを組み合わせることができます:
159+
160+
``` js
161+
// getData() と getOtherData() が Promise を返すことを想定している
162+
163+
actions: {
164+
async actionA ({ commit }) {
165+
commit('gotData', await getData())
166+
},
167+
async actionB ({ dispatch, commit }) {
168+
await dispatch('actionA') // actionA が完了するのを待機する
169+
commit('gotOtherData', await getOtherData())
170+
}
171+
}
172+
```
173+
174+
> `store.dispatch` で異なるモジュール内の複数のアクションハンドラをトリガーすることができます。そのようなケースでは、全てのトリガーされたハンドラが解決されたときに解決する Promise が戻り値として返ってくることになります。

docs/ja/api.md

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# API リファレンス
2+
3+
### Vuex.Store
4+
5+
``` js
6+
import Vuex from 'vuex'
7+
8+
const store = new Vuex.Store({ ...options })
9+
```
10+
11+
### Vuex.Store コンストラクタオプション
12+
13+
- **state**
14+
15+
- 型: `Object`
16+
17+
ストアのための ルートステートオブジェクトです。
18+
19+
[詳細](state.md)
20+
21+
- **mutations**
22+
23+
- 型: `{ [type: string]: Function }`
24+
25+
ストアにミューテーションを登録します。ハンドラ関数は第一引数に `state` を常に受け取り(モジュール内で定義されていれば、モジュールのローカルステートを受け取り)、指定されていれば第二引数に `payload` を受け取ります。
26+
27+
[詳細](mutations.md)
28+
29+
- **actions**
30+
31+
- 型: `{ [type: string]: Function }`
32+
33+
ストアにアクションを登録します。ハンドラ関数は次のプロパティを持つ `context` オブジェクトを受け取ります。:
34+
35+
``` js
36+
{
37+
state, // store.state と同じか、モジュール内にあればローカルステート
38+
rootState, // store.state と同じ。ただしモジュール内に限る
39+
commit, // store.commit と同じ
40+
dispatch, // store.dispatch と同じ
41+
getters // store.getters と同じ
42+
}
43+
```
44+
45+
[詳細](actions.md)
46+
47+
- **getters**
48+
49+
- type: `{ [key: string]: Function }`
50+
51+
ストアにゲッターを登録します. ゲッター関数は次の引数を受け取ります:
52+
53+
```
54+
state, // モジュール内で定義されていればモジュールのローカルステート
55+
getters, // store.getters と同じ
56+
rootState // store.state と同じ
57+
```
58+
59+
登録されたゲッターは `store.getters` 上に公開されます。
60+
61+
[詳細](getters.md)
62+
63+
- **modules**
64+
65+
-: `Object`
66+
67+
サブモジュールを含む次のような形式のオブジェクトはストアにマージされます。
68+
69+
``` js
70+
{
71+
key: {
72+
state,
73+
mutations
74+
actions?,
75+
getters?,
76+
modules?
77+
78+
},
79+
...
80+
}
81+
```
82+
83+
各モジュールは、ルートオプションに似た `state``mutations` を含むことができます。モジュールの状態は、モジュールのキーを使って、ストアのルートステートに結合されます。モジュールのミューテーションとゲッターは、第一引数としてルートステートの代わりに、モジュールのローカルステートだけを受け取り、モジュールのアクションの `context.state` もローカルステートを指すようになります。
84+
85+
[詳細](modules.md)
86+
87+
- **plugins**
88+
89+
-: `Array<Function>`
90+
91+
プラグイン関数の配列は、ストアに適用されます。このプラグインは、ストアだけを引数として受け取り、外部への永続化、ロギング、デバッギングのために、ミューテーションを監視するか、または、 websocket や observable のような外から渡されるデータのためにミューテーションをディスパッチします。
92+
93+
[詳細](plugins.md)
94+
95+
- **strict**
96+
97+
-: `Boolean`
98+
- デフォルト: `false`
99+
100+
Vuex ストアを厳格モードにします。厳格モードでは、ミューテーションハンドラ以外で、 Vuex の状態の変更を行うと、エラーが投げられます。
101+
102+
[詳細](strict.md)
103+
104+
### Vuex.Store インスタンスプロパティ
105+
106+
- **state**
107+
108+
- type: `Object`
109+
110+
ルートステート、読み取り専用です。
111+
112+
- **getters**
113+
114+
- type: `Object`
115+
116+
登録されているゲッターを公開します。読み取り専用です。
117+
118+
### Vuex.Store インスタンスメソッド
119+
120+
- **`commit(type: string, payload?: any) | commit(mutation: Object)`**
121+
122+
ミューテーションをコミットします。[詳細](mutations.md)
123+
124+
- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`**
125+
126+
アクションをディスパッチします。すべてのトリガーされたアクションハンドラを解決するPromiseを返します。[詳細](actions.md)
127+
128+
- **`replaceState(state: Object)`**
129+
130+
ストアのルートステートを置き換えます。これは、ステートのハイドレーションやタイムトラベルのためだけに利用すべきです。
131+
132+
- **`watch(getter: Function, cb: Function, options?: Object)`**
133+
134+
リアクティブにゲッター関数の返す値を監視します。値が変わった場合は、コールバックを呼びます。ゲッターはストアの状態のみを引数として受け取ります。 Vue の`vm.$watch`メソッドと同じオプションをオプションのオブジェクトとして受け付けます。
135+
136+
監視を止める場合は、ハンドラ関数の返り値を関数として呼び出します。
137+
138+
- **`subscribe(handler: Function)`**
139+
140+
ストアへのミューテーションを購読します。`handler` は、全てのミューテーションの後に呼ばれ、引数として、ミューテーション ディスクリプタとミューテーション後の状態を受け取ります。
141+
142+
``` js
143+
store.subscribe((mutation, state) => {
144+
console.log(mutation.type)
145+
console.log(mutation.payload)
146+
})
147+
```
148+
149+
プラグインの中でもっともよく利用されます。[詳細](plugins.md)
150+
151+
- **`registerModule(path: string | Array<string>, module: Module)`**
152+
153+
動的なモジュールを登録します。[詳細](modules.md#dynamic-module-registration)
154+
155+
- **`unregisterModule(path: string | Array<string>)`**
156+
157+
動的なモジュールを解除します。[詳細](modules.md#dynamic-module-registration)
158+
159+
- **`hotUpdate(newOptions: Object)`**
160+
161+
新しいアクションとミューテーションをホットスワップします。[詳細](hot-reload.md)
162+
163+
### コンポーネントをバインドするヘルパー
164+
165+
- **`mapState(map: Array<string> | Object): Object`**
166+
167+
ストアのサブツリーを返すコンポーネントの computed オプションを作成します。[詳細](state.md#the-mapstate-helper)
168+
169+
- **`mapGetters(map: Array<string> | Object): Object`**
170+
171+
ゲッターの評価後の値を返すコンポーネントの computed オプションを作成します。[詳細](getters.md#the-mapgetters-helper)
172+
173+
- **`mapActions(map: Array<string> | Object): Object`**
174+
175+
アクションをディスパッチするコンポーネントの methods オプションを作成します。[詳細](actions.md#dispatching-actions-in-components)
176+
177+
- **`mapMutations(map: Array<string> | Object): Object`**
178+
179+
ミューテーションをコミットするコンポーネントの methods オプションを作成します。[詳細](mutations.md#commiting-mutations-in-components)

0 commit comments

Comments
 (0)