-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
docs(cn): translate content/docs/jsx-in-depth.md into Chinese #158
Conversation
Deploy preview for cn-reactjs ready! Built with commit 9b865a0 |
Deploy preview for zh-hans-reactjs ready! Built with commit 9b865a0 |
@@ -13,15 +13,16 @@ redirect_from: | |||
- "docs/jsx-in-depth-ko-KR.html" | |||
--- | |||
|
|||
Fundamentally, JSX just provides syntactic sugar for the `React.createElement(component, props, ...children)` function. The JSX code: | |||
|
|||
实际上,JSX 仅仅只是 `React.createElement(component, props, ...children)` 函数的语法糖。如下 JSX 代码: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多了一行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当时故意的,因为在CI 构建后的预览地址中,发现首行字体会被放大,当时以为是空格问题(后来发现是样式有问题)。我会移除掉,并把commit合并为一次。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是我对于这篇翻译的一些改进想法。请多指教。
content/docs/jsx-in-depth.md
Outdated
|
||
Capitalized types indicate that the JSX tag is referring to a React component. These tags get compiled into a direct reference to the named variable, so if you use the JSX `<Foo />` expression, `Foo` must be in scope. | ||
大写开头的 JSX 标签意味着它们是 React 组件。这些标签会被编译为对命名变量的直接引用,所以,当您使用 JSX `<Foo />` 表达式时,`Foo` 必须包含在作用域内。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果将 大写开头的 改为 大写字母开头的 是不是会更清楚一些?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,这样更好,我全文没有统一,我会再调整下。
content/docs/jsx-in-depth.md
Outdated
|
||
For example, both of the imports are necessary in this code, even though `React` and `CustomButton` are not directly referenced from JavaScript: | ||
例如, 虽然 `React` 和 `CustomButton` 都没有被直接使用,但都必须在这个代码中导入: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
例如, 虽然 React
和 CustomButton
都没有被直接使用,但都必须在这个代码中导入 改为 例如,在如下代码中,虽然 React
和 CustomButton
都没有被直接使用,但这二者仍然必须被导入?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改为:
例如,在如下代码中,虽然 React
和 CustomButton
并没有被直接使用,但还是需要导入:
content/docs/jsx-in-depth.md
Outdated
@@ -71,11 +72,11 @@ function WarningButton() { | |||
} | |||
``` | |||
|
|||
If you don't use a JavaScript bundler and loaded React from a `<script>` tag, it is already in scope as the `React` global. | |||
如果您并不使用 JavaScript 打包工具且通过 `<script>` 标签加载 React,必须将 `React` 挂载到全局变量中。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果您并不使用 JavaScript 打包工具且通过 <script>
标签加载 React,必须将 React
挂载到全局变量中。 --> 如果您并不使用 JavaScript 打包工具 而是 通过 <script>
标签加载 React,则 必须将 React
挂载到全局变量中。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
赞,已更正。
content/docs/jsx-in-depth.md
Outdated
|
||
You can also refer to a React component using dot-notation from within JSX. This is convenient if you have a single module that exports many React components. For example, if `MyComponents.DatePicker` is a component, you can use it directly from JSX with: | ||
在 JSX 中,您也可以使用点表示法来引用一个 React 组件。当您在一个模块中到处许多 React 组件时,这会非常方便。例如,如果 `MyComponents.DatePicker` 是一个组件,您可以在 JSX 中直接使用: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
到处 --> 导出
content/docs/jsx-in-depth.md
Outdated
@@ -91,49 +92,49 @@ function BlueDatePicker() { | |||
} | |||
``` | |||
|
|||
### User-Defined Components Must Be Capitalized {#user-defined-components-must-be-capitalized} | |||
### 用户定义的组件必须大写开头 {#user-defined-components-must-be-capitalized} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大写开头 --> 以大写字母开头
content/docs/jsx-in-depth.md
Outdated
@@ -372,20 +372,20 @@ function TodoList() { | |||
} | |||
``` | |||
|
|||
JavaScript expressions can be mixed with other types of children. This is often useful in lieu of string templates: | |||
JavaScript 表达式也可以和其他类型的子元素组合。通常用于替代字符串字面量: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种做法可以方便地替代模板字符串:
content/docs/jsx-in-depth.md
Outdated
@@ -403,11 +403,11 @@ function ListOfTenThings() { | |||
} | |||
``` | |||
|
|||
Children passed to a custom component can be anything, as long as that component transforms them into something React can understand before rendering. This usage is not common, but it works if you want to stretch what JSX is capable of. | |||
您可以将任何东西作为子元素传递给自定义组件,只要确保在该组件渲染之前可以被转换成 React 能够理解的事物。这种用法并不常见,但如果您要扩展 JSX,它就有用了。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只要确保在该组件被 React 渲染之前 已经 被转换成 React 能够理解的对象。这种做法可以用来扩展 JSX。
content/docs/jsx-in-depth.md
Outdated
|
||
`false`, `null`, `undefined`, and `true` are valid children. They simply don't render. These JSX expressions will all render to the same thing: | ||
`false`, `null`, `undefined`, and `true` 是合法的子元素。但它们根本不会被渲染。以下的 JSX 表达式将会渲染出同样的结果: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但它们 并 不会被渲染。以下的 JSX 表达式渲染 结果相同 :
content/docs/jsx-in-depth.md
Outdated
@@ -423,7 +423,7 @@ Children passed to a custom component can be anything, as long as that component | |||
<div>{true}</div> | |||
``` | |||
|
|||
This can be useful to conditionally render React elements. This JSX only renders a `<Header />` if `showHeader` is `true`: | |||
这有助于条件渲染其他的 React 元素。在以下 JSX 中,仅当 `showHeader` = `true` 时,才会渲染 `<Header />`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这有助于 依据特定条件来 渲染其他的 React 元素。 例如 在以下...
content/docs/jsx-in-depth.md
Outdated
@@ -432,7 +432,7 @@ This can be useful to conditionally render React elements. This JSX only renders | |||
</div> | |||
``` | |||
|
|||
One caveat is that some ["falsy" values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), such as the `0` number, are still rendered by React. For example, this code will not behave as you might expect because `0` will be printed when `props.messages` is an empty array: | |||
值得注意的是有一些 "falsy" 值(假值,在 JavaScript 中可能会被转换为 false 的值),如数字 0,仍然会被 React 渲染。例如,以下代码不会像您预期那样工作,当 `props.messages` 是空数组时,长度为 `0` 也会被 React 渲染: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当 props.messages
是空数组时,长度为 0
。 但该数组的长度值 0
也会被 React 渲染:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改为 :
虽然 props.messages
是空数组时长度为 0
,但 <MessageList />
仍然会被渲染:
非常感谢 @YaokaiYang-assaultmaster 耐心指导,学到很多,谢谢。 |
我中间还有一些comments被hide了。感觉你是不是没看到呀,可以点 |
看到了呀,一共30多个comment,我都有处理呢。 |
嗷嗷不好意思 我估计看错啦~ |
可以在 changed Tab 里面看后续的改动。再次感谢,您的翻译更显生动。 |
This translate has any questions yet? |
哈哈不敢当不敢当 互相学习嘛 |
学到了不少翻译技巧,Thanks。 |
Anyone review? |
content/docs/jsx-in-depth.md
Outdated
function hello(props) { | ||
// Correct! This use of <div> is legitimate because div is a valid HTML tag: | ||
// 正确!这种 <div> 的使用是合法的,因为div是一个有效的HTML标记 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 正确!这种 <div> 的使用是合法的,因为div是一个有效的HTML标记 | |
// 正确!这种 <div> 的使用是合法的,因为div是一个有效的 HTML 标签 |
content/docs/jsx-in-depth.md
Outdated
function Hello(props) { | ||
// Correct! This use of <div> is legitimate because div is a valid HTML tag: | ||
// 正确! 这种<div>的使用是合法的,因为 div 是一个有效的HTML标记: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 正确! 这种<div>的使用是合法的,因为 div 是一个有效的HTML标记: | |
// 正确! 这种<div>的使用是合法的,因为 div 是一个有效的 HTML 标签: |
content/docs/jsx-in-depth.md
Outdated
|
||
You cannot use a general expression as the React element type. If you do want to use a general expression to indicate the type of the element, just assign it to a capitalized variable first. This often comes up when you want to render a different component based on a prop: | ||
如果您想通过通用表达式来(动态)决定元素类型,您需要首先将它赋值给大写字母开头的变量。这通常用于您想根据 prop 来渲染不同组件的情况: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You cannot use a general expression as the React element type. 没有翻译
- 所有的“您”都改成“你”
content/docs/jsx-in-depth.md
Outdated
|
||
如果您没给 prop 赋值,它的默认值是 `true`。以下两个 JSX 表达式是等价的: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几行行数没有对应上,都乱了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是多删了一行
content/docs/jsx-in-depth.md
Outdated
@@ -245,7 +244,7 @@ function App2() { | |||
} | |||
``` | |||
|
|||
You can also pick specific props that your component will consume while passing all other props using the spread operator. | |||
您还可以仅仅保留选择当前 组件 需要接收的 props,并使用展开操作符将其他 props 传递下去。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
您还可以仅仅保留选择当前 组件 需要接收的 props,并使用展开操作符将其他 props 传递下去。 | |
您还可以仅仅保留选择当前组件 需要接收的 props,并使用展开操作符将其他 props 传递下去。 |
content/docs/jsx-in-depth.md
Outdated
|
||
```js | ||
<MyComponent>foo</MyComponent> | ||
|
||
<MyComponent>{'foo'}</MyComponent> | ||
``` | ||
|
||
This is often useful for rendering a list of JSX expressions of arbitrary length. For example, this renders an HTML list: | ||
这对于展示任意长度的列表是非常有用的。例如,渲染HTML列表: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这对于展示任意长度的列表是非常有用的。例如,渲染HTML列表: | |
这对于展示任意长度的列表是非常有用的。例如,渲染 HTML 列表: |
content/docs/jsx-in-depth.md
Outdated
|
||
Normally, JavaScript expressions inserted in JSX will evaluate to a string, a React element, or a list of those things. However, `props.children` works just like any other prop in that it can pass any sort of data, not just the sorts that React knows how to render. For example, if you have a custom component, you could have it take a callback as `props.children`: | ||
通常,JSX 中的 JavaScript 表达式将会被计算为字符串、React元素或者是一个列表。不过,`props.children` 和其他 prop 一样,它可以传递任意类型的数据,而不仅仅是 React 已知的可以渲染的类型。例如,如果您有一个自定义组件,您可以把回调函数作为 `props.children` 进行传递: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常,JSX 中的 JavaScript 表达式将会被计算为字符串、React元素或者是一个列表。不过,`props.children` 和其他 prop 一样,它可以传递任意类型的数据,而不仅仅是 React 已知的可以渲染的类型。例如,如果您有一个自定义组件,您可以把回调函数作为 `props.children` 进行传递: | |
通常,JSX 中的 JavaScript 表达式将会被计算为字符串、React 元素或者是一个列表。不过,`props.children` 和其他 prop 一样,它可以传递任意类型的数据,而不仅仅是 React 已知的可以渲染的类型。例如,如果您有一个自定义组件,您可以把回调函数作为 `props.children` 进行传递: |
content/docs/jsx-in-depth.md
Outdated
@@ -423,7 +422,7 @@ Children passed to a custom component can be anything, as long as that component | |||
<div>{true}</div> | |||
``` | |||
|
|||
This can be useful to conditionally render React elements. This JSX only renders a `<Header />` if `showHeader` is `true`: | |||
这有助于依据特定条件来渲染其他的 React 元素。例如,在以下 JSX 中,仅当 `showHeader` = `true` 时,才会渲染 `<Header />`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要用 = 号,因为 = 在计算机里一般表示赋值
这有助于依据特定条件来渲染其他的 React 元素。例如,在以下 JSX 中,仅当 `showHeader` = `true` 时,才会渲染 `<Header />`: | |
这有助于依据特定条件来渲染其他的 React 元素。例如,在以下 JSX 中,仅当 `showHeader` 为 `true` 时,才会渲染 `<Header />`: |
content/docs/jsx-in-depth.md
Outdated
@@ -432,7 +431,7 @@ This can be useful to conditionally render React elements. This JSX only renders | |||
</div> | |||
``` | |||
|
|||
One caveat is that some ["falsy" values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), such as the `0` number, are still rendered by React. For example, this code will not behave as you might expect because `0` will be printed when `props.messages` is an empty array: | |||
值得注意的是有一些 "falsy" 值(假值,在 JavaScript 中可能会被转换为 false 的值),如数字 0,仍然会被 React 渲染。例如,以下代码并不会像您预期那样工作,虽然 `props.messages` 是空数组时长度为 `0`,但 `<MessageList />` 仍然会被渲染: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- "falsy" values 是一个超链接。需要保留
- 这里不需要注释,删掉,因为都有超链接里,不需要解释。超链接的内容就是解释
content/docs/jsx-in-depth.md
Outdated
@@ -452,7 +451,7 @@ To fix this, make sure that the expression before `&&` is always boolean: | |||
</div> | |||
``` | |||
|
|||
Conversely, if you want a value like `false`, `true`, `null`, or `undefined` to appear in the output, you have to [convert it to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion) first: | |||
反之,如果您想渲染 false, true, null, undefined 等值,您需要先将它们[转换为字符串](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
反之,如果您想渲染 false, true, null, undefined 等值,您需要先将它们[转换为字符串](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion): | |
反之,如果你想渲染 `false`、`true`、`null`、`undefined` 等值,你需要先将它们[转换为字符串](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#String_conversion): |
文中所有的“您”都改成“你”。我没有一一指出,你需要全局替换。 |
@yuqingc 感谢指出,已经更正。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
剩下的都是一些格式的小问题。我肉眼这次也许没有找完全,你可以在你的编辑器内用相关插件或者正则匹配来统一格式化一下。没有其他的大问题了。辛苦了兄弟。
- 单词两边要有空格
- 中文超链接两边不需要空格
content/docs/jsx-in-depth.md
Outdated
function hello(props) { | ||
// Correct! This use of <div> is legitimate because div is a valid HTML tag: | ||
// 正确!这种 <div> 的使用是合法的,因为div是一个有效的 HTML 标签 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 正确!这种 <div> 的使用是合法的,因为div是一个有效的 HTML 标签 | |
// 正确!这种 <div> 的使用是合法的,因为 div 是一个有效的 HTML 标签 |
content/docs/jsx-in-depth.md
Outdated
@@ -196,43 +196,43 @@ function NumberDescriber(props) { | |||
} | |||
``` | |||
|
|||
You can learn more about [conditional rendering](/docs/conditional-rendering.html) and [loops](/docs/lists-and-keys.html) in the corresponding sections. | |||
你可以在对应的章节中学习更多关于 [条件渲染](/docs/conditional-rendering.html) 和 [循环](/docs/lists-and-keys.html) 的内容。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你可以在对应的章节中学习更多关于 [条件渲染](/docs/conditional-rendering.html) 和 [循环](/docs/lists-and-keys.html) 的内容。 | |
你可以在对应的章节中学习更多关于[条件渲染](/docs/conditional-rendering.html)和[循环](/docs/lists-and-keys.html)的内容。 |
content/docs/jsx-in-depth.md
Outdated
|
||
```js | ||
<MyTextBox autocomplete /> | ||
|
||
<MyTextBox autocomplete={true} /> | ||
``` | ||
|
||
In general, we don't recommend using this because it can be confused with the [ES6 object shorthand](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015) `{foo}` which is short for `{foo: foo}` rather than `{foo: true}`. This behavior is just there so that it matches the behavior of HTML. | ||
通常,我们不建议这样使用,因为它可能与 [ES6对象简写](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015) 混淆, `{foo}` 是 `{foo: foo}` 的简写,而不是 `{foo: true}`。这样实现只是为了保持和 HTML 中标签属性的行为一致。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常,我们不建议这样使用,因为它可能与 [ES6对象简写](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015) 混淆, `{foo}` 是 `{foo: foo}` 的简写,而不是 `{foo: true}`。这样实现只是为了保持和 HTML 中标签属性的行为一致。 | |
通常,我们不建议这样使用,因为它可能与 [ES6 对象简写](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015) 混淆,`{foo}` 是 `{foo: foo}` 的简写,而不是 `{foo: true}`。这样实现只是为了保持和 HTML 中标签属性的行为一致。 |
content/docs/jsx-in-depth.md
Outdated
@@ -319,7 +319,7 @@ You can provide more JSX elements as the children. This is useful for displaying | |||
</MyContainer> | |||
``` | |||
|
|||
You can mix together different types of children, so you can use string literals together with JSX children. This is another way in which JSX is like HTML, so that this is both valid JSX and valid HTML: | |||
你可以将不同类型的子元素混合在一起,因此你可以将字符串字面量与 JSX 子元素一起使用。这也是 JSX 类似 HTML 的一种表现,所以如下是合法的 JSX 也是合法的HTML: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你可以将不同类型的子元素混合在一起,因此你可以将字符串字面量与 JSX 子元素一起使用。这也是 JSX 类似 HTML 的一种表现,所以如下是合法的 JSX 也是合法的HTML: | |
你可以将不同类型的子元素混合在一起,因此你可以将字符串字面量与 JSX 子元素一起使用。这也是 JSX 类似 HTML 的一种表现,所以如下是合法的 JSX 也是合法的 HTML: |
@yuqingc 感谢,已经按照规则重新检查了一次。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice Work!
LGTM
@hstarorg 查看邮件,我给你发了个群二维码。 |
@YaokaiYang-assaultmaster 也给我个你的邮箱链接呗? |
@QC-L 没问题 发到你Github首页那个邮箱里啦。 |
收到,Thanks。 |
@YaokaiYang-assaultmaster 回复你了,查收~ |
Any review and translation optimization recommendation is welcomed.