Skip to content

Commit 0100ebc

Browse files
committed
doc: Translate Context
1 parent ab1da7c commit 0100ebc

9 files changed

+99
-101
lines changed

content/docs/context.md

Lines changed: 68 additions & 70 deletions
Large diffs are not rendered by default.

examples/context/motivation-problem.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class App extends React.Component {
66

77
function Toolbar(props) {
88
// highlight-range{1-4,7}
9-
// The Toolbar component must take an extra "theme" prop
10-
// and pass it to the ThemedButton. This can become painful
11-
// if every single button in the app needs to know the theme
12-
// because it would have to be passed through all components.
9+
// Toolbar コンポーネントは外部から”theme”プロパティを受け取らなければなりません。
10+
// そして、プロパティを ThemedButton へ渡します。
11+
// アプリ内の各ボタンがテーマを知る必要がある場合、
12+
// プロパティは全てのコンポーネントを通して渡される為、面倒になります。
1313
return (
1414
<div>
1515
<ThemedButton theme={props.theme} />

examples/context/motivation-solution.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// highlight-range{1-4}
2-
// Context lets us pass a value deep into the component tree
3-
// without explicitly threading it through every component.
4-
// Create a context for the current theme (with "light" as the default).
2+
// コンテクストを使用すると、全てのコンポーネントを明示的に通すことなしに
3+
// コンポーネントツリーの深くまで値を渡すことができます。
4+
// 現在のテーマ(デフォルトは”light”)の為のコンテクストを作成します。
55
const ThemeContext = React.createContext('light');
66

77
class App extends React.Component {
88
render() {
99
// highlight-range{1-3,5}
10-
// Use a Provider to pass the current theme to the tree below.
11-
// Any component can read it, no matter how deep it is.
12-
// In this example, we're passing "dark" as the current value.
10+
// 以下のツリーへ現在のテーマを渡すためにプロバイダを使用します。
11+
// どんな深さでも、どのようなコンポーネントでも読み取ることができます。
12+
// このサンプルでは、”dark”を現在の値として渡しています。
1313
return (
1414
<ThemeContext.Provider value="dark">
1515
<Toolbar />
@@ -19,8 +19,8 @@ class App extends React.Component {
1919
}
2020

2121
// highlight-range{1,2}
22-
// A component in the middle doesn't have to
23-
// pass the theme down explicitly anymore.
22+
// 間のコンポーネントはもう明示的にテーマを
23+
// 下に渡す必要はありません。
2424
function Toolbar(props) {
2525
return (
2626
<div>
@@ -31,9 +31,9 @@ function Toolbar(props) {
3131

3232
class ThemedButton extends React.Component {
3333
// highlight-range{1-3,6}
34-
// Assign a contextType to read the current theme context.
35-
// React will find the closest theme Provider above and use its value.
36-
// In this example, the current theme is "dark".
34+
// 現在のテーマのコンテクストを読むために、contextType に指定します。
35+
// React は上位の最も近いテーマプロバイダを見つけ、その値を使用します。
36+
// この例では、現在のテーマは”dark”です。
3737
static contextType = ThemeContext;
3838
render() {
3939
return <Button theme={this.context} />;

examples/context/multiple-contexts.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Theme context, default to light theme
1+
// テーマのコンテクスト、デフォルトのテーマは light
22
const ThemeContext = React.createContext('light');
33

4-
// Signed-in user context
4+
// サインイン済みのユーザのコンテクスト
55
const UserContext = React.createContext({
66
name: 'Guest',
77
});
@@ -10,7 +10,7 @@ class App extends React.Component {
1010
render() {
1111
const {signedInUser, theme} = this.props;
1212

13-
// App component that provides initial context values
13+
// コンテクストの初期値を与える APP コンポーネント
1414
// highlight-range{2-3,5-6}
1515
return (
1616
<ThemeContext.Provider value={theme}>
@@ -31,7 +31,7 @@ function Layout() {
3131
);
3232
}
3333

34-
// A component may consume multiple contexts
34+
// コンポーネントは複数のコンテクストを使用する可能性があります
3535
function Content() {
3636
// highlight-range{2-10}
3737
return (

examples/context/theme-detailed-app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {ThemeContext, themes} from './theme-context';
22
import ThemedButton from './themed-button';
33

4-
// An intermediate component that uses the ThemedButton
4+
// ThemedButtonを使用する間のコンポーネント
55
function Toolbar(props) {
66
return (
77
<ThemedButton onClick={props.changeTheme}>
@@ -29,9 +29,9 @@ class App extends React.Component {
2929

3030
render() {
3131
//highlight-range{1-3}
32-
// The ThemedButton button inside the ThemeProvider
33-
// uses the theme from state while the one outside uses
34-
// the default dark theme
32+
// ThemeProvider 内の ThemedButton ボタンは
33+
// state からのテーマを使用し、外側では
34+
// デフォルトの dark テーマを使用します
3535
//highlight-range{3-5,7}
3636
return (
3737
<Page>

examples/context/theme-detailed-theme-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export const themes = {
1111

1212
// highlight-range{1-3}
1313
export const ThemeContext = React.createContext(
14-
themes.dark // default value
14+
themes.dark // デフォルトの値
1515
);

examples/context/updating-nested-context-app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class App extends React.Component {
1515
};
1616

1717
// highlight-range{1-2,5}
18-
// State also contains the updater function so it will
19-
// be passed down into the context provider
18+
// state には更新する関数も含まれているため、
19+
// コンテクストプロバイダにも渡されます。
2020
this.state = {
2121
theme: themes.light,
2222
toggleTheme: this.toggleTheme,
@@ -25,7 +25,7 @@ class App extends React.Component {
2525

2626
render() {
2727
// highlight-range{1,3}
28-
// The entire state is passed to the provider
28+
// state は全部プロバイダへ渡されます
2929
return (
3030
<ThemeContext.Provider value={this.state}>
3131
<Content />

examples/context/updating-nested-context-context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Make sure the shape of the default value passed to
2-
// createContext matches the shape that the consumers expect!
1+
// createContextに渡されるデフォルトの値の形が、
2+
// コンシューマが期待する形と一致することを確認してください!
33
// highlight-range{2-3}
44
export const ThemeContext = React.createContext({
55
theme: themes.dark,

examples/context/updating-nested-context-theme-toggler-button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {ThemeContext} from './theme-context';
22

33
function ThemeTogglerButton() {
44
// highlight-range{1-2,5}
5-
// The Theme Toggler Button receives not only the theme
6-
// but also a toggleTheme function from the context
5+
// ThemeTogglerButton は theme だけでなく、
6+
// toggleTheme 関数もコンテクストから受け取ります
77
return (
88
<ThemeContext.Consumer>
99
{({theme, toggleTheme}) => (

0 commit comments

Comments
 (0)