Skip to content

Commit ab5f452

Browse files
committed
Update translation of Promise in Simplified Chinese
1 parent 8d20f35 commit ab5f452

File tree

13 files changed

+51
-51
lines changed

13 files changed

+51
-51
lines changed

src/content/10/zh/part10c.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fetch('https://my-api.com/post-end-point', {
5252
注意,这些URL是编造的,不会(很可能)对你的请求发出响应。与Axios相比,Fetch API的操作水平要低一些。例如,没有任何请求或响应体的序列化和解析。这意味着你必须自己设置<i>Content-Type</i>头并使用<em>JSON.stringify</em>方法来序列化请求体。
5353

5454
<!-- The <em>fetch</em> function returns a promise which resolves a [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) object. Note that error status codes such as 400 and 500 <i>are not rejected</i> like for example in Axios. In case of a JSON formatted response we can parse the response body using the <em>Response.json</em> method:-->
55-
<em>fetch</em>函数返回一个承诺,它解决了一个[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) 对象。请注意,错误状态代码如400和500 <i>不会被拒绝</i>,例如在Axios中。如果是JSON格式的响应,我们可以使用<em>Response.json</em>方法解析响应体。
55+
<em>fetch</em>函数返回一个 Promise ,它解决了一个[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) 对象。请注意,错误状态代码如400和500 <i>不会被拒绝</i>,例如在Axios中。如果是JSON格式的响应,我们可以使用<em>Response.json</em>方法解析响应体。
5656

5757
```javascript
5858
const fetchMovies = async () => {

src/content/12/zh/part12b.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,13 +863,13 @@ Emitted 'error' event on RedisClient instance at:
863863
#### Exercise 12.10:
864864

865865
<!-- The project already has [https://www.npmjs.com/package/redis](https://www.npmjs.com/package/redis) installed and two functions "promisified" - getAsync and setAsync.-->
866-
该项目已经安装了[https://www.npmjs.com/package/redis](https://www.npmjs.com/package/redis)和两个 "承诺 "的函数--getAsync和setAsync。
866+
该项目已经安装了[https://www.npmjs.com/package/redis](https://www.npmjs.com/package/redis)和两个 " Promise "的函数--getAsync和setAsync。
867867

868868
<!-- - setAsync function takes in key and value, using the key to store the value.-->
869869
- setAsync函数接收键和值,用键来存储值。
870870

871871
<!-- - getAsync function takes in key and returns the value in a promise.-->
872-
- getAsync函数接收键并在一个承诺中返回值
872+
- getAsync函数接收键并在一个 Promise 中返回值
873873

874874
<!-- Implement a todo counter that saves the number of created todos to Redis:-->
875875
实现一个todo计数器,将创建的todos的数量保存到Redis。

src/content/2/zh/part2c.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ setTimeout(() => {
164164
让我们回到从服务器获取数据的话题上来。
165165

166166
<!-- We could use the previously mentioned promise based function [fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) to pull the data from the server. Fetch is a great tool. It is standardized and supported by all modern browsers (excluding IE).-->
167-
我们可以使用之前提到的基于承诺的函数[fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)来从服务器获取数据。Fetch是一个伟大的工具。它是标准化的,被所有现代浏览器支持(不包括IE)。
167+
我们可以使用之前提到的基于 Promise 的函数[fetch](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch)来从服务器获取数据。Fetch是一个伟大的工具。它是标准化的,被所有现代浏览器支持(不包括IE)。
168168

169169
<!-- That being said, we will be using the [axios](https://github.com/axios/axios) library instead for communication between the browser and server. It functions like fetch, but is somewhat more pleasant to use. Another good reason to use axios is our getting familiar with adding external libraries, so-called <i>npm packages</i>, to React projects.-->
170170
也就是说,我们将使用[axios](https://github.com/axios/axios)库来代替浏览器和服务器之间的通信。它的功能类似于fetch,但使用起来更顺手一些。使用axios的另一个很好的理由是我们要熟悉在React项目中添加外部库,即所谓的npm包</i>。
@@ -342,29 +342,29 @@ console.log(promise2)
342342
**注意:**当文件<i>index.js</i>的内容发生变化时,React并不总是自动注意到这一点,所以你可能需要刷新浏览器来看到你的变化!一个简单的解决方法是在项目的根目录下创建一个名为<i>.env</i>的文件,并添加这一行<i>FAST_REFRESH=false</i>,使React自动注意到变化。重新启动应用以使应用的变化生效。
343343

344344
<!-- Axios' method _get_ returns a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises).-->
345-
'Axios' 方法 _get_ 返回一个[承诺](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)
345+
'Axios' 方法 _get_ 返回一个[ Promise ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)
346346

347347
<!-- The documentation on Mozilla's site states the following about promises:-->
348-
Mozilla网站上的文档对承诺有如下说明
348+
Mozilla网站上的文档对 Promise 有如下说明
349349

350350
<!-- > <i>A Promise is an object representing the eventual completion or failure of an asynchronous operation.</i>-->
351351
> <i>A Promise是一个代表异步操作最终完成或失败的对象。</i>
352352
353353
<!-- In other words, a promise is an object that represents an asynchronous operation. A promise can have three distinct states:-->
354-
换句话说,一个承诺是一个代表异步操作的对象。一个承诺可以有三种不同的状态
354+
换句话说,一个 Promise 是一个代表异步操作的对象。一个 Promise 可以有三种不同的状态
355355

356356
<!-- 1. The promise is <i>pending</i>: It means that the final value (one of the following two) is not available yet.-->
357357
1.答应是<i>pending</i>:这意味着最终的值(以下两个中的一个)还不能用。
358358
<!-- 2. The promise is <i>fulfilled</i>: It means that the operation has been completed and the final value is available, which generally is a successful operation. This state is sometimes also called <i>resolved</i>.-->
359-
2.承诺是<i>fulfilled</i>:它意味着操作已经完成,最终值可用,一般来说是一个成功的操作。这种状态有时也被称为<i>resolved</i>。
359+
2. Promise 是<i>fulfilled</i>:它意味着操作已经完成,最终值可用,一般来说是一个成功的操作。这种状态有时也被称为<i>resolved</i>。
360360
<!-- 3. The promise is <i>rejected</i>: It means that an error prevented the final value from being determined, which generally represents a failed operation.-->
361-
3.承诺被<i>拒绝</i>:这意味着一个错误阻止了最终值的确定,这一般代表一个失败的操作。
361+
3. Promise 被<i>拒绝</i>:这意味着一个错误阻止了最终值的确定,这一般代表一个失败的操作。
362362

363363
<!-- The first promise in our example is <i>fulfilled</i>, representing a successful _axios.get('http://localhost:3001/notes')_ request. The second one, however, is <i>rejected</i>, and the console tells us the reason. It looks like we were trying to make an HTTP GET request to a non-existent address.-->
364-
我们例子中的第一个承诺是<i>fulfilled</i>,代表一个成功的_axios.get('http://localhost:3001/notes')_请求。然而,第二个承诺是<i>拒绝的</i>,并且控制台告诉我们原因。看起来我们试图向一个不存在的地址发出HTTP GET请求。
364+
我们例子中的第一个 Promise 是<i>fulfilled</i>,代表一个成功的_axios.get('http://localhost:3001/notes')_请求。然而,第二个 Promise 是<i>拒绝的</i>,并且控制台告诉我们原因。看起来我们试图向一个不存在的地址发出HTTP GET请求。
365365

366366
<!-- If, and when, we want to access the result of the operation represented by the promise, we must register an event handler to the promise. This is achieved using the method <em>then</em>:-->
367-
如果,以及何时,我们想访问承诺所代表的操作的结果,我们必须为承诺注册一个事件处理程序。这可以通过<em>then</em>方法实现。
367+
如果,以及何时,我们想访问 Promise 所代表的操作的结果,我们必须为 Promise 注册一个事件处理程序。这可以通过<em>then</em>方法实现。
368368

369369
```js
370370
const promise = axios.get('http://localhost:3001/notes')
@@ -382,7 +382,7 @@ promise.then(response => {
382382
JavaScript运行环境调用由<em>then</em>方法注册的回调函数,为其提供一个<em>response</em>对象作为参数。<em>response</em>对象包含与HTTP GET请求的响应相关的所有基本数据,其中包括返回的<i>数据</i>、<i>状态代码</i>和<i>头信息</i>。
383383

384384
<!-- Storing the promise object in a variable is generally unnecessary, and it's instead common to chain the <em>then</em> method call to the axios method call, so that it follows it directly:-->
385-
将承诺对象存储在一个变量中通常是不必要的,而通常是将<em>then</em>方法调用链到axios方法调用中,这样它就直接跟随它。
385+
将 Promise 对象存储在一个变量中通常是不必要的,而通常是将<em>then</em>方法调用链到axios方法调用中,这样它就直接跟随它。
386386

387387
```js
388388
axios.get('http://localhost:3001/notes').then(response => {
@@ -529,7 +529,7 @@ response => {
529529
```
530530

531531
<!-- When data arrives from the server, the JavaScript runtime calls the function registered as the event handler, which prints <i>promise fulfilled</i> to the console and stores the notes received from the server into the state using the function <em>setNotes(response.data)</em>.-->
532-
当数据从服务器到达时,JavaScript运行时调用注册为事件处理程序的函数,该函数将<i>承诺兑现</i>打印到控制台,并使用函数<em>setNotes(response.data)</em>将从服务器收到的注释存储到状态中。
532+
当数据从服务器到达时,JavaScript运行时调用注册为事件处理程序的函数,该函数将<i> Promise 兑现</i>打印到控制台,并使用函数<em>setNotes(response.data)</em>将从服务器收到的注释存储到状态中。
533533

534534
<!-- As always, a call to a state-updating function triggers the re-rendering of the component. As a result, <i>render 3 notes</i> is printed to the console, and the notes fetched from the server are rendered to the screen.-->
535535
一如既往,对状态更新函数的调用会触发组件的重新渲染。结果,<i>render 3 notes</i>被打印到控制台,而从服务器上获取的笔记被渲染到屏幕上。
@@ -601,7 +601,7 @@ useEffect(() => {
601601
```
602602

603603
<!-- A reference to an event handler function is assigned to the variable <em>eventHandler</em>. The promise returned by the <em>get</em> method of Axios is stored in the variable <em>promise</em>. The registration of the callback happens by giving the <em>eventHandler</em> variable, referring to the event-handler function, as a parameter to the <em>then</em> method of the promise. It isn't usually necessary to assign functions and promises to variables, and a more compact way of representing things, as seen further above, is sufficient.-->
604-
一个事件处理函数的引用被分配到变量<em>eventHandler</em>。由Axios的<em>get</em>方法返回的承诺被存储在变量<em>promise</em>中。回调的注册是通过给<em>eventHandler</em>变量,指的是事件处理函数,作为承诺的<em>then</em>方法的一个参数。通常没有必要把函数和承诺分配给变量,用更紧凑的方式来表示事情,如上面进一步看到的,就足够了。
604+
一个事件处理函数的引用被分配到变量<em>eventHandler</em>。由Axios的<em>get</em>方法返回的 Promise 被存储在变量<em>promise</em>中。回调的注册是通过给<em>eventHandler</em>变量,指的是事件处理函数,作为 Promise 的<em>then</em>方法的一个参数。通常没有必要把函数和 Promise 分配给变量,用更紧凑的方式来表示事情,如上面进一步看到的,就足够了。
605605

606606
```js
607607
useEffect(() => {

src/content/2/zh/part2d.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ export default {
336336
```
337337
338338
<!-- The module returns an object that has three functions (<i>getAll</i>, <i>create</i>, and <i>update</i>) as its properties that deal with notes. The functions directly return the promises returned by the axios methods.-->
339-
该模块返回一个对象,该对象有三个函数(<i>getAll</i>、<i>create</i>和<i>update</i>)作为其属性,处理笔记。这些函数直接返回axios方法所返回的承诺
339+
该模块返回一个对象,该对象有三个函数(<i>getAll</i>、<i>create</i>和<i>update</i>)作为其属性,处理笔记。这些函数直接返回axios方法所返回的 Promise
340340
341341
<!-- The <i>App</i> component uses <em>import</em> to get access to the module:-->
342342
<i>App</i>组件使用<em>import</em>来获得对模块的访问。
@@ -457,7 +457,7 @@ export default {
457457
458458
459459
<!-- We no longer return the promise returned by axios directly. Instead, we assign the promise to the <em>request</em> variable and call its <em>then</em> method:-->
460-
我们不再直接返回axios返回的承诺。相反,我们将承诺分配给<em>request</em>变量并调用其<em>then</em>方法。
460+
我们不再直接返回axios返回的 Promise 。相反,我们将 Promise 分配给<em>request</em>变量并调用其<em>then</em>方法。
461461
462462
```js
463463
const getAll = () => {
@@ -481,7 +481,7 @@ const getAll = () => {
481481
```
482482
483483
<!-- The modified <em>getAll</em> function still returns a promise, as the <em>then</em> method of a promise also [returns a promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then).-->
484-
修改后的<em>getAll</em>函数仍然返回一个承诺,因为一个承诺的<em>then</em>方法也[返回一个承诺](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)。
484+
修改后的<em>getAll</em>函数仍然返回一个 Promise ,因为一个 Promise 的<em>then</em>方法也[返回一个 Promise ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)。
485485
486486
<!-- After defining the parameter of the <em>then</em> method to directly return <i>response.data</i>, we have gotten the <em>getAll</em> function to work like we wanted it to. When the HTTP request is successful, the promise returns the data sent back in the response from the backend.-->
487487
在定义了<em>then</em>方法的参数以直接返回<i>response.data</i>之后,我们已经让<em>getAll</em>函数像我们希望的那样工作。当HTTP请求成功时,promise会返回从后端响应中发回的数据。
@@ -545,7 +545,7 @@ const App = () => {
545545
[你不懂JS](https://github.com/getify/You-Dont-Know-JS/tree/1st-ed)系列书籍中的 "异步和性能 "一书[很好地解释了这个话题](https://github.com/getify/You-Dont-Know-JS/blob/1st-ed/async%20%26%20performance/ch3.md),但解释的篇幅很多。
546546
547547
<!-- Promises are central to modern JavaScript development and it is highly recommended to invest a reasonable amount of time into understanding them.-->
548-
承诺是现代JavaScript开发的核心,强烈建议投入合理的时间来理解它们。
548+
Promise 是现代JavaScript开发的核心,强烈建议投入合理的时间来理解它们。
549549
550550
### Cleaner Syntax for Defining Object Literals
551551
@@ -692,16 +692,16 @@ const getAll = () => {
692692
应用应该能够优雅地处理这些类型的错误情况。除非用户碰巧打开了他们的控制台,否则他们无法知道错误确实发生了。在应用中可以看到错误的唯一方法是,点击按钮对注释的重要性没有影响。
693693
694694
<!-- We had [previously](/en/part2/getting_data_from_server#axios-and-promises) mentioned that a promise can be in one of three different states. When an HTTP request fails, the associated promise is <i>rejected</i>. Our current code does not handle this rejection in any way.-->
695-
我们[之前](/en/part2/getting_data_from_server#axios-and-promises)提到,一个承诺可以处于三种不同的状态之一。当一个HTTP请求失败时,相关的承诺会被<i>拒绝</i>。我们目前的代码没有以任何方式处理这种拒绝。
695+
我们[之前](/en/part2/getting_data_from_server#axios-and-promises)提到,一个 Promise 可以处于三种不同的状态之一。当一个HTTP请求失败时,相关的 Promise 会被<i>拒绝</i>。我们目前的代码没有以任何方式处理这种拒绝。
696696
697697
<!-- The rejection of a promise is [handled](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) by providing the <em>then</em> method with a second callback function, which is called in the situation where the promise is rejected.-->
698-
拒绝承诺是通过提供带有第二个回调函数的<em>then</em>方法来[处理](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)的,该函数在承诺被拒绝的情况下被调用
698+
拒绝 Promise 是通过提供带有第二个回调函数的<em>then</em>方法来[处理](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)的,该函数在 Promise 被拒绝的情况下被调用
699699
700700
<!-- The more common way of adding a handler for rejected promises is to use the [catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) method.-->
701-
为被拒绝的承诺添加处理程序的更常见方式是使用[catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)方法。
701+
为被拒绝的 Promise 添加处理程序的更常见方式是使用[catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)方法。
702702
703703
<!-- In practice, the error handler for rejected promises is defined like this:-->
704-
在实践中,被拒绝的承诺的错误处理程序是这样定义的
704+
在实践中,被拒绝的 Promise 的错误处理程序是这样定义的
705705
706706
```js
707707
axios
@@ -718,10 +718,10 @@ axios
718718
如果请求失败,与<em>catch</em>方法注册的事件处理程序被调用。
719719
720720
<!-- The <em>catch</em> method is often utilized by placing it deeper within the promise chain.-->
721-
<em>catch</em>方法经常被利用,将其置于承诺链的更深处
721+
<em>catch</em>方法经常被利用,将其置于 Promise 链的更深处
722722
723723
<!-- When our application makes an HTTP request, we are in fact creating a [promise chain](https://javascript.info/promise-chaining):-->
724-
当我们的应用发出一个HTTP请求时,我们实际上是在创建一个[承诺链](https://javascript.info/promise-chaining)。
724+
当我们的应用发出一个HTTP请求时,我们实际上是在创建一个[ Promise 链](https://javascript.info/promise-chaining)。
725725
726726
```js
727727
axios
@@ -733,7 +733,7 @@ axios
733733
```
734734
735735
<!-- The <em>catch</em> method can be used to define a handler function at the end of a promise chain, which is called once any promise in the chain throws an error and the promise becomes <i>rejected</i>.-->
736-
<em>catch</em>方法可以用来在承诺链的末端定义一个处理函数,一旦承诺链中的任何一个承诺抛出错误,承诺就会被调用,成为<i>拒绝</i>。
736+
<em>catch</em>方法可以用来在 Promise 链的末端定义一个处理函数,一旦 Promise 链中的任何一个 Promise 抛出错误, Promise 就会被调用,成为<i>拒绝</i>。
737737
738738
```js
739739
axios

0 commit comments

Comments
 (0)