Skip to content

Commit 49f53fe

Browse files
ChelesteWangQC-Llyj505KnowsCount
authored
[Beta]: docs(cn): translate describing the ui (#650)
* docs(cn): translate describing the ui * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update describing-the-ui.md * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: lyj505 <920245353@qq.com> * docs(cn): optimized translation * Update beta/src/pages/learn/describing-the-ui.md Co-authored-by: KnowsCount <knowscount@gmail.com> * Apply suggestions from code review * Fix fullstop position Co-authored-by: QiChang Li <github@liqichang.com> Co-authored-by: lyj505 <920245353@qq.com> Co-authored-by: KnowsCount <knowscount@gmail.com>
1 parent 1261a39 commit 49f53fe

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

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

+50-47
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
---
2-
title: Describing the UI
2+
title: 描述用户界面
3+
translators:
4+
- ChelesteWang
5+
- QC-L
6+
- KnowsCount
7+
- lyj505
38
---
49

510
<Intro>
611

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.
12+
React 是一个用于构建用户界面(UI)的 JavaScript 库,用户界面由按钮、文本和图像等小单元内容构建而成。React 帮助你把它们组合成可重用、可嵌套的 *组件*。从 web 端网站到移动端应用,屏幕上的所有内容都可以被分解成组件。在本章节中,你将学习如何创建、定制以及有条件地显示 React 组件。
813

914
</Intro>
1015

1116
<YouWillLearn isChapter={true}>
1217

13-
* [How to write your first React component](/learn/your-first-component)
14-
* [When and how to create multi-file components](/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)
18+
* [如何创建你的第一个组件](/learn/your-first-component)
19+
* [在什么时候以及如何创建多文件组件](/learn/importing-and-exporting-components)
20+
* [如何使用 JSX 为 JavaScript 添加标记](/learn/writing-markup-with-jsx)
21+
* [如何在 JSX 中使用花括号来从组件中使用 JavaScript 功能](/learn/javascript-in-jsx-with-curly-braces)
22+
* [如何用 props 配置组件](/learn/passing-props-to-a-component)
23+
* [如何有条件地渲染组件](/learn/conditional-rendering)
24+
* [如何在同一时间渲染多个组件](/learn/rendering-lists)
25+
* [如何通过保持组件的纯粹性来避免令人困惑的错误](/learn/keeping-components-pure)
2126

2227
</YouWillLearn>
2328

24-
## Your first component {/*your-first-component*/}
29+
## 你的第一个组件 {/*your-first-component*/}
2530

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:
31+
React 应用是由被称为 “组件” 的独立 UI 片段构建而成。React 组件本质上是可以任意添加标记的 JavaScript 函数。组件可以小到一个按钮,也可以大到是整个页面。这是一个 `Gallery` 组件,用于渲染三个 `Profile` 组件:
2732

2833
<Sandpack>
2934

@@ -57,14 +62,13 @@ img { margin: 0 10px 10px 0; height: 90px; }
5762

5863
<LearnMore path="/learn/your-first-component">
5964

60-
Read **[Your First Component](/learn/your-first-component)** to learn how to declare and use React components.
65+
请参阅 **[你的第一个组件](/learn/your-first-component)** 以学习如何声明并使用 React 组件
6166

6267
</LearnMore>
6368

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:
69+
## 导入与导出组件 {/*importing-and-exporting-components*/}
6770

71+
你可以在一个文件中声明许多组件,但文件的体积过大会变得难以浏览。为了解决这个问题,你可以在一个文件中只*导出*一个组件,然后再从另一个文件中*导入*该组件:
6872

6973
<Sandpack>
7074

@@ -112,15 +116,14 @@ img { margin: 0 10px 10px 0; }
112116

113117
<LearnMore path="/learn/importing-and-exporting-components">
114118

115-
Read **[Importing and Exporting Components](/learn/importing-and-exporting-components)** to learn how to split components into their own files.
116-
119+
请参阅 **[导入与导出组件](/learn/importing-and-exporting-components)** 以学习如何切分组件。
117120
</LearnMore>
118121

119-
## Writing markup with JSX {/*writing-markup-with-jsx*/}
122+
## 使用 JSX 编写标记 {/*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 组件都是一个 JavaScript 函数,它可能包含一些标记,React 会将其渲染到浏览器中。React 组件使用一种叫做 JSX 的语法扩展来表示该标记。JSX 看起来很像 HTML,但它更为严格,可以显示动态信息。
122125

123-
If we paste existing HTML markup into a React component, it won't always work:
126+
如果我们把现有的 HTML 标记粘贴到 React 组件中,它并不一定能成功运行:
124127

125128
<Sandpack>
126129

@@ -149,7 +152,7 @@ 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 片段,你可以使用它进行语法转换 [converter](https://transform.tools/html-to-jsx)
153156
154157
<Sandpack>
155158
@@ -181,13 +184,13 @@ 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 编写标记](/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 的标记语法,使渲染逻辑和内容展示维护在同一个地方。有时你会想在标记中添加一点 JavaScript 逻辑或引用一个动态属性。在这种情况下,你可以在 JSX 中使用花括号来为 JavaScript "开辟通道":
191194

192195
<Sandpack>
193196

@@ -229,13 +232,13 @@ body > div > div { padding: 20px; }
229232
230233
<LearnMore path="/learn/javascript-in-jsx-with-curly-braces">
231234
232-
Read **[JavaScript in JSX with Curly Braces](/learn/javascript-in-jsx-with-curly-braces)** to learn how to access JavaScript data from JSX.
235+
请参阅 **[JSX 中使用大括号编写 JavaScript](/learn/javascript-in-jsx-with-curly-braces)** 以学习如何从 JSX 中访问 JavaScript 数据。
233236
234237
</LearnMore>
235238
236-
## Passing props to a component {/*passing-props-to-a-component*/}
239+
## 将 `props` 传递给一个组件 {/*passing-props-to-a-component*/}
237240
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!
241+
React 组件使用 *props* 来进行组件之间的通讯。每个父组件都可以通过为子组件提供 props 的方式来传递信息。props 可能会让你想起 HTML 属性,但你可以通过它们传递任何 JavaScript 的值,包括对象、数组、函数、甚至是 JSX!
239242
240243
<Sandpack>
241244
@@ -310,15 +313,15 @@ export function getImageUrl(person, size = 's') {
310313

311314
<LearnMore path="/learn/passing-props-to-a-component">
312315

313-
Read **[Passing Props to a Component](/learn/passing-props-to-a-component)** to learn how to pass and read props.
316+
请参阅 **[向组件传递 props](/learn/passing-props-to-a-component)** 以了解如何传递并读取 props
314317

315318
</LearnMore>
316319

317-
## Conditional rendering {/*conditional-rendering*/}
320+
## 条件渲染 {/*conditional-rendering*/}
318321

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.
322+
你的组件经常需要根据不同的条件来显示不同的东西。在 React 中,你可以使用 JavaScript 语法,如 `if` 语句、`&&` `? :` 操作符有条件地渲染 JSX。
320323

321-
In this example, the JavaScript `&&` operator is used to conditionally render a checkmark:
324+
在这个示例中,JavaScript `&&` 操作符将会条件渲染一个复选标记:
322325

323326
<Sandpack>
324327

@@ -358,15 +361,15 @@ export default function PackingList() {
358361
359362
<LearnMore path="/learn/conditional-rendering">
360363
361-
Read **[Conditional Rendering](/learn/conditional-rendering)** to learn the different ways to render content conditionally.
364+
请参阅 **[条件渲染](/learn/conditional-rendering)** 以学习使用不同的方法对内容进行条件渲染。
362365
363366
</LearnMore>
364367
365-
## Rendering lists {/*rendering-lists*/}
368+
## 渲染列表 {/*rendering-lists*/}
366369
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.
370+
通常,你需要根据数据集合来渲染多个较为类似的组件。你可以在 React 中使用 JavaScript`filter()` `map()` 来实现数组的过滤和转换,将数据数组转换为组件数组。
368371
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.
372+
对于数组的每个元素项,你需要指定一个 `key`。通常你需要使用数据库中的 ID 作为 `key`。即使列表发生了变化,React 也可以通过 key 来跟踪每个元素在列表中的位置。
370373
371374
<Sandpack>
372375
@@ -458,18 +461,18 @@ h2 { font-size: 20px; }
458461

459462
<LearnMore path="/learn/rendering-lists">
460463

461-
Read **[Rendering Lists](/learn/rendering-lists)** to learn how to render a list of components, and how to choose a key.
464+
请参阅 **[渲染列表](/learn/rendering-lists)** 以学习如何渲染一个组件列表,以及如何选择一个 `key`
462465

463466
</LearnMore>
464467

465-
## Keeping components pure {/*keeping-components-pure*/}
468+
## 保持组件的纯粹 {/*keeping-components-pure*/}
466469

467-
Some JavaScript functions are “pure.” A pure function:
470+
有些 JavaScript 函数是 "纯粹" 的。纯函数的基本定义:
468471

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.
472+
* **管好自己的事**。 在函数调用前,它不会改变任何已经存在的对象或变量。
473+
* **输入相同,输出也相同**。 在输入相同的情况下,对纯函数来说应总是返回相同的结果。
471474

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:
475+
严格遵循纯函数的定义编写组件,可以让代码库体量增长时,避免一些令人困惑的错误和不可预测的行为。下面是一个非纯函数组件的示例:
473476

474477
<Sandpack>
475478

@@ -495,7 +498,7 @@ export default function TeaSet() {
495498

496499
</Sandpack>
497500

498-
You can make this component pure by passing a prop instead of modifying a preexisting variable:
501+
你可以通过传递一个 `props` 来使这个组件变得纯粹,而非修改已经存在的变量:
499502

500503
<Sandpack>
501504

@@ -519,12 +522,12 @@ export default function TeaSet() {
519522

520523
<LearnMore path="/learn/keeping-components-pure">
521524

522-
Read **[Keeping Components Pure](/learn/keeping-components-pure)** to learn how to write components as pure, predictable functions.
525+
请参阅 **[保持组件的纯粹](/learn/keeping-components-pure)** 以学习如何将组件写成纯粹且可预测的函数。
523526

524527
</LearnMore>
525528

526-
## What's next? {/*whats-next*/}
529+
## 下节预告 {/*whats-next*/}
527530

528-
Head over to [Your First Component](/learn/your-first-component) to start reading this chapter page by page!
531+
请访问 [你的第一个组件](/learn/your-first-component) 这个章节并开始阅读!
529532

530-
Or, if you're already familiar with these topics, why not read about [Adding Interactivity](/learn/adding-interactivity)?
533+
如若你已熟悉这些主题,可直接阅读 [增加交互](/learn/adding-interactivity) 一节。

0 commit comments

Comments
 (0)