Skip to content

Commit 37b32b8

Browse files
authored
Merge pull request #312 from yuaanlin/docs/describing-the-ui
feat: translate describing the ui
2 parents 1459076 + 0d0a26a commit 37b32b8

File tree

2 files changed

+69
-62
lines changed

2 files changed

+69
-62
lines changed

beta/src/pages/learn/describing-the-ui.md

+60-53
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
---
2-
title: Describing the UI
2+
title: 描述使用者介面
33
---
44

55
<Intro>
66

7-
React is a JavaScript library for rendering user interfaces (UI). UI is built from small units like buttons, text, and images. React lets you combine them into reusable, nestable *components.* From web sites to phone apps, everything on the screen can be broken down into components. In this chapter, you'll learn to create, customize, and conditionally display React components.
7+
React 是一個用來渲染使用者介面 (UI) 的 Javascript 函式庫。一個完整的使用者介面是用各種小元件(例如按鈕、文字或圖片)組合而成。React 讓你將這些小元件組合成可以重複使用、可以巢狀使用的 *component*
8+
9+
無論是網站還是手機 App,所有畫面上的東西都可以被拆分成一個個 component。在這個章節,你將學會如何建立、客製化以及根據不同的條件來在畫面上渲染 React component。
810

911
</Intro>
1012

1113
<YouWillLearn isChapter={true}>
1214

13-
* [How to write your first React component](/learn/your-first-component)
14-
* [When and how to create multi-component files](/learn/importing-and-exporting-components)
15-
* [How to add markup to JavaScript with JSX](/learn/writing-markup-with-jsx)
16-
* [How to use curly braces with JSX to access JavaScript functionality from your components](/learn/javascript-in-jsx-with-curly-braces)
17-
* [How to configure components with props](/learn/passing-props-to-a-component)
18-
* [How to conditionally render components](/learn/conditional-rendering)
19-
* [How to render multiple components at a time](/learn/rendering-lists)
20-
* [How to avoid confusing bugs by keeping components pure](/learn/keeping-components-pure)
15+
* [如何寫出你的第一個 React Component](/learn/your-first-component)
16+
* [如何建立多個 Component 的檔案](/learn/importing-and-exporting-components)
17+
* [如何用 JSX 在 Javascript 中加入 Markup](/learn/writing-markup-with-jsx)
18+
* [如何在 JSX 中透過大括號來使用 Javascript 的語法](/learn/javascript-in-jsx-with-curly-braces)
19+
* [如何用 Props 來設定你的 Component](/learn/passing-props-to-a-component)
20+
* [如何根據特定條件來渲染 Component](/learn/conditional-rendering)
21+
* [如何一次渲染多個 Component](/learn/rendering-lists)
22+
* [如何把 Component 寫成「純函數」來避免容易混淆的錯誤](/learn/keeping-components-pure)
2123

2224
</YouWillLearn>
2325

24-
## Your first component {/*your-first-component*/}
26+
## 你的第一個 component {/*your-first-component*/}
27+
28+
一個完整的 React 應用程式是由多個被稱為 *Component* 的使用者介面分塊組合而成。一個 React Component 是一個你可以在裡面使用 Markup 語法的 Javascript 函數。
2529

26-
React applications are built from isolated pieces of UI called *components*. A React component is a JavaScript function that you can sprinkle with markup. Components can be as small as a button, or as large as an entire page. Here is a `Gallery` component rendering three `Profile` components:
30+
Component 可能小至一個按鈕,也可能大至整個頁面。這裡有一個名叫 `Gallery` 的 Component,這個 Component 裡面渲染了三個名叫 `Profile` 的 Component:
2731

2832
<Sandpack>
2933

