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

docs Typechecking With PropTypes #108

Merged
merged 5 commits into from
Mar 27, 2019
Merged

Conversation

ycjcl868
Copy link
Collaborator

大佬们 review review ~

@ycjcl868 ycjcl868 added the Pending Review 已翻译,待校对阶段 label Feb 17, 2019
@ycjcl868 ycjcl868 changed the title 📝 docs Typechecking With PropTypes docs Typechecking With PropTypes Feb 17, 2019
@ycjcl868 ycjcl868 mentioned this pull request Feb 17, 2019
@netlify
Copy link

netlify bot commented Feb 17, 2019

Deploy preview for cn-reactjs ready!

Built with commit f47755a

https://deploy-preview-108--cn-reactjs.netlify.com

@tesseralis tesseralis removed their request for review February 17, 2019 20:32
Copy link
Collaborator

@robertying robertying left a comment

Choose a reason for hiding this comment

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

赞 👍!
主要的问题是行数不对应。我还根据我自己的理解提供了一些建议。大家互相讨论修改吧。

>
> `React.PropTypes` has moved into a different package since React v15.5. Please use [the `prop-types` library instead](https://www.npmjs.com/package/prop-types).
> React 15.5 起,`React.PropTypes` 已移入另一个包中。请使用 [`prop-types`](https://www.npmjs.com/package/prop-types) 库代替。
Copy link
Collaborator

Choose a reason for hiding this comment

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

自 React 15.5 起 => 自 React v15.5 起,版本v我觉得还是保留比较好吧~

如果要与原文一致的话,写成 请使用prop-types 库替代,会不会更好呢?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

感觉不需要翻译出来。

>
>We provide [a codemod script](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) to automate the conversion.
>我们提供了一个 [codemod](/blog/2017/04/07/react-v15.5.0.html#migrating-from-reactproptypes) 脚本来自动转换。
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里也是一样的问题,可以把 一个 codemon 脚本 放在链接内吧。这样以后原文更改后这里的翻译变化能更对应~

@@ -30,18 +30,17 @@ Greeting.propTypes = {
};
```

`PropTypes` exports a range of validators that can be used to make sure the data you receive is valid. In this example, we're using `PropTypes.string`. When an invalid value is provided for a prop, a warning will be shown in the JavaScript console. For performance reasons, `propTypes` is only checked in development mode.
`PropTypes` 提供一系列验证器,可用于组件接收的数据类型是有效的。在本例中, 我们使用了 `PropTypes.string`。当传入类型不正确的属性时,JavaScript 控制台将会显示警告。出于性能方面的考虑,`propTypes` 只仅在开发模式下进行检查。
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. 可用于组件接收的数据类型是有效的 =》 可用于确保组件接收的数据类型是有效的。忘记翻译啦~

  2. 当传入类型不正确的属性时 =》 当一个类型不正确的值传入该 prop 时。 我个人倾向于 prop 不翻译(之前貌似讨论的是这样的),其次我觉得这里应该把“value”翻译出来吧~

  3. 只仅在开发模式下进行检查 =》 仅在开发模式下被检查

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

会不会有点牵强


### PropTypes {#proptypes}
### Prop 类型 {#proptypes}
Copy link
Collaborator

Choose a reason for hiding this comment

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

PropTypes 是专有名词吧,这里不应该拆开来翻译,你觉得呢?


```javascript
import PropTypes from 'prop-types';

MyComponent.propTypes = {
// You can declare that a prop is a specific JS type. By default, these
// are all optional.
// 你可以将属性声明为 JS 原生类型,默认情况下这些属性都是可选的。
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里根据之前群里讨论的结果,要求中文行数要和英文一致,防止错位,使得后续 merge 有困难。


With `PropTypes.element` you can specify that only a single child can be passed to a component as children.
使用 `PropTypes.element`
你可以指定 children 只有一个元素作为传递到组件。
Copy link
Collaborator

Choose a reason for hiding this comment

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

行数问题。

额,这里是机器翻译吗?
翻译成“你可以通过 PropTypes.element 来确保传递给组件的 children 中只包含一个子元素”。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

子元素 这里感觉不太合适,本意是一个 ReactElement。

@@ -119,16 +114,17 @@ MyComponent.propTypes = {
};
```

### Requiring Single Child {#requiring-single-child}
### 限制一个元素 {#requiring-single-child}
Copy link
Collaborator

Choose a reason for hiding this comment

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

在标题中,使用“限制单个元素”是否更正式些呢?

@@ -143,9 +139,9 @@ MyComponent.propTypes = {
};
```

### Default Prop Values {#default-prop-values}
### 属性默认值 {#default-prop-values}
Copy link
Collaborator

Choose a reason for hiding this comment

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

占个坑~
主要是 prop 是否翻译的问题。
如果不翻译,那么是“默认 prop 值”

ReactDOM.render(
<Greeting />,
document.getElementById('example')
);
```

If you are using a Babel transform like [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) , you can also declare `defaultProps` as static property within a React component class. This syntax has not yet been finalized though and will require a compilation step to work within a browser. For more information, see the [class fields proposal](https://github.com/tc39/proposal-class-fields).
如果你正在使用像 [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) 的 Babel 转换工具,你也可以在 React 组件类中声明 `defaultProps` 作为静态属性。此语法提案还没有最终确定,在浏览器中需要进行编译才能使用。要了解更多信息,请查阅 [class fields proposal](https://github.com/tc39/proposal-class-fields)
Copy link
Collaborator

Choose a reason for hiding this comment

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

在浏览器中需要进行编译才能使用 有歧义,因为浏览器不能编译这些新语法。不如翻译成“需要编译后才能在浏览器中运行”

@@ -184,4 +180,4 @@ class Greeting extends React.Component {
}
```

The `defaultProps` will be used to ensure that `this.props.name` will have a value if it was not specified by the parent component. The `propTypes` typechecking happens after `defaultProps` are resolved, so typechecking will also apply to the `defaultProps`.
`defaultProps` 用于确保 `this.props.name` 在父组件没有指定值时,有一个默认值。`propTypes` 类型检查发生在 `defaultProps` 赋值后,所以类型检查也适用于 `defaultProps`
Copy link
Collaborator

Choose a reason for hiding this comment

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

在父组件没有指定值时 =》 在父组件没有指定其值时

这样会不会更清晰一些~

@ycjcl868
Copy link
Collaborator Author

赞 👍!
主要的问题是行数不对应。我还根据我自己的理解提供了一些建议。大家互相讨论修改吧。

感谢 review,修改了一部分,另一部分这周抽时间再斟酌斟酌。

@netlify
Copy link

netlify bot commented Feb 27, 2019

Deploy preview for zh-hans-reactjs processing.

Building with commit 476da15

https://app.netlify.com/sites/zh-hans-reactjs/deploys/5c76abe06601390008ef68f0

@netlify
Copy link

netlify bot commented Feb 27, 2019

Deploy preview for zh-hans-reactjs ready!

Built with commit f47755a

https://deploy-preview-108--zh-hans-reactjs.netlify.com

Copy link
Member

@QC-L QC-L left a comment

Choose a reason for hiding this comment

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

LGTM

@robertying robertying merged commit 8ad2344 into master Mar 27, 2019
@yesmeck yesmeck deleted the docs-typechecking-with-proptypes branch March 27, 2019 11:35
@yesmeck yesmeck restored the docs-typechecking-with-proptypes branch March 27, 2019 11:35
@ycjcl868 ycjcl868 deleted the docs-typechecking-with-proptypes branch April 5, 2019 13:34
OhIAmFine pushed a commit to OhIAmFine/zh-hans.reactjs.org that referenced this pull request May 6, 2019
* 📝 docs Typechecking With PropTypes

* fix: typechecking doc

* fix: doc

* fix: doc

* fix: doc
@awxiaoxian2020 awxiaoxian2020 removed the Pending Review 已翻译,待校对阶段 label Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants