Skip to content

Commit 155cce9

Browse files
committed
docs: translate cookbook > automatic global registration of base components
1 parent 596cbfe commit 155cce9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/cookbook/automatic-global-registration-of-base-components.md

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# Automatic Global Registration of Base Components
1+
# ベースコンポーネントの自動グローバル登録
22

3-
## Base Example
3+
## 基本的な例
44

5-
Many of your components will be relatively generic, possibly only wrapping an element like an input or a button. We sometimes refer to these as [base components](../style-guide/#base-component-names-strongly-recommended) and they tend to be used very frequently across your components.
5+
多くのコンポーネントは割と一般的なもので、あるいは入力やボタンをラップするだけのものかもしれません。わたしたちは、このようなコンポーネントを [ベースコンポーネント](../style-guide/#base-component-names-strongly-recommended) と呼ぶことがあって、コンポーネント全体に渡ってとても頻繁に使われる傾向があります。
66

7-
The result is that many components may include long lists of base components:
7+
8+
その結果、多くのコンポーネントはベースコンポーネントの長いリストに含まれていることがあります:
89

910
```js
1011
import BaseButton from './BaseButton.vue'
@@ -19,7 +20,7 @@ export default {
1920
}
2021
```
2122

22-
Just to support relatively little markup in a template:
23+
テンプレート内の比較的小さなマークアップをサポートするためだけのものです:
2324

2425
```html
2526
<BaseInput v-model="searchText" @keydown.enter="search" />
@@ -28,7 +29,7 @@ Just to support relatively little markup in a template:
2829
</BaseButton>
2930
```
3031

31-
Fortunately, if you're using webpack (or [Vue CLI](https://github.com/vuejs/vue-cli), which uses webpack internally), you can use `require.context` to globally register only these very common base components. Here's an example of the code you might use to globally import base components in your app's entry file (e.g. `src/main.js`):
32+
幸いなことに、webpack(または [Vue CLI](https://github.com/vuejs/vue-cli)、これは内部的に webpack を使っています)を使う場合、これらのとても汎用的なベースコンポーネントだけをグローバルに登録するのに `require.context` を使うことができます。このコード例は、アプリケーションのエントリファイル(例えば `src/main.js`)でベースコンポーネントをグローバルにインポートするのに使えるでしょう:
3233

3334
```js
3435
import { createApp } from 'vue'
@@ -39,22 +40,22 @@ import App from './App.vue'
3940
const app = createApp(App)
4041

4142
const requireComponent = require.context(
42-
// The relative path of the components folder
43+
// コンポーネントフォルダの相対パス
4344
'./components',
44-
// Whether or not to look in subfolders
45+
// サブフォルダ内を探すかどうか
4546
false,
46-
// The regular expression used to match base component filenames
47+
// ベースコンポーネントのファイル名とマッチさせるための正規表現
4748
/Base[A-Z]\w+\.(vue|js)$/
4849
)
4950

5051
requireComponent.keys().forEach(fileName => {
51-
// Get component config
52+
// コンポーネント設定の取得
5253
const componentConfig = requireComponent(fileName)
5354

54-
// Get PascalCase name of component
55+
// コンポーネントのパスカルケースでの名前を取得
5556
const componentName = upperFirst(
5657
camelCase(
57-
// Gets the file name regardless of folder depth
58+
// フォルダの深さに関わらずファイル名を取得
5859
fileName
5960
.split('/')
6061
.pop()
@@ -64,9 +65,9 @@ requireComponent.keys().forEach(fileName => {
6465

6566
app.component(
6667
componentName,
67-
// Look for the component options on `.default`, which will
68-
// exist if the component was exported with `export default`,
69-
// otherwise fall back to module's root.
68+
// `.default` にあるコンポーネントのオプションを探す。
69+
// コンポーネントが `export default` でエクスポートされていれば存在して、
70+
// そうでなければモジュールのルートのフォールバックする。
7071
componentConfig.default || componentConfig
7172
)
7273
})

0 commit comments

Comments
 (0)