@@ -40,7 +44,7 @@ function Profile() {
4044
export default function Gallery() {
4145
return (
4246
<section>
43-
<h1>Amazing scientists</h1>
47+
<h1>驚人的科學家們</h1>
4448
<Profile />
4549
<Profile />
4650
<Profile />
@@ -57,14 +61,13 @@ img { margin: 0 10px 10px 0; height: 90px; }
5761

5862
<LearnMore path="/learn/your-first-component">
5963

60-
Read **[Your First Component](/learn/your-first-component)** to learn how to declare and use React components.
64+
閱讀 **[你的第一個 Component](/learn/your-first-component)** 來學習如何宣告並使用 React Component。
6165

6266
</LearnMore>
6367

64-
## Importing and exporting components {/*importing-and-exporting-components*/}
65-
66-
You can declare many components in one file, but large files can get difficult to navigate. To solve this, you can *export* a component into its own file, and then *import* that component from another file:
68+
## 導入和導出 Component {/*importing-and-exporting-components*/}
6769

70+
你可以在一個檔案中宣告很多的 Component,但如果檔案太大的話我們將很難快速的找到想要的程式碼在檔案的哪個位置。為了解決這個問題,你可以從一個檔案 *導出* 一個 Component,然後在另一個檔案中 *導入* 這個 Component 並使用他:
6871

6972
<Sandpack>
7073

@@ -84,7 +87,7 @@ import Profile from './Profile.js';
8487
export default function Gallery() {
8588
return (
8689
<section>
87-
<h1>Amazing scientists</h1>
90+
<h1>驚人的科學家們</h1>
8891
<Profile />
8992
<Profile />
9093
<Profile />
@@ -112,23 +115,23 @@ img { margin: 0 10px 10px 0; }
112115

113116
<LearnMore path="/learn/importing-and-exporting-components">
114117

115-
Read **[Importing and Exporting Components](/learn/importing-and-exporting-components)** to learn how to split components into their own files.
118+
閱讀 **[導入及導出 Component](/learn/importing-and-exporting-components)** 來學習如何把多個 Component 拆分到屬於他們自己的檔案中。
116119

117120
</LearnMore>
118121

119-
## Writing markup with JSX {/*writing-markup-with-jsx*/}
122+
## 用 JSX 來撰寫 Markup 語法 {/*writing-markup-with-jsx*/}
120123

121-
Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information.
124+
每個 React component 都是一個可以渲染一些 Markup 語法到瀏覽器的 Javascript 函數,React components 使用一個語法擴充功能稱作 JSX 來表示這些 Markup 語法。JSX 看起來就像 HTML 一樣,但他比 HTML 更加嚴格一些,並且能夠顯示出動態的資訊。
122125

123-
If we paste existing HTML markup into a React component, it won't always work:
126+
如果你把一個 HTML Markup 直接貼到一個 React component 中,他不一定可以正常運作:
124127

125128
<Sandpack>
126129

127130
```js
128131
export default function TodoList() {
129132
return (
130-
// This doesn't quite work!
131-
<h1>Hedy Lamarr's Todos</h1>
133+
// 這個寫法沒辦法正常運作!
134+
<h1>Hedy Lamarr 的待辦事項</h1>
132135
<img
133136
src="https://i.imgur.com/yXOvdOSs.jpg"
134137
alt="Hedy Lamarr"
@@ -149,15 +152,15 @@ img { height: 90px; }
149152

150153
</Sandpack>
151154

152-
If you have existing HTML like this, you can fix it using a [converter](https://transform.tools/html-to-jsx):
155+
如果你有像這樣的現成 HTML,你可以用這個 [轉換工具](https://transform.tools/html-to-jsx) 來修復他。
153156

154157
<Sandpack>
155158

156159
```js
157160
export default function TodoList() {
158161
return (
159162
<>
160-
<h1>Hedy Lamarr's Todos</h1>
163+
<h1>Hedy Lamarr 的待辦事項</h1>
161164
<img
162165
src="https://i.imgur.com/yXOvdOSs.jpg"
163166
alt="Hedy Lamarr"
@@ -181,13 +184,15 @@ img { height: 90px; }
181184

182185
<LearnMore path="/learn/writing-markup-with-jsx">
183186

184-
Read **[Writing Markup with JSX](/learn/writing-markup-with-jsx)** to learn how to write valid JSX.
187+
閱讀 **[用 JSX 來撰寫 Markup 語法](/learn/writing-markup-with-jsx)** 來學習如何撰寫正確的 JSX 語法。
185188

186189
</LearnMore>
187190

188-
## JavaScript in JSX with curly braces {/*javascript-in-jsx-with-curly-braces*/}
191+
## JSX 中使用 Javascript 的語法 {/*javascript-in-jsx-with-curly-braces*/}
189192

190-
JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to "open a window" to JavaScript:
193+
JSX 讓你可以在 Javascript 檔案中使用類似 HTML 的語法,這讓我們把渲染邏輯和內容能夠寫在同一個地方。有時候你可能想要在 Markup 中使用一些 Javascript 的邏輯或是引入一個動態的變數。
194+
195+
在這種情況,你可以在 JSX 語法中使用 **大括號** 來「打開一個 Javascript 的視窗」:
191196

192197
<Sandpack>
193198

@@ -203,7 +208,7 @@ const person = {
203208
export default function TodoList() {
204209
return (
205210
<div style={person.theme}>
206-
<h1>{person.name}'s Todos</h1>
211+
<h1>{person.name} 的待辦事項</h1>
207212
<img
208213
className="avatar"
209214
src="https://i.imgur.com/7vQD0fPs.jpg"
@@ -229,13 +234,15 @@ body > div > div { padding: 20px; }
229234

230235
<LearnMore path="/learn/javascript-in-jsx-with-curly-braces">
231236

232-
Read **[JavaScript in JSX with Curly Braces](/learn/javascript-in-jsx-with-curly-braces)** to learn how to access JavaScript data from JSX.
237+
閱讀 **[JSX 中使用 Javascript 的語法](/learn/javascript-in-jsx-with-curly-braces)** 來學習如何在 JSX 語法中存取 JavaScript 的資料。
233238

234239
</LearnMore>
235240

236-
## Passing props to a component {/*passing-props-to-a-component*/}
241+
## 傳遞 Props 到一個 Component 中 {/*passing-props-to-a-component*/}
242+
243+
React components 使用 *props* 來互相傳遞資訊。每個上層的 Component 都可以藉由賦予他們 Props 的方式來傳遞一些資訊到他的下層 Component 中。
237244

238-
React components use *props* to communicate with each other. Every parent component can pass some information to its child components by giving them props. Props might remind you of HTML attributes, but you can pass any JavaScript value through them, including objects, arrays, functions, and even JSX!
245+
Props 可能會讓你想起 HTML 語法中的 attributes,但你可以傳遞任何 JavaScript 的變數到 Props 中,包括物件、陣列、函數,甚至是 JSX
239246

240247
<Sandpack>
241248

@@ -310,15 +317,15 @@ export function getImageUrl(person, size = 's') {
310317

311318
<LearnMore path="/learn/passing-props-to-a-component">
312319

313-
Read **[Passing Props to a Component](/learn/passing-props-to-a-component)** to learn how to pass and read props.
320+
閱讀 **[傳遞 Props Component](/learn/passing-props-to-a-component)** 來學習如何傳入 Props 到 Component 中並使用他。
314321

315322
</LearnMore>
316323

317-
## Conditional rendering {/*conditional-rendering*/}
324+
## 條件渲染 {/*conditional-rendering*/}
318325

319-
Your components will often need to display different things depending on different conditions. In React, you can conditionally render JSX using JavaScript syntax like `if` statements, `&&`, and `? :` operators.
326+
有時候你的 Component 會需要根據不同的條件來展示不同的內容。在 React 中,你可以使用 JavaScript 語法中的 `if` 陳述式,`&&` 以及 `? :` 運算子來根據條件渲染不同的 JSX。
320327

321-
In this example, the JavaScript `&&` operator is used to conditionally render a checkmark:
328+
在下面的範例中,我們用 JavaScript `&&` 運算子來根據條件渲染打勾符號:
322329

323330
<Sandpack>
324331

@@ -358,15 +365,15 @@ export default function PackingList() {
358365
359366
<LearnMore path="/learn/conditional-rendering">
360367
361-
Read **[Conditional Rendering](/learn/conditional-rendering)** to learn the different ways to render content conditionally.
368+
閱讀 **[條件渲染](/learn/conditional-rendering)** 來學習各種根據條件來渲染內容的方法。
362369
363370
</LearnMore>
364371
365-
## Rendering lists {/*rendering-lists*/}
372+
## 列表渲染 {/*rendering-lists*/}
366373
367-
You will often want to display multiple similar components from a collection of data. You can use JavaScript's `filter()` and `map()` with React to filter and transform your array of data into an array of components.
374+
你經常會需要用多個相似的 Component 來展示一系列的資料。這個時候你可以在 React 中使用 JavaScript`filter()` `map()` 來篩選資料並轉換成包含多個 Component 的陣列。
368375
369-
For each array item, you will need to specify a `key`. Usually, you will want to use an ID from the database as a `key`. Keys let React keep track of each item's place in the list even if the list changes.
376+
對轉換後的陣列中的每個物件,你必須要幫他們指定一個 `key`。 一般來說,你可以用他們在資料庫中的 ID 來作為 `key`。 Key 可以讓 React 知道列表中每個物件當前的位置,即便你的列表發生了改動也沒關係。
370377
371378
<Sandpack>
372379
@@ -390,7 +397,7 @@ export default function List() {
390397
);
391398
return (
392399
<article>
393-
<h1>Scientists</h1>
400+
<h1>科學家列表</h1>
394401
<ul>{listItems}</ul>
395402
</article>
396403
);
@@ -458,18 +465,18 @@ h2 { font-size: 20px; }
458465

459466
<LearnMore path="/learn/rendering-lists">
460467

461-
Read **[Rendering Lists](/learn/rendering-lists)** to learn how to render a list of components, and how to choose a key.
468+
閱讀 **[列表渲染](/learn/rendering-lists)** 來學習如何一次把一個陣列渲染成多個 Component,以及如何幫每個 Component 選擇一個 key
462469

463470
</LearnMore>
464471

465-
## Keeping components pure {/*keeping-components-pure*/}
472+
## 把 Component 寫成「純函數」 {/*keeping-components-pure*/}
466473

467-
Some JavaScript functions are *pure.* A pure function:
474+
我們說一個 JavaScript 的函數是一個 *純函數* (Pure Function) ,如果他滿足這些條件:
468475

469-
* **Minds its own business.** It does not change any objects or variables that existed before it was called.
470-
* **Same inputs, same output.** Given the same inputs, a pure function should always return the same result.
476+
* **不多管閒事** : 這個函數不會修改任何在他被呼叫之前就已經存在的物件或變數。
477+
* **一樣的輸入,一樣的輸出** : 只要我們輸入相同的參數,這個函數總是回傳一個相同的輸出。
471478

472-
By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. Here is an example of an impure component:
479+
如果我們嚴格地把 Component 都寫成純函數,就可以在隨著專案規模越來越大的過程中避免一系列不可預期的問題出現。這裡給出了一個「不純的函數」作為例子:
473480

474481
<Sandpack>
475482

@@ -495,7 +502,7 @@ export default function TeaSet() {
495502

496503
</Sandpack>
497504

498-
You can make this component pure by passing a prop instead of modifying a preexisting variable:
505+
你可以藉由改成 Props 傳入資料的方式,而不是直接從外部讀取,來將函數改造為純函數:
499506

500507
<Sandpack>
501508

@@ -519,12 +526,12 @@ export default function TeaSet() {
519526

520527
<LearnMore path="/learn/keeping-components-pure">
521528

522-
Read **[Keeping Components Pure](/learn/keeping-components-pure)** to learn how to write components as pure, predictable functions.
529+
閱讀 **[把 Component 寫成「純函數」](/learn/keeping-components-pure)** 來學習如何用「純函數」且「行為可預測」的寫法來撰寫 Component。
523530

524531
</LearnMore>
525532

526-
## What's next? {/*whats-next*/}
533+
## 下一步 {/*whats-next*/}
527534

528-
Head over to [Your First Component](/learn/your-first-component) to start reading this chapter page by page!
535+
出發前往 [你的第一個 Component](/learn/your-first-component) 來一頁一頁閱讀這個章節的內容!
529536

530-
Or, if you're already familiar with these topics, why not read about [Adding Interactivity](/learn/adding-interactivity)?
537+
或是,如果你已經熟悉這些主題了,不妨瞭解看看 [加入可互動性](/learn/adding-interactivity) ?

beta/src/sidebarLearn.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,40 @@
3838
}]
3939
},
4040
{
41-
"title": "Describing the UI",
41+
"title": "描述使用者介面",
4242
"tags": [],
4343
"path": "/learn/describing-the-ui",
4444
"routes": [
4545
{
46-
"title": "Your First Component",
46+
"title": "你的第一個 Component",
4747
"path": "/learn/your-first-component"
4848
},
4949
{
50-
"title": "Importing and Exporting Components",
50+
"title": "導入及導出 Component",
5151
"path": "/learn/importing-and-exporting-components"
5252
},
5353
{
54-
"title": "Writing Markup with JSX",
54+
"title": "用 JSX 撰寫 Markup",
5555
"path": "/learn/writing-markup-with-jsx"
5656
},
5757
{
58-
"title": "JavaScript in JSX with Curly Braces",
58+
"title": "JSX 中使用 JavaScript 的語法",
5959
"path": "/learn/javascript-in-jsx-with-curly-braces"
6060
},
6161
{
62-
"title": "Passing Props to a Component",
62+
"title": "傳遞 Props Component",
6363
"path": "/learn/passing-props-to-a-component"
6464
},
6565
{
66-
"title": "Conditional Rendering",
66+
"title": "條件渲染",
6767
"path": "/learn/conditional-rendering"
6868
},
6969
{
70-
"title": "Rendering Lists",
70+
"title": "列表渲染",
7171
"path": "/learn/rendering-lists"
7272
},
7373
{
74-
"title": "Keeping Components Pure",
74+
"title": "把 Component 寫成「純函數」",
7575
"path": "/learn/keeping-components-pure"
7676
}
7777
]

0 commit comments

Comments
 (0)