Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate web-components.md #102

Merged
merged 6 commits into from
Feb 13, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions content/docs/web-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ redirect_from:
- "docs/webcomponents.html"
---

React and [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) are built to solve different problems. Web Components provide strong encapsulation for reusable components, while React provides a declarative library that keeps the DOM in sync with your data. The two goals are complementary. As a developer, you are free to use React in your Web Components, or to use Web Components in React, or both.
React [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components) は異なる課題を解決する為に構築されました。Web Components はコンポーネントをパッケージ化して、高い再利用性を与えます。一方で React DOM とデータを同期させる為の宣言型のライブラリを提供しています。この2つの目標は互いを補完しあっています。あなたは開発者として、Web Component 内で React を使用することも、React 内で Web Components を使用することも、あるいはその両方を行うこともできます。
smikitky marked this conversation as resolved.
Show resolved Hide resolved

Most people who use React don't use Web Components, but you may want to, especially if you are using third-party UI components that are written using Web Components.
React を使用するほとんどの人は Web Components を使用しませんが、Web Components を用いたサードパーティ製の UI コンポーネントを使用したい時などには活用できるかもしれません。

## Using Web Components in React {#using-web-components-in-react}
## React で Web Components を使用する {#using-web-components-in-react}

```javascript
class HelloMessage extends React.Component {
Expand All @@ -20,14 +20,14 @@ class HelloMessage extends React.Component {
}
```

> Note:
> 注意:
>
> Web Components often expose an imperative API. For instance, a `video` Web Component might expose `play()` and `pause()` functions. To access the imperative APIs of a Web Component, you will need to use a ref to interact with the DOM node directly. If you are using third-party Web Components, the best solution is to write a React component that behaves as a wrapper for your Web Component.
> Web Components はよく命令形の API を公開しています。例えば、`video` という Web Component `play()` `pause()` といった関数を公開しているかもしれません。Web Component が使う命令形の API にアクセスするには DOM ノードと直接やり取りするために ref を使う必要があります。サードパーティ製の Web Components を使用している場合は、Web Component の Wrapper として機能する React のコンポーネントを作成するのがベストな選択でしょう。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

訳語の統一より

https://github.com/reactjs/ja.reactjs.org/wiki/%E8%A8%B3%E8%AA%9E%E3%81%AE%E7%B5%B1%E4%B8%80

Suggested change
> Web Components はよく命令形の API を公開しています。例えば、`video` という Web Component が `play()``pause()` といった関数を公開しているかもしれません。Web Component が使う命令形の API にアクセスするには DOM ノードと直接やり取りするために ref を使う必要があります。サードパーティ製の Web Components を使用している場合は、Web Component の Wrapper として機能する React のコンポーネントを作成するのがベストな選択でしょう。
> Web Components はよく命令型の API を公開しています。例えば、`video` という Web Component が `play()``pause()` といった関数を公開しているかもしれません。Web Component が使う命令型の API にアクセスするには DOM ノードと直接やり取りするために ref を使う必要があります。サードパーティ製の Web Components を使用している場合は、Web Component の Wrapper として機能する React のコンポーネントを作成するのがベストな選択でしょう。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あと同じ行の"Wrapper"も「ラッパ」に変えていただいてよいでしょうか

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

レビューありがとうございます、指摘箇所を修正致しました!:bow:

>
> Events emitted by a Web Component may not properly propagate through a React render tree.
> You will need to manually attach event handlers to handle these events within your React components.
> Web Component から発された Event は React のレンダーツリーを正しく伝わってこない可能性があります。
> React コンポーネント内でイベントに適切に対応するにはそのためのイベントハンドラを与える必要があります。

One common confusion is that Web Components use "class" instead of "className".
よくある混乱の1つとして、Web Components が "className" の代わりに "class" を使用しているケースがあります。
smikitky marked this conversation as resolved.
Show resolved Hide resolved

```javascript
function BrickFlipbox() {
Expand All @@ -40,7 +40,7 @@ function BrickFlipbox() {
}
```

## Using React in your Web Components {#using-react-in-your-web-components}
## Web Components で React を使用する {#using-react-in-your-web-components}

```javascript
class XSearch extends HTMLElement {
Expand All @@ -56,7 +56,7 @@ class XSearch extends HTMLElement {
customElements.define('x-search', XSearch);
```

>Note:
>注釈:
smikitky marked this conversation as resolved.
Show resolved Hide resolved
>
>This code **will not** work if you transform classes with Babel. See [this issue](https://github.com/w3c/webcomponents/issues/587) for the discussion.
>Include the [custom-elements-es5-adapter](https://github.com/webcomponents/webcomponentsjs#custom-elements-es5-adapterjs) before you load your web components to fix this issue.
>Babel を使ってクラス変換を行うと上記のコードは**機能しません**。 詳細や議論は[この issue](https://github.com/w3c/webcomponents/issues/587) を参照してください.
smikitky marked this conversation as resolved.
Show resolved Hide resolved
>この問題を解決するには [custom-elements-es5-adapter](https://github.com/webcomponents/webcomponentsjs#custom-elements-es5-adapterjs) を Web Component の前に読み込む必要があります。
smikitky marked this conversation as resolved.
Show resolved Hide resolved